From 87f3fe24f7008dd1460cec1abd3ea7f3ae16679f Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Oct 2018 13:19:37 +0200 Subject: [PATCH] Moving UPDATE defines/constants out of boot --- boot.php | 19 ------------------- mod/admin.php | 9 +++++---- src/Core/Update.php | 3 +++ src/Database/DBStructure.php | 8 ++++++-- update.php | 21 +++++++++++---------- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/boot.php b/boot.php index 5973156ecd..efff5baffa 100644 --- a/boot.php +++ b/boot.php @@ -43,13 +43,6 @@ define('FRIENDICA_VERSION', '2018.12-dev'); define('DFRN_PROTOCOL_VERSION', '2.23'); define('NEW_UPDATE_ROUTINE_VERSION', 1170); -/** - * @brief Constants for the database update check - */ -const DB_UPDATE_NOT_CHECKED = 0; // Database check wasn't executed before -const DB_UPDATE_SUCCESSFUL = 1; // Database check was successful -const DB_UPDATE_FAILED = 2; // Database check failed - /** * @brief Constant with a HTML line break. * @@ -119,18 +112,6 @@ define('REGISTER_OPEN', 2); * @} */ -/** - * @name Update - * - * DB update return values - * @{ - */ -define('UPDATE_SUCCESS', 0); -define('UPDATE_FAILED', 1); -/** - * @} - */ - /** * @name CP * diff --git a/mod/admin.php b/mod/admin.php index 08c2ecbbc4..d97bac194d 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -16,6 +16,7 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Core\Theme; +use Friendica\Core\Update; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Database\DBStructure; @@ -864,10 +865,10 @@ function admin_page_summary(App $a) } } - if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) { + if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) { DBStructure::update(false, true); } - if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) { + if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) { $showwarning = true; $warningtext[] = L10n::t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.'); } @@ -1613,9 +1614,9 @@ function admin_page_dbsync(App $a) if (function_exists($func)) { $retval = $func(); - if ($retval === UPDATE_FAILED) { + if ($retval === Update::FAILED) { $o .= L10n::t("Executing %s failed with error: %s", $func, $retval); - } elseif ($retval === UPDATE_SUCCESS) { + } elseif ($retval === Update::SUCCESS) { $o .= L10n::t('Update %s was successfully applied.', $func); Config::set('database', $func, 'success'); } else { diff --git a/src/Core/Update.php b/src/Core/Update.php index a524830e75..d4bcd04bba 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -6,6 +6,9 @@ use Friendica\Database\DBStructure; class Update { + const SUCCESS = 0; + const FAILED = 1; + /** * Automatic database updates */ diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 9a14114de1..b24c513336 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -23,6 +23,10 @@ require_once 'include/text.php'; */ class DBStructure { + const UPDATE_NOT_CHECKED = 0; // Database check wasn't executed before + const UPDATE_SUCCESSFUL = 1; // Database check was successful + const UPDATE_FAILED = 2; // Database check failed + /** * Database structure definition loaded from config/dbstructure.php * @@ -535,9 +539,9 @@ class DBStructure Config::set('system', 'maintenance_reason', ''); if ($errors) { - Config::set('system', 'dbupdate', DB_UPDATE_FAILED); + Config::set('system', 'dbupdate', self::UPDATE_FAILED); } else { - Config::set('system', 'dbupdate', DB_UPDATE_SUCCESSFUL); + Config::set('system', 'dbupdate', self::UPDATE_SUCCESSFUL); } } diff --git a/update.php b/update.php index 6a0ed1af20..439dd04bd5 100644 --- a/update.php +++ b/update.php @@ -4,6 +4,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Core\Update; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -65,7 +66,7 @@ function update_1179() { // Update the central item storage with uid=0 Worker::add(PRIORITY_LOW, "threadupdate"); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1181() { @@ -73,7 +74,7 @@ function update_1181() { // Fill the new fields in the term table. Worker::add(PRIORITY_LOW, "TagUpdate"); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1189() { @@ -84,7 +85,7 @@ function update_1189() { Config::delete('system','directory_submit_url'); } - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1191() { @@ -144,7 +145,7 @@ function update_1191() { Config::set('system', 'maintenance', 0); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1203() { @@ -165,19 +166,19 @@ function update_1244() { // Logged in users are forcibly logged out DBA::delete('session', ['1 = 1']); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1245() { $rino = Config::get('system', 'rino_encrypt'); if (!$rino) { - return UPDATE_SUCCESS; + return Update::SUCCESS; } Config::set('system', 'rino_encrypt', 1); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1247() { @@ -226,13 +227,13 @@ function update_1260() { SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0"); Config::set('system', 'maintenance', 0); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1261() { // This fixes the results of an issue in the develop branch of 2018-05. DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1278() { @@ -244,7 +245,7 @@ function update_1278() { Config::set('system', 'maintenance', 0); - return UPDATE_SUCCESS; + return Update::SUCCESS; } function update_1288() {