booleanise relationships

This commit is contained in:
Shish 2020-10-26 18:55:03 +00:00
parent ed64cea8f6
commit 19d85e415d

View File

@ -31,19 +31,20 @@ class Relationships extends Extension
{ {
global $database; global $database;
// Create the database tables
if ($this->get_version("ext_relationships_version") < 1) { if ($this->get_version("ext_relationships_version") < 1) {
$database->execute("ALTER TABLE images ADD parent_id INT"); $database->execute("ALTER TABLE images ADD parent_id INT");
$database->execute($database->scoreql_to_sql("ALTER TABLE images ADD has_children SCORE_BOOL DEFAULT SCORE_BOOL_N NOT NULL")); $database->execute("ALTER TABLE images ADD has_children BOOLEAN DEFAULT FALSE NOT NULL");
$database->execute("CREATE INDEX images__parent_id ON images(parent_id)"); $database->execute("CREATE INDEX images__parent_id ON images(parent_id)");
$this->set_version("ext_relationships_version", 1); $this->set_version("ext_relationships_version", 1);
} }
if ($this->get_version("ext_relationships_version") < 2) { if ($this->get_version("ext_relationships_version") < 2) {
$database->execute("CREATE INDEX images__has_children ON images(has_children)"); $database->execute("CREATE INDEX images__has_children ON images(has_children)");
$this->set_version("ext_relationships_version", 2); $this->set_version("ext_relationships_version", 2);
} }
if ($this->get_version("ext_relationships_version") < 3) {
$database->standardise_boolean("images", "has_children");
$this->set_version("ext_relationships_version", 3);
}
} }
public function onImageInfoSet(ImageInfoSetEvent $event) public function onImageInfoSet(ImageInfoSetEvent $event)
@ -204,9 +205,8 @@ class Relationships extends Extension
["pid"=>$parent_id] ["pid"=>$parent_id]
); );
$database->execute( $database->execute(
"UPDATE images "UPDATE images SET has_children = :has_children WHERE id = :pid",
SET has_children = :has_children WHERE id = :pid", ["has_children"=>$children>0, "pid"=>$parent_id]
["has_children"=>$database->scoresql_value_prepare($children>0), "pid"=>$parent_id]
); );
} }
} }