hotfix CCache and enable use cache
This commit is contained in:
1 parent
fa02e60b5d
commit
d5bdfbc33c
4 files changed
+113
-94
No files matched your search
@@ -1,103 +1,110 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/inc/bootstrap.php';
|
require_once __DIR__ . '/inc/bootstrap.php';
|
||||||
if(!CUSer::is_admin()) {
|
if (!CUSer::is_admin()) {
|
||||||
die('403 - Access denied');
|
die('403 - Access denied');
|
||||||
}
|
}
|
||||||
require_once __DIR__ . '/inc/header.php';
|
require_once __DIR__ . '/inc/header.php';
|
||||||
?>
|
?>
|
||||||
<?php
|
<?php
|
||||||
if(
|
if (
|
||||||
isset($_REQUEST['run_task']) and $_REQUEST['run_task'] == 'Y' and
|
isset($_REQUEST['run_task']) and $_REQUEST['run_task'] == 'Y' and
|
||||||
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
|
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
|
||||||
):
|
):
|
||||||
CCron::runTask($_REQUEST['task_id']);
|
CCron::runTask($_REQUEST['task_id']);
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
alert("Задание выполнено");
|
alert("Задание выполнено");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if(
|
if (
|
||||||
isset($_REQUEST['remove_task']) and $_REQUEST['remove_task'] == 'Y' and
|
isset($_REQUEST['remove_task']) and $_REQUEST['remove_task'] == 'Y' and
|
||||||
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
|
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
|
||||||
):
|
):
|
||||||
CCron::removeTask($_REQUEST['task_id']);
|
CCron::removeTask($_REQUEST['task_id']);
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
alert("Задание удалено");
|
alert("Задание удалено");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="row maxheight">
|
<div class="row maxheight">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<!-- Header BG Table -->
|
<!-- Header BG Table -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h4>Планировщик</h4>
|
<h4>Планировщик</h4>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
|
|
||||||
<code>CCron <a href="add_cron.php" class="btn btn-success">Добавить</a></code>
|
<code>CCron <a href="add_cron.php" class="btn btn-success">Добавить</a></code>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
<?php
|
<?php
|
||||||
CPagination::execute($_REQUEST['page'], CCron::count_tasks(), PAGINATION_LIMIT);
|
CPagination::execute($_REQUEST['page'], CCron::count_tasks(), PAGINATION_LIMIT);
|
||||||
$limit = CPagination::getLimit();
|
$limit = CPagination::getLimit();
|
||||||
?>
|
?>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-borderless table-header-bg">
|
<table class="table table-striped table-borderless table-header-bg">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-center" style="width: 50px;">ID</th>
|
<th class="text-center" style="width: 50px;">ID</th>
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
<th>Описание</th>
|
<th>Описание</th>
|
||||||
<th>Интервал</th>
|
<th>Интервал</th>
|
||||||
<th style="width: 116px;">Был запуск</th>
|
<th style="width: 116px;">Был запуск</th>
|
||||||
<th>Активность</th>
|
<th>Активность</th>
|
||||||
<th>Команда</th>
|
<th>Команда</th>
|
||||||
<th class="text-center" style="width: 110px;"></th>
|
<th class="text-center" style="width: 110px;"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach(CCron::getTasks($limit, 'ASC') as $task): ?>
|
<?php foreach (CCron::getTasks($limit, 'ASC') as $task): ?>
|
||||||
<tr data-name="<?php echo htmlspecialchars($task['name']);?>" data-id="<?php echo $task['id'];?>">
|
<tr data-name="<?php echo htmlspecialchars($task['name']); ?>"
|
||||||
<td class="mob_hide"><?php echo $task['id'];?></td>
|
data-id="<?php echo $task['id']; ?>">
|
||||||
<td><?php echo $task['name'];?></td>
|
<td class="mob_hide"><?php echo $task['id']; ?></td>
|
||||||
<td class="mob_hide"><?php echo $task['description'];?></td>
|
<td><?php echo $task['name']; ?></td>
|
||||||
<td class="mob_hide"><?php echo $task['period'];?></td>
|
<td class="mob_hide"><?php echo $task['description']; ?></td>
|
||||||
<td class="mob_hide"><?php echo date("d.m.y H:i:s", $task['last_run']);?></td>
|
<td class="mob_hide"><?php echo $task['period']; ?></td>
|
||||||
<td class="mob_hide"><?php echo $task['active'] == 'Y' ? '<button class="btn btn-app btn-block">Да</button>' : '<button class="btn btn-app-red btn-block">Нет</button>';?></td>
|
<td class="mob_hide"><?php echo date("d.m.y H:i:s", $task['last_run']); ?></td>
|
||||||
<td class="mob_hide"><code><?php echo htmlspecialchars(base64_decode($task['command']));?></code></td>
|
<td class="mob_hide"><?php echo $task['active'] == 'Y' ? '<button class="btn btn-app btn-block">Да</button>' : '<button class="btn btn-app-red btn-block">Нет</button>'; ?></td>
|
||||||
<td class="text-center">
|
<td class="mob_hide">
|
||||||
<div class="btn-group">
|
<code><?php echo htmlspecialchars(base64_decode($task['command'])); ?></code></td>
|
||||||
<button onClick="javascript:window.location.href='cron.php?run_task=Y&task_id=<?php echo $task['id'];?>'" class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="Запустить задание"><i class="fa fa-power-off"></i></button>
|
<td class="text-center">
|
||||||
<button onClick="javascript:window.location.href='edit_cron.php?id=<?php echo $task['id'];?>'" class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="Редактировать задание"><i class="ion-edit"></i></button>
|
<div class="btn-group">
|
||||||
<button onClick="javascript:window.location.href='cron.php?remove_task=Y&task_id=<?php echo $task['id'];?>'" class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="Удалить задание"><i class="ion-close"></i></button>
|
<button onClick="javascript:window.location.href='cron.php?run_task=Y&task_id=<?php echo $task['id']; ?>'"
|
||||||
</div>
|
class="btn btn-xs btn-default" type="button" data-toggle="tooltip"
|
||||||
</td>
|
title="Запустить задание"><i class="fa fa-power-off"></i></button>
|
||||||
|
<button onClick="javascript:window.location.href='edit_cron.php?id=<?php echo $task['id']; ?>'"
|
||||||
</tr>
|
class="btn btn-xs btn-default" type="button" data-toggle="tooltip"
|
||||||
<?php endforeach; ?>
|
title="Редактировать задание"><i class="ion-edit"></i></button>
|
||||||
</tbody>
|
<button onClick="javascript:window.location.href='cron.php?remove_task=Y&task_id=<?php echo $task['id']; ?>'"
|
||||||
</table>
|
class="btn btn-xs btn-default" type="button" data-toggle="tooltip"
|
||||||
</div>
|
title="Удалить задание"><i class="ion-close"></i></button>
|
||||||
<?php CPagination::show('page'); ?>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- .card-block -->
|
</td>
|
||||||
</div>
|
|
||||||
<!-- .card -->
|
</tr>
|
||||||
<!-- End Header BG Table -->
|
<?php endforeach; ?>
|
||||||
</div>
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php CPagination::show('page'); ?>
|
||||||
|
</div>
|
||||||
|
<!-- .card-block -->
|
||||||
|
</div>
|
||||||
|
<!-- .card -->
|
||||||
|
<!-- End Header BG Table -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/inc/footer.php';
|
require_once __DIR__ . '/inc/footer.php';
|
||||||
?>
|
?>
|
||||||
@@ -32,6 +32,11 @@ define('USE_CACHE', true);
|
|||||||
*/
|
*/
|
||||||
define('CACHEDIR', $_SERVER['DOCUMENT_ROOT'].'/cache/');
|
define('CACHEDIR', $_SERVER['DOCUMENT_ROOT'].'/cache/');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Время актуальности кэша в секундах
|
||||||
|
*/
|
||||||
|
define('CACHE_TTL', 3600);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сервер базы данных
|
* Сервер базы данных
|
||||||
*/
|
*/
|
||||||
|
|||||||
+10
-2
@@ -69,8 +69,16 @@ function pre($arr, $stop = false) {
|
|||||||
* @param int $userId
|
* @param int $userId
|
||||||
*/
|
*/
|
||||||
function isHaveAccessToDevice($deviceId, $userId){
|
function isHaveAccessToDevice($deviceId, $userId){
|
||||||
global $DB;
|
$cacheId = md5('isHaveAccessToDevice_'.$deviceId.'_'.$userId);
|
||||||
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
|
echo $cacheId;
|
||||||
|
if(CCache::checkCache($cacheId)){
|
||||||
|
$arDevice = CCache::getCache($cacheId);
|
||||||
|
} else {
|
||||||
|
global $DB;
|
||||||
|
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
|
||||||
|
CCache::writeCache($cacheId, $arDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if($arDevice){
|
if($arDevice){
|
||||||
if($arDevice[0]['user'] == $userId){
|
if($arDevice[0]['user'] == $userId){
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ class CCache
|
|||||||
if (!self::$cache_enabled) {
|
if (!self::$cache_enabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(self::ageOfCache($name) > CACHE_TTL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (file_exists(self::$cache_dir . md5($name) . '.tmp')) {
|
if (file_exists(self::$cache_dir . md5($name) . '.tmp')) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -187,15 +190,11 @@ class CCache
|
|||||||
* Получение времени существованя кэша в секундах
|
* Получение времени существованя кэша в секундах
|
||||||
*
|
*
|
||||||
* @param string $name Имя элемента кэша
|
* @param string $name Имя элемента кэша
|
||||||
* @return false|int Время в секундах или false
|
* @return int Время в секундах или false
|
||||||
*/
|
*/
|
||||||
public static function ageOfCache(string $name)
|
public static function ageOfCache(string $name)
|
||||||
{ // Получить возраст элемента кэша
|
{
|
||||||
if (self::checkCache($name)) {
|
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
|
||||||
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user