Moving UPDATE defines/constants out of boot

This commit is contained in:
Philipp Holzer 2018-10-14 13:19:37 +02:00
parent 4ae985e5ed
commit 87f3fe24f7
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
5 changed files with 25 additions and 35 deletions

View File

@ -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
*

View File

@ -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 {

View File

@ -6,6 +6,9 @@ use Friendica\Database\DBStructure;
class Update
{
const SUCCESS = 0;
const FAILED = 1;
/**
* Automatic database updates
*/

View File

@ -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);
}
}

View File

@ -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() {