aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-11-08 17:03:39 +0100
committerLaria Carolin Chabowski <laria@laria.me>2020-11-08 17:03:39 +0100
commit2f2fa9f27db1dc630180babf7efa206157f37003 (patch)
tree07436f7b2669707572716578370a2b8ded8e8141 /ratatoeskr/sys
parent87eb96b81c196ad3fe652128084371b4b510207e (diff)
downloadratatoeskr-cms-2f2fa9f27db1dc630180babf7efa206157f37003.tar.gz
ratatoeskr-cms-2f2fa9f27db1dc630180babf7efa206157f37003.tar.bz2
ratatoeskr-cms-2f2fa9f27db1dc630180babf7efa206157f37003.zip
Make dbversion a method of Database
We currently don't actually use it, but it might come in handy, so let's keep it.
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/Database.php20
-rw-r--r--ratatoeskr/sys/models.php27
2 files changed, 20 insertions, 27 deletions
diff --git a/ratatoeskr/sys/Database.php b/ratatoeskr/sys/Database.php
index 4f9014a..d9fc327 100644
--- a/ratatoeskr/sys/Database.php
+++ b/ratatoeskr/sys/Database.php
@@ -110,4 +110,24 @@ class Database
{
return (int)$this->pdo->lastInsertId();
}
+
+ /**
+ * Get the version of the database structure currently used.
+ * @return int
+ */
+ public function dbversion(): int
+ {
+ $tableName = $this->subPrefix("PREFIX_meta");
+
+ /* Is the meta table present? If no, the version is 0. */
+ $stmt = $this->query("SHOW TABLES LIKE ?", $tableName);
+ list($table) = $stmt->fetch();
+ if ($table != $tableName) {
+ return 0;
+ }
+
+ $stmt = $this->query("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'");
+ $sqlrow = $stmt->fetch();
+ return (int)unserialize(base64_decode($sqlrow["value"]));
+ }
}
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index b24345f..01ffeb3 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -3173,33 +3173,6 @@ class ArticleExtradata extends KVStorage
}
/*
- * Function: dbversion
- * Get the version of the database structure currently used.
- *
- * Returns:
- * The numerical version of the current database structure.
- */
-function dbversion()
-{
- global $config;
-
- /* Is the meta table present? If no, the version is 0. */
- $stmt = qdb(
- "SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?",
- $config["mysql"]["db"],
- sub_prefix("PREFIX_meta")
- );
- list($n) = $stmt->fetch();
- if ($n == 0) {
- return 0;
- }
-
- $stmt = qdb("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'");
- $sqlrow = $stmt->fetch();
- return unserialize(base64_decode($sqlrow["value"]));
-}
-
-/*
* Function: clean_database
* Clean up the database
*/