From: Aaron Schulz Date: Tue, 5 Mar 2013 19:03:20 +0000 (-0800) Subject: [LockManager] Added ScopedLock::release function. X-Git-Tag: 1.31.0-rc.0~20476^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=98dc0349b25714b75dc631b1e63724e926bae7d2;p=lhc%2Fweb%2Fwiklou.git [LockManager] Added ScopedLock::release function. * Added more lock unit tests. Change-Id: Ic359307cf26cfb621ae8d2db867801735a375dde --- diff --git a/includes/filebackend/lockmanager/ScopedLock.php b/includes/filebackend/lockmanager/ScopedLock.php index 5a80bee8b3..790a5c64a7 100644 --- a/includes/filebackend/lockmanager/ScopedLock.php +++ b/includes/filebackend/lockmanager/ScopedLock.php @@ -78,6 +78,19 @@ class ScopedLock { return null; } + /** + * Release a scoped lock and set any errors in the attatched Status object. + * This is useful for early release of locks before function scope is destroyed. + * This is the same as setting the lock object to null. + * + * @param ScopedLock $lock + * @return void + * @since 1.21 + */ + public static function release( ScopedLock &$lock = null ) { + $lock = null; + } + function __destruct() { $wasOk = $this->status->isOK(); $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) ); diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index dac5edb341..a08910a92a 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -2072,6 +2072,23 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName)." ); } + + $status = Status::newGood(); + $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status ); + $this->assertType( 'ScopedLock', $sl, + "Scoped locking of files succeeded ($backendName)." ); + $this->assertEquals( array(), $status->errors, + "Scoped locking of files succeeded ($backendName)." ); + $this->assertEquals( true, $status->isOK(), + "Scoped locking of files succeeded with OK status ($backendName)." ); + + ScopedLock::release( $sl ); + $this->assertEquals( null, $sl, + "Scoped unlocking of files succeeded ($backendName)." ); + $this->assertEquals( array(), $status->errors, + "Scoped unlocking of files succeeded ($backendName)." ); + $this->assertEquals( true, $status->isOK(), + "Scoped unlocking of files succeeded with OK status ($backendName)." ); } // test helper wrapper for backend prepare() function