]> git.mxchange.org Git - friendica.git/commitdiff
Replace Lock::release() with DI::lock()->release() and remove Core\Lock
authornupplaPhil <admin@philipp.info>
Mon, 6 Jan 2020 23:24:10 +0000 (00:24 +0100)
committernupplaPhil <admin@philipp.info>
Mon, 6 Jan 2020 23:24:10 +0000 (00:24 +0100)
14 files changed:
src/Console/Lock.php
src/Core/Lock.php [deleted file]
src/Core/Lock/CacheLock.php
src/Core/Lock/DatabaseLock.php
src/Core/Lock/ILock.php
src/Core/Lock/Lock.php
src/Core/Lock/SemaphoreLock.php
src/Core/Update.php
src/Core/Worker.php
src/Model/Item.php
src/Protocol/OStatus.php
tests/Util/DbaLockMockTrait.php
tests/src/Core/Lock/LockTest.php
tests/src/Core/Lock/SemaphoreLockTest.php

index 71de727028f87a1e72248f58eae71b8affdeb26b..da1f408d0d1ab3b74f0a346d2669cdd1a9b7cebf 100644 (file)
@@ -133,7 +133,7 @@ HELP;
                if (count($this->args) >= 2) {
                        $lock = $this->getArgument(1);
 
-                       if ($this->lock->releaseLock($lock, true)) {
+                       if ($this->lock->release($lock, true)) {
                                $this->out(sprintf('Lock \'%s\' released.', $lock));
                        } else {
                                $this->out(sprintf('Couldn\'t release Lock \'%s\'', $lock));
diff --git a/src/Core/Lock.php b/src/Core/Lock.php
deleted file mode 100644 (file)
index a01ad88..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * @file src/Core/Lock.php
- * @brief Functions for preventing parallel execution of functions
- */
-
-namespace Friendica\Core;
-
-use Friendica\Core\Cache\Cache;
-use Friendica\DI;
-
-/**
- * This class contain Functions for preventing parallel execution of functions
- */
-class Lock
-{
-       /**
-        * @brief Releases a lock if it was set by us
-        *
-        * @param string $key      Name of the lock
-        * @param bool   $override Overrides the lock to get releases
-        *
-        * @return bool
-        * @throws \Exception
-        */
-       public static function release($key, $override = false)
-       {
-               return DI::lock()->releaseLock($key, $override);
-       }
-
-       /**
-        * @brief Releases all lock that were set by us
-        * @return void
-        * @throws \Exception
-        */
-       public static function releaseAll()
-       {
-               DI::lock()->releaseAll();
-       }
-}
index a4355cd085790d3ec27dbcd94cb3c123a507e2ba..3eb0af765c6053490afc61b89c014a76ff9f75bc 100644 (file)
@@ -66,7 +66,7 @@ class CacheLock extends Lock
        /**
         * (@inheritdoc)
         */
-       public function releaseLock($key, $override = false)
+       public function release($key, $override = false)
        {
                $cachekey = self::getLockKey($key);
 
@@ -122,7 +122,7 @@ class CacheLock extends Lock
                $locks = $this->getLocks();
 
                foreach ($locks as $lock) {
-                       if (!$this->releaseLock($lock, $override)) {
+                       if (!$this->release($lock, $override)) {
                                $success = false;
                        }
                }
index 4d1b3080bcd0f6ddce8ff73623f4618657d26de3..0788f04b284846eebfd9bf1452b8569ac7f9752e 100644 (file)
@@ -74,7 +74,7 @@ class DatabaseLock extends Lock
        /**
         * (@inheritdoc)
         */
-       public function releaseLock($key, $override = false)
+       public function release($key, $override = false)
        {
                if ($override) {
                        $where = ['name' => $key];
index 082abbd70db3002e1e492ddf5b037ebad18e4824..121f29a4367e7472e8d102b79aa8c8ad6d0a91a4 100644 (file)
@@ -40,7 +40,7 @@ interface ILock
         *
         * @return boolean Was the unlock successful?
         */
-       public function releaseLock($key, $override = false);
+       public function release($key, $override = false);
 
        /**
         * Releases all lock that were set by us
index f03ffe03d144e565f7f99f581b6685f46650edb2..694384b72f975880d9c2f2f8dfea5f137876d57c 100644 (file)
@@ -61,7 +61,7 @@ abstract class Lock implements ILock
                $return = true;
 
                foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
-                       if (!$this->releaseLock($acquiredLock, $override)) {
+                       if (!$this->release($acquiredLock, $override)) {
                                $return = false;
                        }
                }
index 64a105ec03fa0d5efcbfed4c547da85c44e1fafc..1a28eb357cb1f78d3c3ab48f7948c2de385a4f0c 100644 (file)
@@ -55,7 +55,7 @@ class SemaphoreLock extends Lock
         * @param bool $override not necessary parameter for semaphore locks since the lock lives as long as the execution
         *                       of the using function
         */
-       public function releaseLock($key, $override = false)
+       public function release($key, $override = false)
        {
                $success = false;
 
index 5873f798e44f73c7172d1447db649445ca554ec6..badbdc7851d380092b3965e1e0bbd3ccc794e9e0 100644 (file)
@@ -74,7 +74,7 @@ class Update
                // In force mode, we release the dbupdate lock first
                // Necessary in case of an stuck update
                if ($override) {
-                       Lock::release('dbupdate', true);
+                       DI::lock()->release('dbupdate', true);
                }
 
                $build = Config::get('system', 'build', null, true);
@@ -102,7 +102,7 @@ class Update
                                        $retryBuild = Config::get('system', 'build', null, true);
                                        if ($retryBuild !== $build) {
                                                Logger::info('Update already done.', ['from' => $stored, 'to' => $current]);
-                                               Lock::release('dbupdate');
+                                               DI::lock()->release('dbupdate');
                                                return '';
                                        }
 
@@ -111,7 +111,7 @@ class Update
                                                $r = self::runUpdateFunction($x, 'pre_update');
                                                if (!$r) {
                                                        Config::set('system', 'update', Update::FAILED);
-                                                       Lock::release('dbupdate');
+                                                       DI::lock()->release('dbupdate');
                                                        return $r;
                                                }
                                        }
@@ -127,7 +127,7 @@ class Update
                                                }
                                                Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
                                                Config::set('system', 'update', Update::FAILED);
-                                               Lock::release('dbupdate');
+                                               DI::lock()->release('dbupdate');
                                                return $retval;
                                        } else {
                                                Config::set('database', 'last_successful_update', $current);
@@ -140,7 +140,7 @@ class Update
                                                $r = self::runUpdateFunction($x, 'update');
                                                if (!$r) {
                                                        Config::set('system', 'update', Update::FAILED);
-                                                       Lock::release('dbupdate');
+                                                       DI::lock()->release('dbupdate');
                                                        return $r;
                                                }
                                        }
@@ -151,7 +151,7 @@ class Update
                                        }
 
                                        Config::set('system', 'update', Update::SUCCESS);
-                                       Lock::release('dbupdate');
+                                       DI::lock()->release('dbupdate');
                                }
                        }
                }
@@ -194,7 +194,7 @@ class Update
                                                L10n::t('Update %s failed. See error logs.', $x)
                                        );
                                        Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]);
-                                       Lock::release('dbupdate_function');
+                                       DI::lock()->release('dbupdate_function');
                                        return false;
                                } else {
                                        Config::set('database', 'last_successful_update_function', $funcname);
@@ -204,7 +204,7 @@ class Update
                                                Config::set('system', 'build', $x);
                                        }
 
-                                       Lock::release('dbupdate_function');
+                                       DI::lock()->release('dbupdate_function');
                                        Logger::info('Update function finished.', ['function' => $funcname]);
                                        return true;
                                }
index ed0f3a2e782c84e6fb5c8bfece784087807db087..086934fb8b1d4002450fee0312db7f49dc25ae61 100644 (file)
@@ -117,7 +117,7 @@ class Worker
                                // Trying to fetch new processes - but only once when successful
                                if (!$refetched && DI::lock()->acquire('worker_process', 0)) {
                                        self::findWorkerProcesses();
-                                       Lock::release('worker_process');
+                                       DI::lock()->release('worker_process');
                                        self::$state = self::STATE_REFETCH;
                                        $refetched = true;
                                } else {
@@ -133,17 +133,17 @@ class Worker
                                // Count active workers and compare them with a maximum value that depends on the load
                                        if (self::tooMuchWorkers()) {
                                                Logger::log('Active worker limit reached, quitting.', Logger::DEBUG);
-                                               Lock::release('worker');
+                                               DI::lock()->release('worker');
                                                return;
                                        }
 
                                        // Check free memory
                                        if (DI::process()->isMinMemoryReached()) {
                                                Logger::log('Memory limit reached, quitting.', Logger::DEBUG);
-                                               Lock::release('worker');
+                                               DI::lock()->release('worker');
                                                return;
                                        }
-                                       Lock::release('worker');
+                                       DI::lock()->release('worker');
                                }
                        }
 
@@ -940,7 +940,7 @@ class Worker
 
                $found = self::findWorkerProcesses();
 
-               Lock::release('worker_process');
+               DI::lock()->release('worker_process');
 
                if ($found) {
                        $stamp = (float)microtime(true);
@@ -1178,7 +1178,7 @@ class Worker
 
                // If there are already enough workers running, don't fork another one
                $quit = self::tooMuchWorkers();
-               Lock::release('worker');
+               DI::lock()->release('worker');
 
                if ($quit) {
                        return $added;
index 411608d677fdacfa5ec4a267223eaa0c702172dc..0fc1280c2b7f4577cb771b62e5f219fda2457bf2 100644 (file)
@@ -2076,11 +2076,11 @@ class Item
                } else {
                        // This shouldn't happen.
                        Logger::log('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
-                       Lock::release('item_insert_activity');
+                       DI::lock()->release('item_insert_activity');
                        return false;
                }
                if ($locked) {
-                       Lock::release('item_insert_activity');
+                       DI::lock()->release('item_insert_activity');
                }
                return true;
        }
@@ -2121,7 +2121,7 @@ class Item
                        Logger::log('Could not insert content for URI ' . $item['uri'] . ' - should not happen');
                }
                if ($locked) {
-                       Lock::release('item_insert_content');
+                       DI::lock()->release('item_insert_content');
                }
        }
 
index 99702f9517c74bd906dcdfbea01efcf20e0f9888..2e47f18d1655776c5f0a5f6886871797b28f9f66 100644 (file)
@@ -541,7 +541,7 @@ class OStatus
                                                        // We are having duplicated entries. Hopefully this solves it.
                                                        if (DI::lock()->acquire('ostatus_process_item_insert')) {
                                                                $ret = Item::insert($item);
-                                                               Lock::release('ostatus_process_item_insert');
+                                                               DI::lock()->release('ostatus_process_item_insert');
                                                                Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret);
                                                        } else {
                                                                $ret = Item::insert($item);
index 035a859365982579c1077a09e3d706f3a6e32bec..09bfd130c19fed7af7ee77fcb7a7fe8363e042f2 100644 (file)
@@ -103,7 +103,7 @@ trait DbaLockMockTrait
         * @param null|int $pid    The PID which was set
         * @param null|int $times  How often the method will get used
         *
-        *@see DatabaseLock::releaseLock()
+        *@see DatabaseLock::release()
         *
         */
        public function mockReleaseLock($key, $pid = null, $times = null)
index 269d48abd9c99dea437285f18ad79a28d7a162f4..70d7819d7318a739e5f0ebf5b42da73c34d7f254 100644 (file)
@@ -63,7 +63,7 @@ abstract class LockTest extends MockedTest
                $this->assertFalse($this->instance->isLocked('foo'));
                $this->assertTrue($this->instance->acquire('foo', 1));
                $this->assertTrue($this->instance->isLocked('foo'));
-               $this->instance->releaseLock('foo');
+               $this->instance->release('foo');
                $this->assertFalse($this->instance->isLocked('foo'));
        }
 
@@ -99,7 +99,7 @@ abstract class LockTest extends MockedTest
                $this->assertTrue($this->instance->acquire('bar', 1));
                $this->assertTrue($this->instance->acquire('nice', 1));
 
-               $this->assertTrue($this->instance->releaseLock('foo'));
+               $this->assertTrue($this->instance->release('foo'));
 
                $this->assertFalse($this->instance->isLocked('foo'));
                $this->assertTrue($this->instance->isLocked('bar'));
@@ -119,7 +119,7 @@ abstract class LockTest extends MockedTest
                $this->assertFalse($this->instance->isLocked('test'));
                $this->assertTrue($this->instance->acquire('test', 1, 10));
                $this->assertTrue($this->instance->isLocked('test'));
-               $this->assertTrue($this->instance->releaseLock('test'));
+               $this->assertTrue($this->instance->release('test'));
                $this->assertFalse($this->instance->isLocked('test'));
        }
 
@@ -197,6 +197,6 @@ abstract class LockTest extends MockedTest
        public function testReleaseLockWithoutLock()
        {
                $this->assertFalse($this->instance->isLocked('wrongLock'));
-               $this->assertFalse($this->instance->releaseLock('wrongLock'));
+               $this->assertFalse($this->instance->release('wrongLock'));
        }
 }
index 48c3b9f4360c53515f91c5eb725e9fc44106adee..089d891cab0dfebfcca32e2eb6187d2753f99634 100644 (file)
@@ -55,7 +55,7 @@ class SemaphoreLockTest extends LockTest
                touch($file);
 
                $this->assertTrue(file_exists($file));
-               $this->assertFalse($this->instance->releaseLock('test', false));
+               $this->assertFalse($this->instance->release('test', false));
                $this->assertTrue(file_exists($file));
        }
 
@@ -72,7 +72,7 @@ class SemaphoreLockTest extends LockTest
                touch($file);
 
                $this->assertTrue(file_exists($file));
-               $this->assertFalse($this->instance->releaseLock('test', true));
+               $this->assertFalse($this->instance->release('test', true));
                $this->assertTrue(file_exists($file));
        }
 
@@ -87,6 +87,6 @@ class SemaphoreLockTest extends LockTest
                $this->assertTrue(file_exists($file));
                $this->assertTrue($this->instance->acquire('test'));
                $this->assertTrue($this->instance->isLocked('test'));
-               $this->assertTrue($this->instance->releaseLock('test'));
+               $this->assertTrue($this->instance->release('test'));
        }
 }