aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/DB_Upgrade.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/DB_Upgrade.php')
-rw-r--r--Zotlabs/Lib/DB_Upgrade.php62
1 files changed, 40 insertions, 22 deletions
diff --git a/Zotlabs/Lib/DB_Upgrade.php b/Zotlabs/Lib/DB_Upgrade.php
index b6e3f7b7b..e11c2eb10 100644
--- a/Zotlabs/Lib/DB_Upgrade.php
+++ b/Zotlabs/Lib/DB_Upgrade.php
@@ -1,21 +1,39 @@
<?php
+/**
+ * A class to handle database schema upgrades.
+ *
+ * SPDX-FileCopyrightText: 2024 Hubzilla Community
+ * SPDX-FileContributor: Harald Eilertsen
+ *
+ * SPDX-License-Identifier: MIT
+ */
namespace Zotlabs\Lib;
-
+use Zotlabs\Lib\Config;
+
+/**
+ * Upgrade the database schema if necessary.
+ *
+ * Compares the currently active database schema version with the version
+ * required for this version of Hubzilla, and performs the upgrade if needed.
+ *
+ * If the difference consists of more than one revision of the schema, each of
+ * the intermediate upgrades are performed in turn.
+ */
class DB_Upgrade {
- public $config_name = '';
- public $func_prefix = '';
-
- function __construct($db_revision) {
+ /**
+ * Check the installed and required schema versions and perform the upgrade
+ * if necessary.
+ *
+ * @param int $db_version The required DB schema version.
+ */
+ public static function run(int $db_revision): void {
- $this->config_name = 'db_version';
- $this->func_prefix = '_';
-
- $build = get_config('system', 'db_version', 0);
+ $build = Config::Get('system', 'db_version', 0);
if(! intval($build))
- $build = set_config('system', 'db_version', $db_revision);
+ $build = Config::Set('system', 'db_version', $db_revision);
if($build == $db_revision) {
// Nothing to be done.
@@ -27,7 +45,7 @@ class DB_Upgrade {
logger('Critical: check_config unable to determine database schema version');
return;
}
-
+
$current = intval($db_revision);
if($stored < $current) {
@@ -38,7 +56,7 @@ class DB_Upgrade {
for($x = $stored + 1; $x <= $current; $x ++) {
$s = '_' . $x;
$cls = '\\Zotlabs\Update\\' . $s ;
- if(! class_exists($cls)) {
+ if(! class_exists($cls)) {
return;
}
@@ -52,10 +70,10 @@ class DB_Upgrade {
Config::Load('database');
- if(get_config('database', $s))
+ if(Config::Get('database', $s))
break;
- set_config('database',$s, '1');
-
+ Config::Set('database',$s, '1');
+
$c = new $cls();
@@ -65,10 +83,10 @@ class DB_Upgrade {
$source = t('Source code of failed update: ') . "\n\n" . @file_get_contents('Zotlabs/Update/' . $s . '.php');
-
+
// Prevent sending hundreds of thousands of emails by creating
- // a lockfile.
+ // a lockfile.
$lockfile = 'store/[data]/mailsent';
@@ -77,7 +95,7 @@ class DB_Upgrade {
@unlink($lockfile);
//send the administrator an e-mail
file_put_contents($lockfile, $x);
-
+
$r = q("select account_language from account where account_email = '%s' limit 1",
dbesc(\App::$config['system']['admin_email'])
);
@@ -86,7 +104,7 @@ class DB_Upgrade {
[
'toEmail' => \App::$config['system']['admin_email'],
'messageSubject' => sprintf( t('Update Error at %s'), z_root()),
- 'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
+ 'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
[
'$sitename' => \App::$config['system']['sitename'],
'$siteurl' => z_root(),
@@ -104,11 +122,11 @@ class DB_Upgrade {
pop_lang();
}
else {
- set_config('database',$s, 'success');
+ Config::Set('database',$s, 'success');
}
}
}
- set_config('system', 'db_version', $db_revision);
+ Config::Set('system', 'db_version', $db_revision);
}
}
-} \ No newline at end of file
+}