booleanise trash
This commit is contained in:
parent
68cdfc21ee
commit
164637188e
1 changed files with 11 additions and 9 deletions
|
@ -92,12 +92,12 @@ class Trash extends Extension
|
||||||
const SEARCH_REGEXP = "/^in:trash$/";
|
const SEARCH_REGEXP = "/^in:trash$/";
|
||||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||||
{
|
{
|
||||||
global $user, $database;
|
global $user;
|
||||||
|
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
|
||||||
if (is_null($event->term) && $this->no_trash_query($event->context)) {
|
if (is_null($event->term) && $this->no_trash_query($event->context)) {
|
||||||
$event->add_querylet(new Querylet($database->scoreql_to_sql("trash = SCORE_BOOL_N ")));
|
$event->add_querylet(new Querylet("trash = :false", ["false"=>false]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($event->term)) {
|
if (is_null($event->term)) {
|
||||||
|
@ -105,7 +105,7 @@ class Trash extends Extension
|
||||||
}
|
}
|
||||||
if (preg_match(self::SEARCH_REGEXP, strtolower($event->term), $matches)) {
|
if (preg_match(self::SEARCH_REGEXP, strtolower($event->term), $matches)) {
|
||||||
if ($user->can(Permissions::VIEW_TRASH)) {
|
if ($user->can(Permissions::VIEW_TRASH)) {
|
||||||
$event->add_querylet(new Querylet($database->scoreql_to_sql("trash = SCORE_BOOL_Y ")));
|
$event->add_querylet(new Querylet("trash = :true", ["true"=>true]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,13 +133,13 @@ class Trash extends Extension
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function set_trash($image_id, $trash)
|
public static function set_trash(int $image_id, bool $trash)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$database->execute(
|
$database->execute(
|
||||||
"UPDATE images SET trash = :trash WHERE id = :id",
|
"UPDATE images SET trash = :trash WHERE id = :id",
|
||||||
["trash"=>$database->scoresql_value_prepare($trash),"id"=>$image_id]
|
["trash"=>$trash,"id"=>$image_id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
||||||
|
@ -182,11 +182,13 @@ class Trash extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if ($this->get_version(TrashConfig::VERSION) < 1) {
|
if ($this->get_version(TrashConfig::VERSION) < 1) {
|
||||||
$database->execute($database->scoreql_to_sql(
|
$database->execute("ALTER TABLE images ADD COLUMN trash BOOLEAN NOT NULL DEFAULT FALSE");
|
||||||
"ALTER TABLE images ADD COLUMN trash SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
|
|
||||||
));
|
|
||||||
$database->execute("CREATE INDEX images_trash_idx ON images(trash)");
|
$database->execute("CREATE INDEX images_trash_idx ON images(trash)");
|
||||||
$this->set_version(TrashConfig::VERSION, 1);
|
$this->set_version(TrashConfig::VERSION, 2);
|
||||||
|
}
|
||||||
|
if ($this->get_version(TrashConfig::VERSION) < 2) {
|
||||||
|
$database->standardise_boolean("images", "trash");
|
||||||
|
$this->set_version(TrashConfig::VERSION, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue