Sets a lock on the requested principal and returns the generated lock
ID. NOTE: No security checks are done in the Horde_Lock API. It is
expected that the calling application has done all necessary security
checks before requesting a lock be granted.
abstract public setLock ( string $requestor, string $scope, string $principal, integer $lifetime = 1, $exclusive = Horde_Lock::TYPE_SHARED ) : mixed | ||
$requestor | string | User ID of the lock requestor. |
$scope | string | The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together. |
$principal | string | A principal on which a lock should be granted. The format can be any string but is suggested to be in URI form. |
$lifetime | integer | Time (in seconds) for which the lock will be considered valid. |
Résultat | mixed | A string lock ID. |
/** * @throws Wicked_Exception */ public function lock() { if ($this->_locks) { $id = $this->_locks->setLock(Wicked::lockUser(), 'wicked', $this->pageName(), $GLOBALS['conf']['wicked']['lock']['time'] * 60, Horde_Lock::TYPE_EXCLUSIVE); if ($id) { $this->_lock = $this->_locks->getLockInfo($id); } else { throw new Wicked_Exception(_("The page is already locked.")); } } }
/** * Locks a uri * * @param string $uri * @param Locks\LockInfo $lockInfo * @return bool */ public function lock($uri, Locks\LockInfo $lockInfo) { list($app) = explode('/', $uri); $type = $lockInfo->scope == Locks\LockInfo::EXCLUSIVE ? Horde_Lock::TYPE_EXCLUSIVE : Horde_Lock::TYPE_SHARED; try { $lockId = $this->_lock->setLock($this->_registry->getAuth(), $app, $uri, $lockInfo->timeout ?: Horde_Lock::PERMANENT, $type); $lockInfo->token = $lockId; } catch (Horde_Lock_Exception $e) { throw new DAV\Exception($e->getMessage(), $e->getCode(), $e); } }
/** * Locks a user indefinitely or for a specified time. * * @param string $userId The user to lock. * @param integer $time The duration in minutes, 0 = permanent. * * @throws Horde_Auth_Exception */ public function lockUser($userId, $time = 0) { if (!$this->_lock_api) { throw new Horde_Auth_Exception('Unsupported.'); } if ($time == 0) { $time = Horde_Lock::PERMANENT; } else { $time *= 60; } try { if ($this->_lock_api->setLock($userId, 'horde_auth', 'login:'******'User is already locked', Horde_Auth::REASON_LOCKED); }
/** * Lock an item belonging to a share, or an entire share itself. * * @param Horde_Lock $locks The lock object. * @param string $uid The uid of a specific object to lock, if * null, entire share is locked. * * @return mixed A lock ID on sucess, false if: * - The share is already locked, * - The item is already locked, * - A share lock was requested and an item is already locked in the * share. */ public function lock(Horde_Lock $locks, $uid = null) { $shareid = $this->_share->getId(); // Default parameters. $locktype = Horde_Lock::TYPE_EXCLUSIVE; $timeout = 600; $itemscope = $this->_share->getShareOb()->getApp() . ':' . $shareid; if (!empty($uid)) { // Check if the share is locked. Share locks are placed at app scope try { $result = $locks->getLocks($this->_share->getShareOb()->getApp(), $shareid, $locktype); } catch (Horde_Lock_Exception $e) { throw new Horde_Exception_Wrapped($e); } if (!empty($result)) { // Lock found. return false; } // Try to place the item lock at app:shareid scope. return $locks->setLock($GLOBALS['registry']->getAuth(), $itemscope, $uid, $timeout, $locktype); } else { // Share lock requested. Check for locked items. try { $result = $locks->getLocks($itemscope, null, $locktype); } catch (Horde_Lock_Exception $e) { throw new Horde_Exception_Wrapped($e); } if (!empty($result)) { // Lock found. return false; } // Try to place the share lock return $locks->setLock($GLOBALS['registry']->getAuth(), $this->_share->getShareOb()->getApp(), $shareid, $timeout, $locktype); } }