X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FCore%2FUpdate.php;h=115abbab152fc1f96bddf8cc0c166cbac819067f;hb=b06fc578804fdc0073631e7c97eccd25543e769e;hp=252ea8ef31d5f190c534ed53cbffeec0fc075842;hpb=d577ab98eb0f28f9f807795f54c87d80ef9c0dc2;p=friendica.git diff --git a/src/Core/Update.php b/src/Core/Update.php index 252ea8ef31..115abbab15 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -14,10 +14,16 @@ class Update /** * @brief Function to check if the Database structure needs an update. * + * @param string $basePath The base path of this application * @param boolean $via_worker boolean Is the check run via the worker? + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function check($via_worker) + public static function check($basePath, $via_worker) { + if (!DBA::connected()) { + return; + } + $build = Config::get('system', 'build'); if (empty($build)) { @@ -31,9 +37,13 @@ class Update } 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) { - self::run(); + if ($via_worker) { + // Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself. + // This is a fallback, since normally the database update will be performed by a worker job. + // This worker job doesn't work for changes to the "workerqueue" table itself. + self::run($basePath); + } else { + Worker::add(PRIORITY_CRITICAL, 'DBUpdate'); } } } @@ -41,18 +51,21 @@ class Update /** * Automatic database updates * - * @param bool $force Force the Update-Check even if the lock is set - * @param bool $verbose Run the Update-Check verbose - * @param bool $sendMail Sends a Mail to the administrator in case of success/failure + * @param string $basePath The base path of this application + * @param bool $force Force the Update-Check even if the database version doesn't match + * @param bool $override Overrides any running/stuck updates + * @param bool $verbose Run the Update-Check verbose + * @param bool $sendMail Sends a Mail to the administrator in case of success/failure * * @return string Empty string if the update is successful, error messages otherwise + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function run($force = false, $verbose = false, $sendMail = true) + public static function run($basePath, $force = false, $override = false, $verbose = false, $sendMail = true) { // In force mode, we release the dbupdate lock first // Necessary in case of an stuck update - if ($force) { - Lock::release('dbupdate'); + if ($override) { + Lock::release('dbupdate', true); } $build = Config::get('system', 'build'); @@ -62,12 +75,12 @@ class Update Config::set('system', 'build', $build); } - if ($build != DB_UPDATE_VERSION) { + if ($build != DB_UPDATE_VERSION || $force) { require_once 'update.php'; $stored = intval($build); $current = intval(DB_UPDATE_VERSION); - if ($stored < $current) { + if ($stored < $current || $force) { Config::load('database'); Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - starting', Logger::DEBUG); @@ -85,8 +98,8 @@ class Update } // update the structure in one call - $retval = DBStructure::update($verbose, true); - if ($retval) { + $retval = DBStructure::update($basePath, $verbose, true); + if (!empty($retval)) { if ($sendMail) { self::updateFailed( DB_UPDATE_VERSION, @@ -126,10 +139,11 @@ class Update /** * Executes a specific update function * - * @param int $x the DB version number of the 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 + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function runUpdateFunction($x, $prefix) { @@ -189,13 +203,13 @@ class Update /** * 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 + * @param int $update_id number of failed update + * @param string $error_message error message + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ 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]); + $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['email' => explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))]); // No valid result? if (!DBA::isResult($adminlist)) { @@ -236,8 +250,7 @@ class Update 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]); + $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['email' => explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))]); if (DBA::isResult($adminlist)) { // every admin could had different language