edit-method.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 if (empty($_POST['method']) || !in_array($_POST['method'], ['GET', 'POST', 'PUT', 'DELETE', 'CLI'])) {
25  exit(json_encode(['error' => 'Метод запроса указан некорректно']));
26 }
27 
28 $sth = $dbh->prepare("UPDATE `crontabs` SET `method` = :method WHERE `id` = :id");
29 $sth->bindValue(':method', $_POST['method']);
30 $sth->bindValue(':id', $row->id);
31 $sth->execute();
32 
33 if ($sth->errorCode() == '00000') {
34  $mem = new Wrong\Memory\Cache('cron');
35  $mem->delete($row->id);
36  exit(json_encode(['result' => 'ok', 'message' => 'Метод успешно установлен']));
37 }
38 
39 exit(json_encode(['error' => 'Ошибка']));
40 
$_POST['groups']
Definition: add-action.php:16
if(!($row=Wrong\Models\Crontabs::find($_POST['id']))) if(! $user->access() ->write($row)) if(empty($_POST['method'])||!in_array($_POST['method'], ['GET', 'POST', 'PUT', 'DELETE', 'CLI'])) $sth
Definition: edit-method.php:28
$mem
Definition: settings.php:129
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