]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Update.php
Merge pull request #8055 from nupplaphil/task/remove_get_server
[friendica.git] / src / Core / Update.php
index bb2513d38858741ac6de779edca7058c5d19746a..0ead704c101671faa77b9c17fd95122e0df88d2e 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Core;
 
+use Friendica\App;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Util\Strings;
@@ -14,16 +15,23 @@ 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?
+        * @param string   $basePath   The base path of this application
+        * @param boolean  $via_worker Is the check run via the worker?
+        * @param App\Mode $mode       The current app mode
+        *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function check($basePath, $via_worker)
+       public static function check($basePath, $via_worker, App\Mode $mode)
        {
                if (!DBA::connected()) {
                        return;
                }
 
+               // Don't check the status if the last update was failed
+               if (Config::get('system', 'update', Update::SUCCESS, true) == Update::FAILED) {
+                       return;
+               }
+
                $build = Config::get('system', 'build');
 
                if (empty($build)) {
@@ -101,7 +109,9 @@ class Update
                                        for ($x = $stored + 1; $x <= $current; $x++) {
                                                $r = self::runUpdateFunction($x, 'pre_update');
                                                if (!$r) {
-                                                       break;
+                                                       Config::set('system', 'update', Update::FAILED);
+                                                       Lock::release('dbupdate');
+                                                       return $r;
                                                }
                                        }
 
@@ -115,6 +125,7 @@ class Update
                                                        );
                                                }
                                                Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
+                                               Config::set('system', 'update', Update::FAILED);
                                                Lock::release('dbupdate');
                                                return $retval;
                                        } else {
@@ -127,7 +138,9 @@ class Update
                                        for ($x = $stored + 1; $x <= $current; $x++) {
                                                $r = self::runUpdateFunction($x, 'update');
                                                if (!$r) {
-                                                       break;
+                                                       Config::set('system', 'update', Update::FAILED);
+                                                       Lock::release('dbupdate');
+                                                       return $r;
                                                }
                                        }
 
@@ -136,6 +149,7 @@ class Update
                                                self::updateSuccessfull($stored, $current);
                                        }
 
+                                       Config::set('system', 'update', Update::SUCCESS);
                                        Lock::release('dbupdate');
                                }
                        }
@@ -238,25 +252,25 @@ class Update
                        $sent[] = $admin['email'];
 
                        $lang = (($admin['language'])?$admin['language']:'en');
-                       L10n::pushLang($lang);
+                       $l10n = L10n::withLang($lang);
 
-                       $preamble = Strings::deindent(L10n::t("
+                       $preamble = Strings::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);
+                       $body = $l10n->t("The error message is\n[pre]%s[/pre]", $error_message);
 
                        notification([
                                        'uid'      => $admin['uid'],
                                        'type'     => SYSTEM_EMAIL,
                                        'to_email' => $admin['email'],
+                                       'subject'  => $l10n->t('[Friendica Notify] Database update'),
                                        'preamble' => $preamble,
                                        'body'     => $body,
                                        'language' => $lang]
                        );
-                       L10n::popLang();
                }
 
                //try the logger
@@ -280,9 +294,9 @@ class Update
                                $sent[] = $admin['email'];
 
                                $lang = (($admin['language']) ? $admin['language'] : 'en');
-                               L10n::pushLang($lang);
+                               $l10n = L10n::withLang($lang);
 
-                               $preamble = Strings::deindent(L10n::t("
+                               $preamble = Strings::deindent($l10n->t("
                                        The friendica database was successfully updated from %s to %s.",
                                        $from_build, $to_build));
 
@@ -290,11 +304,11 @@ class Update
                                                'uid' => $admin['uid'],
                                                'type' => SYSTEM_EMAIL,
                                                'to_email' => $admin['email'],
+                                               'subject'  => l10n::t('[Friendica Notify] Database update'),
                                                'preamble' => $preamble,
                                                'body' => $preamble,
                                                'language' => $lang]
                                );
-                               L10n::popLang();
                        }
                }