]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Lock/DatabaseLockDriver.php
Deleting parameter-types of methods (lack of support in PHP 5.6)
[friendica.git] / src / Core / Lock / DatabaseLockDriver.php
index 8761a1479ee219ca24c86cace4481bc240fbe7d0..9b415753fceecec0663900c682a2e8d5618b1539 100644 (file)
@@ -8,7 +8,7 @@ use Friendica\Database\DBM;
 /**
  * Locking driver that stores the locks in the database
  */
-class DatabaseLockDriver implements ILockDriver
+class DatabaseLockDriver extends AbstractLockDriver
 {
        /**
         * @brief Sets a lock for a given name
@@ -42,7 +42,7 @@ class DatabaseLockDriver implements ILockDriver
                                        dba::update('locks', ['locked' => true, 'pid' => getmypid()], ['name' => $key]);
                                        $got_lock = true;
                                }
-                       } elseif (!DBM::is_result($lock)) {
+                       } else {
                                dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid()]);
                                $got_lock = true;
                        }
@@ -54,6 +54,8 @@ class DatabaseLockDriver implements ILockDriver
                        }
                } while (!$got_lock && ((time() - $start) < $timeout));
 
+               $this->markAcquire($key);
+
                return $got_lock;
        }
 
@@ -66,7 +68,9 @@ class DatabaseLockDriver implements ILockDriver
         */
        public function releaseLock($key)
        {
-               dba::update('locks', ['locked' => false, 'pid' => 0], ['name' => $key, 'pid' => getmypid()]);
+               dba::delete('locks', ['locked' => false, 'pid' => 0], ['name' => $key, 'pid' => getmypid()]);
+
+               $this->releaseLock($key);
 
                return;
        }
@@ -78,6 +82,8 @@ class DatabaseLockDriver implements ILockDriver
         */
        public function releaseAll()
        {
-               dba::update('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]);
+               dba::delete('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]);
+
+               $this->acquiredLocks = [];
        }
 }