mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
more checks of arrays
This commit is contained in:
parent
70d3e08c11
commit
a4635a1933
3 changed files with 26 additions and 7 deletions
|
|
@ -102,7 +102,7 @@ class ListsController extends ApiController {
|
|||
function deleteId($id)
|
||||
{
|
||||
checkWriteAccess();
|
||||
$this->response->data = $this->deleteList($id);
|
||||
$this->response->data = $this->deleteList((int)$id);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -348,17 +348,19 @@ class ListsController extends ApiController {
|
|||
{
|
||||
$t = array();
|
||||
$t['total'] = 0;
|
||||
if (!is_array($this->req->jsonBody['order'])) {
|
||||
$order = $this->req->jsonBody['order'] ?? [];
|
||||
if (!array_is_list($order)) {
|
||||
return $t;
|
||||
}
|
||||
$db = DBConnection::instance();
|
||||
$order = $this->req->jsonBody['order'];
|
||||
$a = array();
|
||||
$setCase = '';
|
||||
foreach ($order as $ow => $id) {
|
||||
$id = (int)$id;
|
||||
$max = count($order);
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
$id = (int)$order[$i];
|
||||
$a[] = $id;
|
||||
$setCase .= "WHEN id=$id THEN $ow\n";
|
||||
$setCase .= "WHEN id=$id THEN $i\n";
|
||||
}
|
||||
$ids = implode(',', $a);
|
||||
$db->dq("UPDATE {$db->prefix}lists SET d_edited=?, ow = CASE\n $setCase END WHERE id IN ($ids)",
|
||||
|
|
|
|||
|
|
@ -197,3 +197,20 @@ function randomString(int $len = 16, string $chars = '0123456789abcdefghijklmnop
|
|||
}
|
||||
return implode('', $a);
|
||||
}
|
||||
|
||||
// taken from symfony/polyfill-php81 (MIT License)
|
||||
if (!function_exists('array_is_list')) {
|
||||
function array_is_list(array $array): bool
|
||||
{
|
||||
if ([] === $array || $array === array_values($array)) {
|
||||
return true;
|
||||
}
|
||||
$nextKey = -1;
|
||||
foreach ($array as $k => $v) {
|
||||
if ($k !== ++$nextKey) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -457,8 +457,8 @@ function logAndDie($userText, $errText = null)
|
|||
|
||||
function loadExtensions()
|
||||
{
|
||||
$a = Config::get('extensions');
|
||||
if (!$a || !is_array($a)) {
|
||||
$a = Config::get('extensions') ?: null;
|
||||
if (!$a || !array_is_list($a)) {
|
||||
return;
|
||||
}
|
||||
foreach ($a as $ext) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue