From 08a4a6d41f647a0b92ca8a028d62ac6fbd38b1b7 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 26 Oct 2020 17:28:21 +0000 Subject: [PATCH] pm also used char for postgres --- core/database.php | 8 +++++++- ext/pm/main.php | 3 +-- ext/wiki/main.php | 15 +-------------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/core/database.php b/core/database.php index 1cba1666..cc643c81 100644 --- a/core/database.php +++ b/core/database.php @@ -356,7 +356,7 @@ class Database return $this->db; } - public function standardise_boolean(string $table, string $column): void + public function standardise_boolean(string $table, string $column, boolean $include_postgres=false): void { $d = $this->get_driver_name(); if ($d == DatabaseDriver::MYSQL) { @@ -373,5 +373,11 @@ class Database # text, so we can in-place replace a char with a bool $this->execute("UPDATE $table SET $column = ($column IN ('Y', 1))"); } + if ($d == DatabaseDriver::PGSQL) { + $this->execute("ALTER TABLE $table ADD COLUMN ${column}_b BOOLEAN DEFAULT FALSE NOT NULL"); + $this->execute("UPDATE $table SET ${column}_b = ($column = 'Y')"); + $this->execute("ALTER TABLE $table DROP COLUMN $column"); + $this->execute("ALTER TABLE $table RENAME COLUMN ${column}_b TO $column"); + } } } diff --git a/ext/pm/main.php b/ext/pm/main.php index ee3b3b77..fb72fea5 100644 --- a/ext/pm/main.php +++ b/ext/pm/main.php @@ -96,7 +96,7 @@ class PrivMsg extends Extension if ($config->get_int("pm_version") < 3) { log_info("pm", "Updating is_read boolean"); - $database->standardise_boolean("private_message", "is_read"); + $database->standardise_boolean("private_message", "is_read", true); $config->set_int("pm_version", 3); log_info("pm", "extension upgraded"); } @@ -114,7 +114,6 @@ class PrivMsg extends Extension } } - public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 5e3dce9f..c85eeeb5 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -146,20 +146,7 @@ class Wiki extends Extension $this->set_version("ext_wiki_version", 2); } if ($this->get_version("ext_wiki_version") < 3) { - $d = $database->get_driver_name(); - if ($d == DatabaseDriver::MYSQL) { - $database->execute("ALTER TABLE wiki_pages MODIFY COLUMN locked BOOLEAN;"); - $database->execute("UPDATE wiki_pages SET locked=0 WHERE locked=2;"); - } - if ($d == DatabaseDriver::SQLITE) { - $database->execute("UPDATE wiki_pages SET locked = (locked IN ('Y', 1))"); - } - if ($d == DatabaseDriver::PGSQL) { - $database->execute("ALTER TABLE wiki_pages ADD COLUMN locked_b BOOLEAN DEFAULT FALSE NOT NULL"); - $database->execute("UPDATE wiki_pages SET locked_b = (locked = 'Y')"); - $database->execute("ALTER TABLE wiki_pages DROP COLUMN locked"); - $database->execute("ALTER TABLE wiki_pages RENAME COLUMN locked_b TO locked"); - } + $database->standardise_boolean("wiki_pages", "locked", true); $this->set_version("ext_wiki_version", 3); } }