diff --git a/bin/worker.php b/bin/worker.php
index d5cd1f6b4..9ae2f68b3 100755
--- a/bin/worker.php
+++ b/bin/worker.php
@@ -7,6 +7,7 @@
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\Worker;
+use Friendica\Core\Update;
// Get options
$shortopts = 'sn';
@@ -30,7 +31,7 @@ require_once "boot.php";
$a = new App(dirname(__DIR__));
// Check the database structure and possibly fixes it
-check_db(true);
+Update::check(true);
// Quit when in maintenance
if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
diff --git a/boot.php b/boot.php
index 3efd065f3..a94b38038 100644
--- a/boot.php
+++ b/boot.php
@@ -28,9 +28,9 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\System;
+use Friendica\Core\Update;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
-use Friendica\Database\DBStructure;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Util\DateTimeFormat;
@@ -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
*
@@ -432,143 +413,6 @@ function defaults() {
return $return;
}
-/**
- * @brief Function to check if request was an AJAX (xmlhttprequest) request.
- *
- * @param boolean $via_worker boolean Is the check run via the worker?
- */
-function check_db($via_worker)
-{
- $build = Config::get('system', 'build');
-
- if (empty($build)) {
- Config::set('system', 'build', DB_UPDATE_VERSION - 1);
- $build = DB_UPDATE_VERSION - 1;
- }
-
- // We don't support upgrading from very old versions anymore
- if ($build < NEW_UPDATE_ROUTINE_VERSION) {
- die('You try to update from a version prior to database version 1170. The direct upgrade path is not supported. Please update to version 3.5.4 before updating to this version.');
- }
-
- if ($build < DB_UPDATE_VERSION) {
- // When we cannot execute the database update via the worker, we will do it directly
- if (!Worker::add(PRIORITY_CRITICAL, 'DBUpdate') && $via_worker) {
- update_db();
- }
- }
-}
-
-/**
- * @brief Automatic database updates
- * @param object $a App
- */
-function update_db()
-{
- $build = Config::get('system', 'build');
-
- if (empty($build) || ($build > DB_UPDATE_VERSION)) {
- $build = DB_UPDATE_VERSION - 1;
- Config::set('system', 'build', $build);
- }
-
- if ($build != DB_UPDATE_VERSION) {
- require_once 'update.php';
-
- $stored = intval($build);
- $current = intval(DB_UPDATE_VERSION);
- if ($stored < $current) {
- Config::load('database');
-
- // Compare the current structure with the defined structure
- $t = Config::get('database', 'dbupdate_' . DB_UPDATE_VERSION);
- if (!is_null($t)) {
- return;
- }
-
- // run the pre_update_nnnn functions in update.php
- for ($x = $stored + 1; $x <= $current; $x++) {
- $r = run_update_function($x, 'pre_update');
- if (!$r) {
- break;
- }
- }
-
- Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time());
-
- // update the structure in one call
- $retval = DBStructure::update(false, true);
- if ($retval) {
- DBStructure::updateFail(
- DB_UPDATE_VERSION,
- $retval
- );
- return;
- } else {
- Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
- }
-
- // run the update_nnnn functions in update.php
- for ($x = $stored + 1; $x <= $current; $x++) {
- $r = run_update_function($x, 'update');
- if (!$r) {
- break;
- }
- }
- }
- }
-
- return;
-}
-
-function run_update_function($x, $prefix)
-{
- $funcname = $prefix . '_' . $x;
-
- if (function_exists($funcname)) {
- // There could be a lot of processes running or about to run.
- // We want exactly one process to run the update command.
- // So store the fact that we're taking responsibility
- // after first checking to see if somebody else already has.
- // If the update fails or times-out completely you may need to
- // delete the config entry to try again.
-
- $t = Config::get('database', $funcname);
- if (!is_null($t)) {
- return false;
- }
- Config::set('database', $funcname, time());
-
- // call the specific update
- $retval = $funcname();
-
- if ($retval) {
- //send the administrator an e-mail
- DBStructure::updateFail(
- $x,
- L10n::t('Update %s failed. See error logs.', $x)
- );
- return false;
- } else {
- Config::set('database', $funcname, 'success');
-
- if ($prefix == 'update') {
- Config::set('system', 'build', $x);
- }
-
- return true;
- }
- } else {
- Config::set('database', $funcname, 'success');
-
- if ($prefix == 'update') {
- Config::set('system', 'build', $x);
- }
-
- return true;
- }
-}
-
/**
* @brief Used to end the current process, after saving session state.
* @deprecated
diff --git a/mod/admin.php b/mod/admin.php
index d4cbafe54..d97bac194 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.');
}
@@ -1595,7 +1596,8 @@ function admin_page_dbsync(App $a)
$retval = DBStructure::update(false, true);
if ($retval === '') {
$o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "
";
- Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
+ Config::set('database', 'last_successful_update', DB_UPDATE_VERSION);
+ Config::set('database', 'last_successful_update_time', time());
} else {
$o .= L10n::t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "
";
}
@@ -1612,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/App.php b/src/App.php
index 781faf1a5..598c0e66f 100644
--- a/src/App.php
+++ b/src/App.php
@@ -1682,7 +1682,7 @@ class App
$this->module = 'maintenance';
} else {
$this->checkURL();
- check_db(false);
+ Core\Update::check(false);
Core\Addon::loadAddons();
Core\Hook::loadHooks();
}
diff --git a/src/Core/Cache.php b/src/Core/Cache.php
index 0fb328aae..e7277fd70 100644
--- a/src/Core/Cache.php
+++ b/src/Core/Cache.php
@@ -19,6 +19,7 @@ class Cache extends \Friendica\BaseObject
const QUARTER_HOUR = 900;
const FIVE_MINUTES = 300;
const MINUTE = 60;
+ const INFINITE = 0;
/**
* @var Cache\ICacheDriver
diff --git a/src/Core/Cache/DatabaseCacheDriver.php b/src/Core/Cache/DatabaseCacheDriver.php
index d90c6e4f1..f6f5b6486 100644
--- a/src/Core/Cache/DatabaseCacheDriver.php
+++ b/src/Core/Cache/DatabaseCacheDriver.php
@@ -40,7 +40,7 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
*/
public function get($key)
{
- $cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
+ $cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, DateTimeFormat::utcNow()]);
if (DBA::isResult($cache)) {
$cached = $cache['v'];
@@ -62,11 +62,19 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
*/
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
{
- $fields = [
- 'v' => serialize($value),
- 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
- 'updated' => DateTimeFormat::utcNow()
- ];
+ if ($ttl > 0) {
+ $fields = [
+ 'v' => serialize($value),
+ 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
+ 'updated' => DateTimeFormat::utcNow()
+ ];
+ } else {
+ $fields = [
+ 'v' => serialize($value),
+ 'expires' => -1,
+ 'updated' => DateTimeFormat::utcNow()
+ ];
+ }
return DBA::update('cache', $fields, ['k' => $key], true);
}
diff --git a/src/Core/Cache/ICacheDriver.php b/src/Core/Cache/ICacheDriver.php
index 2c04c5992..1188e5187 100644
--- a/src/Core/Cache/ICacheDriver.php
+++ b/src/Core/Cache/ICacheDriver.php
@@ -34,7 +34,7 @@ interface ICacheDriver
*
* @param string $key The cache key
* @param mixed $value The value to store
- * @param integer $ttl The cache lifespan, must be one of the Cache constants
+ * @param integer $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*/
diff --git a/src/Core/Cache/IMemoryCacheDriver.php b/src/Core/Cache/IMemoryCacheDriver.php
index a50e2d1d4..0c5146f43 100644
--- a/src/Core/Cache/IMemoryCacheDriver.php
+++ b/src/Core/Cache/IMemoryCacheDriver.php
@@ -28,7 +28,7 @@ interface IMemoryCacheDriver extends ICacheDriver
* @param string $key The cache key
* @param mixed $oldValue The old value we know from the cache
* @param mixed $newValue The new value we want to set
- * @param int $ttl The cache lifespan, must be one of the Cache constants
+ * @param int $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*/
diff --git a/src/Core/Console/DatabaseStructure.php b/src/Core/Console/DatabaseStructure.php
index 4b607c1e6..f3badc196 100644
--- a/src/Core/Console/DatabaseStructure.php
+++ b/src/Core/Console/DatabaseStructure.php
@@ -3,6 +3,7 @@
namespace Friendica\Core\Console;
use Friendica\Core;
+use Friendica\Core\Update;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use RuntimeException;
@@ -24,7 +25,7 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
$help = << [-h|--help|-?] [-v]
+ bin/console dbstructure [-h|--help|-?] |-f|--force] [-v]
Commands
dryrun Show database update schema queries without running them
@@ -35,14 +36,13 @@ Commands
Options
-h|--help|-? Show help information
-v Show more debug information.
+ -f|--force Force the command in case of "update" (Ignore failed updates/running updates)
HELP;
return $help;
}
protected function doExecute()
{
- $a = get_app();
-
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
@@ -69,34 +69,8 @@ HELP;
$output = DBStructure::update(true, false);
break;
case "update":
- $build = Core\Config::get('system', 'build');
- if (empty($build)) {
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);
- $build = DB_UPDATE_VERSION;
- }
-
- $stored = intval($build);
- $current = intval(DB_UPDATE_VERSION);
-
- // run the pre_update_nnnn functions in update.php
- for ($x = $stored; $x < $current; $x ++) {
- $r = run_update_function($x, 'pre_update');
- if (!$r) {
- break;
- }
- }
-
- $output = DBStructure::update(true, true);
-
- // run the update_nnnn functions in update.php
- for ($x = $stored; $x < $current; $x ++) {
- $r = run_update_function($x, 'update');
- if (!$r) {
- break;
- }
- }
-
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);
+ $force = $this->getOption(['f', 'force'], false);
+ $output = Update::run($force, true, false);
break;
case "dumpsql":
ob_start();
diff --git a/src/Core/Lock.php b/src/Core/Lock.php
index 4a737e381..a5467c644 100644
--- a/src/Core/Lock.php
+++ b/src/Core/Lock.php
@@ -111,12 +111,13 @@ class Lock
*
* @param string $key Name of the lock
* @param integer $timeout Seconds until we give up
+ * @param integer $ttl The Lock lifespan, must be one of the Cache constants
*
* @return boolean Was the lock successful?
*/
- public static function acquire($key, $timeout = 120)
+ public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
{
- return self::getDriver()->acquireLock($key, $timeout);
+ return self::getDriver()->acquireLock($key, $timeout, $ttl);
}
/**
diff --git a/src/Core/Update.php b/src/Core/Update.php
new file mode 100644
index 000000000..139688335
--- /dev/null
+++ b/src/Core/Update.php
@@ -0,0 +1,266 @@
+ DB_UPDATE_VERSION)) {
+ $build = DB_UPDATE_VERSION - 1;
+ Config::set('system', 'build', $build);
+ }
+
+ if ($build != DB_UPDATE_VERSION) {
+ require_once 'update.php';
+
+ $stored = intval($build);
+ $current = intval(DB_UPDATE_VERSION);
+ if ($stored < $current) {
+ Config::load('database');
+
+ Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - starting', Logger::DEBUG);
+
+ // Compare the current structure with the defined structure
+ // If the Lock is acquired, never release it automatically to avoid double updates
+ if (Lock::acquire('dbupdate', 120, Cache::INFINITE)) {
+
+ // run the pre_update_nnnn functions in update.php
+ for ($x = $stored + 1; $x <= $current; $x++) {
+ $r = self::runUpdateFunction($x, 'pre_update');
+ if (!$r) {
+ break;
+ }
+ }
+
+ // update the structure in one call
+ $retval = DBStructure::update($verbose, true);
+ if ($retval) {
+ if ($sendMail) {
+ self::updateFailed(
+ DB_UPDATE_VERSION,
+ $retval
+ );
+ }
+ Logger::log('ERROR: Update from \'' . $stored . '\' to \'' . $current . '\' - failed: ' - $retval, Logger::ALL);
+ Lock::release('dbupdate');
+ return $retval;
+ } else {
+ Config::set('database', 'last_successful_update', $current);
+ Config::set('database', 'last_successful_update_time', time());
+ Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - finished', Logger::DEBUG);
+ }
+
+ // run the update_nnnn functions in update.php
+ for ($x = $stored + 1; $x <= $current; $x++) {
+ $r = self::runUpdateFunction($x, 'update');
+ if (!$r) {
+ break;
+ }
+ }
+
+ Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - successful', Logger::DEBUG);
+ if ($sendMail) {
+ self::updateSuccessfull($stored, $current);
+ }
+
+ Lock::release('dbupdate');
+ }
+ }
+ }
+
+ return '';
+ }
+
+ /**
+ * Executes a specific update function
+ *
+ * @param int $x the DB version number of the function
+ * @param string $prefix the prefix of the function (update, pre_update)
+ *
+ * @return bool true, if the update function worked
+ */
+ public static function runUpdateFunction($x, $prefix)
+ {
+ $funcname = $prefix . '_' . $x;
+
+ Logger::log('Update function \'' . $funcname . '\' - start', Logger::DEBUG);
+
+ if (function_exists($funcname)) {
+ // There could be a lot of processes running or about to run.
+ // We want exactly one process to run the update command.
+ // So store the fact that we're taking responsibility
+ // after first checking to see if somebody else already has.
+ // If the update fails or times-out completely you may need to
+ // delete the config entry to try again.
+
+ if (Lock::acquire('dbupdate_function', 120,Cache::INFINITE)) {
+
+ // call the specific update
+ $retval = $funcname();
+
+ if ($retval) {
+ //send the administrator an e-mail
+ self::updateFailed(
+ $x,
+ L10n::t('Update %s failed. See error logs.', $x)
+ );
+ Logger::log('ERROR: Update function \'' . $funcname . '\' - failed: ' . $retval, Logger::ALL);
+ Lock::release('dbupdate_function');
+ return false;
+ } else {
+ Config::set('database', 'last_successful_update_function', $funcname);
+ Config::set('database', 'last_successful_update_function_time', time());
+
+ if ($prefix == 'update') {
+ Config::set('system', 'build', $x);
+ }
+
+ Lock::release('dbupdate_function');
+ Logger::log('Update function \'' . $funcname . '\' - finished', Logger::DEBUG);
+ return true;
+ }
+ }
+ } else {
+ Logger::log('Skipping \'' . $funcname . '\' without executing', Logger::DEBUG);
+
+ Config::set('database', 'last_successful_update_function', $funcname);
+ Config::set('database', 'last_successful_update_function_time', time());
+
+ if ($prefix == 'update') {
+ Config::set('system', 'build', $x);
+ }
+
+ return true;
+ }
+ }
+
+ /**
+ * send the email and do what is needed to do on update fails
+ *
+ * @param int $update_id number of failed update
+ * @param string $error_message error message
+ */
+ private static function updateFailed($update_id, $error_message) {
+ //send the administrators an e-mail
+ $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
+ $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['`email` IN (%s)', $admin_mail_list]);
+
+ // No valid result?
+ if (!DBA::isResult($adminlist)) {
+ Logger::log(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), Logger::INFO);
+
+ // Don't continue
+ return;
+ }
+
+ // every admin could had different language
+ foreach ($adminlist as $admin) {
+ $lang = (($admin['language'])?$admin['language']:'en');
+ L10n::pushLang($lang);
+
+ $preamble = deindent(L10n::t("
+ The friendica developers released update %s recently,
+ but when I tried to install it, something went terribly wrong.
+ This needs to be fixed soon and I can't do it alone. Please contact a
+ friendica developer if you can not help me on your own. My database might be invalid.",
+ $update_id));
+ $body = L10n::t("The error message is\n[pre]%s[/pre]", $error_message);
+
+ notification([
+ 'uid' => $admin['uid'],
+ 'type' => SYSTEM_EMAIL,
+ 'to_email' => $admin['email'],
+ 'preamble' => $preamble,
+ 'body' => $body,
+ 'language' => $lang]
+ );
+ L10n::popLang();
+ }
+
+ //try the logger
+ Logger::log("CRITICAL: Database structure update failed: " . $error_message);
+ }
+
+ private static function updateSuccessfull($from_build, $to_build)
+ {
+ //send the administrators an e-mail
+ $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
+ $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['`email` IN (%s)', $admin_mail_list]);
+
+ if (DBA::isResult($adminlist)) {
+ // every admin could had different language
+ foreach ($adminlist as $admin) {
+ $lang = (($admin['language']) ? $admin['language'] : 'en');
+ L10n::pushLang($lang);
+
+ $preamble = deindent(L10n::t("
+ The friendica database was successfully updated from %s to %s.",
+ $from_build, $to_build));
+
+ notification([
+ 'uid' => $admin['uid'],
+ 'type' => SYSTEM_EMAIL,
+ 'to_email' => $admin['email'],
+ 'preamble' => $preamble,
+ 'body' => $preamble,
+ 'language' => $lang]
+ );
+ L10n::popLang();
+ }
+ }
+
+ //try the logger
+ Logger::log("Database structure update successful.", Logger::TRACE);
+ }
+}
diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php
index 9a14114de..4a9bc69f6 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
*
@@ -53,58 +57,6 @@ class DBStructure
}
}
- /*
- * send the email and do what is needed to do on update fails
- *
- * @param update_id (int) number of failed update
- * @param error_message (str) error message
- */
- public static function updateFail($update_id, $error_message) {
- $a = get_app();
-
- //send the administrators an e-mail
- $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
- $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
- $admin_mail_list
- );
-
- // No valid result?
- if (!DBA::isResult($adminlist)) {
- Logger::log(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), Logger::INFO);
-
- // Don't continue
- return;
- }
-
- // every admin could had different language
- foreach ($adminlist as $admin) {
- $lang = (($admin['language'])?$admin['language']:'en');
- L10n::pushLang($lang);
-
- $preamble = deindent(L10n::t("
- The friendica developers released update %s recently,
- but when I tried to install it, something went terribly wrong.
- This needs to be fixed soon and I can't do it alone. Please contact a
- friendica developer if you can not help me on your own. My database might be invalid.",
- $update_id));
- $body = L10n::t("The error message is\n[pre]%s[/pre]", $error_message);
-
- notification([
- 'uid' => $admin['uid'],
- 'type' => SYSTEM_EMAIL,
- 'to_email' => $admin['email'],
- 'preamble' => $preamble,
- 'body' => $body,
- 'language' => $lang]
- );
- L10n::popLang();
- }
-
- //try the logger
- Logger::log("CRITICAL: Database structure update failed: ".$error_message);
- }
-
-
private static function tableStructure($table) {
$structures = q("DESCRIBE `%s`", $table);
@@ -535,9 +487,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/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php
index ed8e409e9..ae25760c8 100644
--- a/src/Worker/DBUpdate.php
+++ b/src/Worker/DBUpdate.php
@@ -6,17 +6,12 @@
namespace Friendica\Worker;
use Friendica\Core\Config;
+use Friendica\Core\Update;
class DBUpdate
{
public static function execute()
{
- $a = \Friendica\BaseObject::getApp();
-
- // We are deleting the latest dbupdate entry.
- // This is done to avoid endless loops because the update was interupted.
- Config::delete('database', 'dbupdate_'.DB_UPDATE_VERSION);
-
- update_db($a);
+ Update::run();
}
}
diff --git a/update.php b/update.php
index 6a0ed1af2..115f817d7 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() {
@@ -253,5 +254,5 @@ function update_1288() {
DBA::e("UPDATE `item-activity` INNER JOIN `item` ON `item`.`iaid` = `item-activity`.`id` SET `item-activity`.`uri-id` = `item`.`uri-id` WHERE `item-activity`.`uri-id` IS NULL OR `item-activity`.`uri-id` = 0");
DBA::e("UPDATE `item-content` INNER JOIN `item` ON `item`.`icid` = `item-content`.`id` SET `item-content`.`uri-id` = `item`.`uri-id` WHERE `item-content`.`uri-id` IS NULL OR `item-content`.`uri-id` = 0");
- return UPDATE_SUCCESS;
+ return Update::SUCCESS;
}