1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00
This commit is contained in:
J. King 2017-09-28 09:01:43 -04:00
parent 5ebf6cb689
commit 96ebf936e4
9 changed files with 27 additions and 21 deletions

View file

@ -358,7 +358,9 @@ class Database {
if ($id==$parent) {
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(
"WITH RECURSIVE
target as (select ? as user, ? as source, ? as dest, ? as rename),
@ -377,6 +379,7 @@ class Database {
// if using the desired parent would create a circular dependence, throw a different exception
throw new Db\ExceptionInput("circularDependence", $errData);
} 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")]);
}
return $parent;
@ -391,6 +394,9 @@ class Database {
} elseif (!($info & ValueInfo::VALID)) {
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "name", 'type' => "string"]);
} 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()) {
throw new Db\ExceptionInput("constraintViolation", ["action" => $this->caller(), "field" => "name"]);
}

View file

@ -13,7 +13,7 @@ class ValueInfo {
const EMPTY = 1 << 2;
const WHITE = 1 << 3;
static public function int($value): int {
public static function int($value): int {
$out = 0;
if (is_null($value)) {
// check if the input is null
@ -50,7 +50,7 @@ class ValueInfo {
return $out;
}
static public function str($value): int {
public static function str($value): int {
$out = 0;
// check if the input is null
if (is_null($value)) {
@ -75,7 +75,7 @@ class ValueInfo {
return $out;
}
static public function id($value, bool $allowNull = false): bool {
public static function id($value, bool $allowNull = false): bool {
$info = self::int($value);
if ($allowNull && ($info & self::NULL)) { // null (and allowed)
return true;