hotfix CCache and enable use cache

This commit is contained in:
rsgrinko committed 2021-12-03 22:53:11 +03:00
1 parent fa02e60b5d
commit d5bdfbc33c
4 files changed
+116 -97

No files matched your search

+95 -88
View File
@@ -1,103 +1,110 @@
<?php
require_once __DIR__ . '/inc/bootstrap.php';
if(!CUSer::is_admin()) {
die('403 - Access denied');
}
require_once __DIR__ . '/inc/header.php';
?>
<?php
if(
isset($_REQUEST['run_task']) and $_REQUEST['run_task'] == 'Y' and
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
):
CCron::runTask($_REQUEST['task_id']);
require_once __DIR__ . '/inc/bootstrap.php';
if (!CUSer::is_admin()) {
die('403 - Access denied');
}
require_once __DIR__ . '/inc/header.php';
?>
<script>
$(document).ready(function(){
alert("Задание выполнено");
});
</script>
<?php
if (
isset($_REQUEST['run_task']) and $_REQUEST['run_task'] == 'Y' and
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
):
CCron::runTask($_REQUEST['task_id']);
?>
<script>
$(document).ready(function () {
alert("Задание выполнено");
});
</script>
<?php endif; ?>
<?php
if(
isset($_REQUEST['remove_task']) and $_REQUEST['remove_task'] == 'Y' and
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
):
CCron::removeTask($_REQUEST['task_id']);
?>
<script>
$(document).ready(function(){
alert("Задание удалено");
});
</script>
if (
isset($_REQUEST['remove_task']) and $_REQUEST['remove_task'] == 'Y' and
isset($_REQUEST['task_id']) and !empty($_REQUEST['task_id'])
):
CCron::removeTask($_REQUEST['task_id']);
?>
<script>
$(document).ready(function () {
alert("Задание удалено");
});
</script>
<?php endif; ?>
<div class="row maxheight">
<div class="col-lg-12">
<!-- Header BG Table -->
<div class="card">
<div class="card-header">
<h4>Планировщик</h4>
<div class="card-actions">
<code>CCron <a href="add_cron.php" class="btn btn-success">Добавить</a></code>
</div>
</div>
<div class="card-block">
<?php
CPagination::execute($_REQUEST['page'], CCron::count_tasks(), PAGINATION_LIMIT);
$limit = CPagination::getLimit();
?>
<div class="table-responsive">
<table class="table table-striped table-borderless table-header-bg">
<thead>
<tr>
<th class="text-center" style="width: 50px;">ID</th>
<th>Название</th>
<th>Описание</th>
<th>Интервал</th>
<th style="width: 116px;">Был запуск</th>
<th>Активность</th>
<th>Команда</th>
<th class="text-center" style="width: 110px;"></th>
</tr>
</thead>
<tbody>
<?php foreach(CCron::getTasks($limit, 'ASC') as $task): ?>
<tr data-name="<?php echo htmlspecialchars($task['name']);?>" data-id="<?php echo $task['id'];?>">
<td class="mob_hide"><?php echo $task['id'];?></td>
<td><?php echo $task['name'];?></td>
<td class="mob_hide"><?php echo $task['description'];?></td>
<td class="mob_hide"><?php echo $task['period'];?></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['active'] == 'Y' ? '<button class="btn btn-app btn-block">Да</button>' : '<button class="btn btn-app-red btn-block">Нет</button>';?></td>
<td class="mob_hide"><code><?php echo htmlspecialchars(base64_decode($task['command']));?></code></td>
<td class="text-center">
<div class="btn-group">
<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>
<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>
<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>
</div>
</td>
<div class="col-lg-12">
<!-- Header BG Table -->
<div class="card">
<div class="card-header">
<h4>Планировщик</h4>
<div class="card-actions">
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php CPagination::show('page'); ?>
<code>CCron <a href="add_cron.php" class="btn btn-success">Добавить</a></code>
</div>
</div>
<div class="card-block">
<?php
CPagination::execute($_REQUEST['page'], CCron::count_tasks(), PAGINATION_LIMIT);
$limit = CPagination::getLimit();
?>
<div class="table-responsive">
<table class="table table-striped table-borderless table-header-bg">
<thead>
<tr>
<th class="text-center" style="width: 50px;">ID</th>
<th>Название</th>
<th>Описание</th>
<th>Интервал</th>
<th style="width: 116px;">Был запуск</th>
<th>Активность</th>
<th>Команда</th>
<th class="text-center" style="width: 110px;"></th>
</tr>
</thead>
<tbody>
<?php foreach (CCron::getTasks($limit, 'ASC') as $task): ?>
<tr data-name="<?php echo htmlspecialchars($task['name']); ?>"
data-id="<?php echo $task['id']; ?>">
<td class="mob_hide"><?php echo $task['id']; ?></td>
<td><?php echo $task['name']; ?></td>
<td class="mob_hide"><?php echo $task['description']; ?></td>
<td class="mob_hide"><?php echo $task['period']; ?></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['active'] == 'Y' ? '<button class="btn btn-app btn-block">Да</button>' : '<button class="btn btn-app-red btn-block">Нет</button>'; ?></td>
<td class="mob_hide">
<code><?php echo htmlspecialchars(base64_decode($task['command'])); ?></code></td>
<td class="text-center">
<div class="btn-group">
<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>
<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>
<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>
</div>
<!-- .card-block -->
</div>
<!-- .card -->
<!-- End Header BG Table -->
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php CPagination::show('page'); ?>
</div>
<!-- .card-block -->
</div>
<!-- .card -->
<!-- End Header BG Table -->
</div>
</div>
<?php
require_once __DIR__ . '/inc/footer.php';
require_once __DIR__ . '/inc/footer.php';
?>
+5
View File
@@ -32,6 +32,11 @@ define('USE_CACHE', true);
*/
define('CACHEDIR', $_SERVER['DOCUMENT_ROOT'].'/cache/');
/**
* Время актуальности кэша в секундах
*/
define('CACHE_TTL', 3600);
/**
* Сервер базы данных
*/
+10 -2
View File
@@ -69,8 +69,16 @@ function pre($arr, $stop = false) {
* @param int $userId
*/
function isHaveAccessToDevice($deviceId, $userId){
global $DB;
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
$cacheId = md5('isHaveAccessToDevice_'.$deviceId.'_'.$userId);
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[0]['user'] == $userId){
+6 -7
View File
@@ -72,6 +72,9 @@ class CCache
if (!self::$cache_enabled) {
return false;
}
if(self::ageOfCache($name) > CACHE_TTL) {
return false;
}
if (file_exists(self::$cache_dir . md5($name) . '.tmp')) {
return true;
} else {
@@ -187,15 +190,11 @@ class CCache
* Получение времени существованя кэша в секундах
*
* @param string $name Имя элемента кэша
* @return false|int Время в секундах или false
* @return int Время в секундах или false
*/
public static function ageOfCache(string $name)
{ // Получить возраст элемента кэша
if (self::checkCache($name)) {
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
} else {
return false;
}
{
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
}
}