edit-shedule.php
См. документацию.
1 <?php
2 
3 /**
4  * @file
5  * @brief обработчик устанавливает расписание cron задачи
6  */
7 
8 isset($user) or require $_SERVER['DOCUMENT_ROOT'] . '/page/404.php';
9 
10 header("Content-type: application/json");
11 
12 array_walk_recursive($_POST, function (&$item) {
13  $item = trim(htmlspecialchars($item, ENT_QUOTES));
14 });
15 
16 if (!($row = Wrong\Models\Crontabs::find($_POST['id']))) {
17  exit(json_encode(['error' => 'Ошибка']));
18 }
19 
20 if (!$user->access()->write($row)) {
21  exit(json_encode(['error' => 'Недостаточно прав!']));
22 }
23 
24 try {
25  $cron = Cron\CronExpression::factory($_POST['shedule']);
26 } catch (\Throwable $th) {
27  exit(json_encode(['error' => $th->getMessage()]));
28 }
29 
30 $shedules = [];
31 for ($i = 0; $i < 25; $i++) {
32  $shedules[] = $cron->getNextRunDate(null, $i)->format('Y-m-d H:i:s');
33 }
34 
35 if (count($shedules) != 25) {
36  exit(json_encode(['error' => 'Расписание указано некорректно']));
37 }
38 
39 $_POST['run_at'] = $shedules[0];
40 
41 $sth = $dbh->prepare("UPDATE `crontabs` SET `shedule` = :shedule, `run_at` = :run_at WHERE `id` = :id");
42 $sth->bindValue(':shedule', $_POST['shedule']);
43 $sth->bindValue(':run_at', $shedules[0]);
44 $sth->bindValue(':id', $row->id);
45 $sth->execute();
46 
47 if ($sth->errorCode() == '00000') {
48  $mem = new Wrong\Memory\Cache('cron');
49  $mem->delete($row->id);
50  exit(json_encode(['result' => 'ok', 'message' => 'Расписание успешно установлено']));
51 }
52 
53 exit(json_encode(['error' => 'Ошибка']));
54 
55 
for($i=0; $i< 25; $i++) if(count($shedules) !=25) $_POST['run_at']
catch(\Throwable $th) $shedules
$sth
$mem
Definition: settings.php:129
if(empty($_POST['name'])) if(empty($_POST['type'])||!in_array($_POST['type'], ['page', 'modal', 'incode', 'select', 'action'])) $i
Cache класс, отвечающий за кеширование
Definition: Cache.php:19
$user
Definition: from-user.php:38
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
Definition: from-user.php:36
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit
Definition: install.php:198
$dbh
Definition: session.php:19