boolinate locked

This commit is contained in:
Shish 2020-10-27 01:05:12 +00:00
parent ee7a4f178c
commit 10f563ee37
3 changed files with 8 additions and 12 deletions

View file

@ -659,16 +659,12 @@ class Image
return $this->locked; return $this->locked;
} }
public function set_locked(bool $tf): void public function set_locked(bool $locked): void
{ {
global $database; global $database;
$ln = $tf ? "Y" : "N"; if ($locked !== $this->locked) {
$sln = $database->scoreql_to_sql('SCORE_BOOL_'.$ln); $database->execute("UPDATE images SET locked=:yn WHERE id=:id", ["yn"=>$locked, "id"=>$this->id]);
$sln = str_replace("'", "", $sln); log_info("core_image", "Setting Image #{$this->id} lock to: $locked");
$sln = str_replace('"', "", $sln);
if (bool_escape($sln) !== $this->locked) {
$database->execute("UPDATE images SET locked=:yn WHERE id=:id", ["yn"=>$sln, "id"=>$this->id]);
log_info("core_image", "Setting Image #{$this->id} lock to: $ln");
} }
} }

View file

@ -255,7 +255,7 @@ function create_tables(Database $db)
width INTEGER NOT NULL, width INTEGER NOT NULL,
height INTEGER NOT NULL, height INTEGER NOT NULL,
posted TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, posted TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, locked BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT
"); ");
$db->execute("CREATE INDEX images_owner_id_idx ON images(owner_id)", []); $db->execute("CREATE INDEX images_owner_id_idx ON images(owner_id)", []);

View file

@ -32,9 +32,9 @@ class Upgrade extends Extension
// now done again as v9 with PDO // now done again as v9 with PDO
if ($this->get_version("db_version") < 8) { if ($this->get_version("db_version") < 8) {
$database->execute($database->scoreql_to_sql( $database->execute(
"ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N" "ALTER TABLE images ADD COLUMN locked BOOLEAN NOT NULL DEFAULT FALSE"
)); );
$this->set_version("db_version", 8); $this->set_version("db_version", 8);
} }