Merge pull request #6744 from nupplaphil/task/namespace_to_class
authorMichael Vogel <icarus@dabo.de>
Sun, 24 Feb 2019 13:27:48 +0000 (14:27 +0100)
committerGitHub <noreply@github.com>
Sun, 24 Feb 2019 13:27:48 +0000 (14:27 +0100)
Replace string namespace with *::class

src/Core/Console/DatabaseStructure.php
src/Core/Console/PostUpdate.php
src/Core/Lock.php
src/Core/Lock/CacheLockDriver.php
src/Core/Lock/DatabaseLockDriver.php
src/Core/Lock/ILockDriver.php
src/Core/Lock/SemaphoreLockDriver.php
src/Core/Update.php

index 1ec108d..dededa9 100644 (file)
@@ -31,9 +31,10 @@ Commands
        toinnodb Convert all tables from MyISAM to InnoDB
 
 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)
+    -h|--help|-?       Show help information
+    -v                 Show more debug information.
+    -f|--force         Force the update command (Even if the database structure matches)
+    -o|--override      Override running or stalling updates
 HELP;
                return $help;
        }
@@ -68,8 +69,9 @@ HELP;
                                $output = DBStructure::update($a->getBasePath(), true, false);
                                break;
                        case "update":
-                               $force = $this->getOption(['f', 'force'], false);
-                               $output = Update::run($a->getBasePath(), $force, true, false);
+                               $force    = $this->getOption(['f', 'force'], false);
+                               $override = $this->getOption(['o', 'override'], false);
+                               $output = Update::run($a->getBasePath(), $force, $override,true, false);
                                break;
                        case "dumpsql":
                                ob_start();
@@ -89,5 +91,4 @@ HELP;
 
                return 0;
        }
-
 }
index 103d0fe..a903cd7 100644 (file)
@@ -56,7 +56,7 @@ HELP;
                }
 
                echo L10n::t('Check for pending update actions.') . "\n";
-               Update::run($a->getBasePath(), true, true, false);
+               Update::run($a->getBasePath(), true, false, true, false);
                echo L10n::t('Done.') . "\n";
 
                echo L10n::t('Execute pending post updates.') . "\n";
index e8c8a70..8bc2c24 100644 (file)
@@ -122,12 +122,13 @@ class Lock
        /**
         * @brief Releases a lock if it was set by us
         *
-        * @param string $key Name of the lock
+        * @param string $key      Name of the lock
+        * @param bool   $override Overrides the lock to get releases
         * @return void
         */
-       public static function release($key)
+       public static function release($key, $override = false)
        {
-               self::getDriver()->releaseLock($key);
+               self::getDriver()->releaseLock($key, $override);
        }
 
        /**
index 18d441f..c1cd8ff 100644 (file)
@@ -61,11 +61,15 @@ class CacheLockDriver extends AbstractLockDriver
        /**
         * (@inheritdoc)
         */
-       public function releaseLock($key)
+       public function releaseLock($key, $override = false)
        {
                $cachekey = self::getLockKey($key);
 
-               $this->cache->compareDelete($cachekey, getmypid());
+               if ($override) {
+                       $this->cache->delete($cachekey);
+               } else {
+                       $this->cache->compareDelete($cachekey, getmypid());
+               }
                $this->markRelease($key);
        }
 
index 6f18fb5..a137ef1 100644 (file)
@@ -68,9 +68,15 @@ class DatabaseLockDriver extends AbstractLockDriver
        /**
         * (@inheritdoc)
         */
-       public function releaseLock($key)
+       public function releaseLock($key, $override = false)
        {
-               DBA::delete('locks', ['name' => $key, 'pid' => $this->pid]);
+               if ($override) {
+                       $where = ['name' => $key];
+               } else {
+                       $where = ['name' => $key, 'pid' => $this->pid];
+               }
+
+               DBA::delete('locks', $where);
 
                $this->markRelease($key);
 
index a255f68..7cbaa4f 100644 (file)
@@ -33,11 +33,12 @@ interface ILockDriver
        /**
         * Releases a lock if it was set by us
         *
-        * @param string $key The Name of the lock
+        * @param string $key      The Name of the lock
+        * @param bool   $override Overrides the lock to get released
         *
         * @return void
         */
-       public function releaseLock($key);
+       public function releaseLock($key, $override = false);
 
        /**
         * Releases all lock that were set by us
index cf1ce5a..781e110 100644 (file)
@@ -50,7 +50,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
        /**
         * (@inheritdoc)
         */
-       public function releaseLock($key)
+       public function releaseLock($key, $override = false)
        {
                if (empty(self::$semaphore[$key])) {
                        return false;
index ed6c058..0a0f365 100644 (file)
@@ -37,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) {
+                       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');
                        }
                }
        }
@@ -48,19 +52,20 @@ class Update
         * Automatic database updates
         *
         * @param string $basePath The base path of this application
-        * @param bool $force      Force the Update-Check even if the lock is set
+        * @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($basePath, $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');
@@ -70,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);
@@ -126,8 +131,6 @@ class Update
                                        Lock::release('dbupdate');
                                }
                        }
-               } elseif ($force) {
-                       DBStructure::update($basePath, $verbose, true);
                }
 
                return '';