mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 06:34:55 +00:00
CS fixes
This commit is contained in:
parent
5ebf6cb689
commit
96ebf936e4
9 changed files with 27 additions and 21 deletions
|
@ -322,7 +322,7 @@ class Database {
|
||||||
|
|
||||||
protected function folderValidateId(string $user, $id = null, bool $subject = false): array {
|
protected function folderValidateId(string $user, $id = null, bool $subject = false): array {
|
||||||
// if the specified ID is not a non-negative integer (or null), this will always fail
|
// if the specified ID is not a non-negative integer (or null), this will always fail
|
||||||
if(!ValueInfo::id($id, true)) {
|
if (!ValueInfo::id($id, true)) {
|
||||||
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "folder", 'type' => "int >= 0"]);
|
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "folder", 'type' => "int >= 0"]);
|
||||||
}
|
}
|
||||||
// if a null or zero ID is specified this is a no-op
|
// if a null or zero ID is specified this is a no-op
|
||||||
|
@ -358,7 +358,9 @@ class Database {
|
||||||
if ($id==$parent) {
|
if ($id==$parent) {
|
||||||
throw new Db\ExceptionInput("circularDependence", $errData);
|
throw new Db\ExceptionInput("circularDependence", $errData);
|
||||||
}
|
}
|
||||||
// make sure both that the prospective parent exists, and that the it is not one of its children (a circular dependence)
|
// make sure both that the prospective parent exists, and that the it is not one of its children (a circular dependence);
|
||||||
|
// also make sure that a folder with the same prospective name and parent does not already exist: if the parent is null,
|
||||||
|
// SQL will happily accept duplicates (null is not unique), so we must do this check ourselves
|
||||||
$p = $this->db->prepare(
|
$p = $this->db->prepare(
|
||||||
"WITH RECURSIVE
|
"WITH RECURSIVE
|
||||||
target as (select ? as user, ? as source, ? as dest, ? as rename),
|
target as (select ? as user, ? as source, ? as dest, ? as rename),
|
||||||
|
@ -368,7 +370,7 @@ class Database {
|
||||||
((select dest from target) is null or exists(select id from arsse_folders join target on owner is user and id is dest)) as extant,
|
((select dest from target) is null or exists(select id from arsse_folders join target on owner is user and id is dest)) as extant,
|
||||||
not exists(select id from folders where id is (select dest from target)) as valid,
|
not exists(select id from folders where id is (select dest from target)) as valid,
|
||||||
not exists(select id from arsse_folders join target on parent is dest and name is coalesce((select rename from target),(select name from arsse_folders join target on id is source))) as available
|
not exists(select id from arsse_folders join target on parent is dest and name is coalesce((select rename from target),(select name from arsse_folders join target on id is source))) as available
|
||||||
", "str", "int", "int","str"
|
", "str", "int", "int", "str"
|
||||||
)->run($user, $id, $parent, $name)->getRow();
|
)->run($user, $id, $parent, $name)->getRow();
|
||||||
if (!$p['extant']) {
|
if (!$p['extant']) {
|
||||||
// if the parent doesn't exist or doesn't below to the user, throw an exception
|
// if the parent doesn't exist or doesn't below to the user, throw an exception
|
||||||
|
@ -377,6 +379,7 @@ class Database {
|
||||||
// if using the desired parent would create a circular dependence, throw a different exception
|
// if using the desired parent would create a circular dependence, throw a different exception
|
||||||
throw new Db\ExceptionInput("circularDependence", $errData);
|
throw new Db\ExceptionInput("circularDependence", $errData);
|
||||||
} elseif (!$p['available']) {
|
} elseif (!$p['available']) {
|
||||||
|
// if a folder with the same parent and name already exists, throw another different exception
|
||||||
throw new Db\ExceptionInput("constraintViolation", ["action" => $this->caller(), "field" => (is_null($name) ? "parent" : "name")]);
|
throw new Db\ExceptionInput("constraintViolation", ["action" => $this->caller(), "field" => (is_null($name) ? "parent" : "name")]);
|
||||||
}
|
}
|
||||||
return $parent;
|
return $parent;
|
||||||
|
@ -390,7 +393,10 @@ class Database {
|
||||||
throw new Db\ExceptionInput("whitespace", ["action" => $this->caller(), "field" => "name"]);
|
throw new Db\ExceptionInput("whitespace", ["action" => $this->caller(), "field" => "name"]);
|
||||||
} elseif (!($info & ValueInfo::VALID)) {
|
} elseif (!($info & ValueInfo::VALID)) {
|
||||||
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "name", 'type' => "string"]);
|
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "name", 'type' => "string"]);
|
||||||
} elseif($checkDuplicates) {
|
} elseif ($checkDuplicates) {
|
||||||
|
// make sure that a folder with the same prospective name and parent does not already exist: if the parent is null,
|
||||||
|
// SQL will happily accept duplicates (null is not unique), so we must do this check ourselves
|
||||||
|
$parent = $parent ? $parent : null;
|
||||||
if ($this->db->prepare("SELECT exists(select id from arsse_folders where parent is ? and name is ?)", "int", "str")->run($parent, $name)->getValue()) {
|
if ($this->db->prepare("SELECT exists(select id from arsse_folders where parent is ? and name is ?)", "int", "str")->run($parent, $name)->getValue()) {
|
||||||
throw new Db\ExceptionInput("constraintViolation", ["action" => $this->caller(), "field" => "name"]);
|
throw new Db\ExceptionInput("constraintViolation", ["action" => $this->caller(), "field" => "name"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Context {
|
||||||
protected function cleanArray(array $spec): array {
|
protected function cleanArray(array $spec): array {
|
||||||
$spec = array_values($spec);
|
$spec = array_values($spec);
|
||||||
for ($a = 0; $a < sizeof($spec); $a++) {
|
for ($a = 0; $a < sizeof($spec); $a++) {
|
||||||
if(ValueInfo::id($spec[$a])) {
|
if (ValueInfo::id($spec[$a])) {
|
||||||
$spec[$a] = (int) $spec[$a];
|
$spec[$a] = (int) $spec[$a];
|
||||||
} else {
|
} else {
|
||||||
$spec[$a] = 0;
|
$spec[$a] = 0;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ValueInfo {
|
||||||
const EMPTY = 1 << 2;
|
const EMPTY = 1 << 2;
|
||||||
const WHITE = 1 << 3;
|
const WHITE = 1 << 3;
|
||||||
|
|
||||||
static public function int($value): int {
|
public static function int($value): int {
|
||||||
$out = 0;
|
$out = 0;
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
// check if the input is null
|
// check if the input is null
|
||||||
|
@ -40,7 +40,7 @@ class ValueInfo {
|
||||||
// mark validity
|
// mark validity
|
||||||
$out += self::VALID;
|
$out += self::VALID;
|
||||||
// mark zeroness
|
// mark zeroness
|
||||||
if($value==0) {
|
if ($value==0) {
|
||||||
$out += self::ZERO;
|
$out += self::ZERO;
|
||||||
}
|
}
|
||||||
// mark negativeness
|
// mark negativeness
|
||||||
|
@ -50,7 +50,7 @@ class ValueInfo {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function str($value): int {
|
public static function str($value): int {
|
||||||
$out = 0;
|
$out = 0;
|
||||||
// check if the input is null
|
// check if the input is null
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
|
@ -75,7 +75,7 @@ class ValueInfo {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function id($value, bool $allowNull = false): bool {
|
public static function id($value, bool $allowNull = false): bool {
|
||||||
$info = self::int($value);
|
$info = self::int($value);
|
||||||
if ($allowNull && ($info & self::NULL)) { // null (and allowed)
|
if ($allowNull && ($info & self::NULL)) { // null (and allowed)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -50,7 +50,7 @@ abstract class AbstractHandler implements Handler {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
if(is_bool($value)) {
|
if (is_bool($value)) {
|
||||||
$out[$key] = var_export($value, true);
|
$out[$key] = var_export($value, true);
|
||||||
} elseif (!is_scalar($value)) {
|
} elseif (!is_scalar($value)) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue