Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / libs / lockmanager / NullLockManager.php
index b83462c..339a7ee 100644 (file)
  */
 
 /**
- * Simple version of LockManager that does nothing
+ * Simple version of LockManager that only does lock reference counting
  * @since 1.19
  */
 class NullLockManager extends LockManager {
        protected function doLock( array $paths, $type ) {
+               foreach ( $paths as $path ) {
+                       if ( isset( $this->locksHeld[$path][$type] ) ) {
+                               ++$this->locksHeld[$path][$type];
+                       } else {
+                               $this->locksHeld[$path][$type] = 1;
+                       }
+               }
+
                return StatusValue::newGood();
        }
 
        protected function doUnlock( array $paths, $type ) {
-               return StatusValue::newGood();
+               $status = StatusValue::newGood();
+
+               foreach ( $paths as $path ) {
+                       if ( isset( $this->locksHeld[$path][$type] ) ) {
+                               if ( --$this->locksHeld[$path][$type] <= 0 ) {
+                                       unset( $this->locksHeld[$path][$type] );
+                                       if ( !$this->locksHeld[$path] ) {
+                                               unset( $this->locksHeld[$path] ); // clean up
+                                       }
+                               }
+                       } else {
+                               $status->warning( 'lockmanager-notlocked', $path );
+                       }
+               }
+
+               return $status;
        }
 }