Copyright 2008-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Ben Klang (bklang@horde.org)
Example #1
0
 public function unlock()
 {
     if ($this->_locks && $this->_lock) {
         $this->_locks->clearLock($this->_lock['lock_id']);
         unset($this->_lock);
     }
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param array $params  Parameters:
  * <pre>
  *   - collection: (string) The collection name.
  *   - mongo_db: [REQUIRED] (Horde_Mongo_Client) A MongoDB client object.
  * </pre>
  */
 public function __construct(array $params = array())
 {
     if (!isset($params['mongo_db'])) {
         throw new InvalidArgumentException('Missing mongo_db parameter.');
     }
     parent::__construct(array_merge(array('collection' => 'horde_locks'), $params));
     $this->_db = $this->_params['mongo_db']->selectCollection(null, $this->_params['collection']);
 }
Example #3
0
 /**
  * Removes a lock from a uri
  *
  * @param string $uri
  * @param Locks\LockInfo $lockInfo
  * @return bool
  */
 public function unlock($uri, Locks\LockInfo $lockInfo)
 {
     try {
         $this->_lock->clearLock($lockInfo->token);
     } catch (Horde_Lock_Exception $e) {
         throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
Example #4
0
File: Sql.php Project: horde/horde
 /**
  * Constructor.
  *
  * @param array $params  Parameters:
  * <pre>
  * 'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance.
  * 'table' - (string) The name of the lock table in 'database'.
  *           DEFAULT: 'horde_locks'
  * </pre>
  *
  * @throws Horde_Lock_Exception
  */
 public function __construct($params = array())
 {
     if (!isset($params['db'])) {
         throw new Horde_Lock_Exception('Missing db parameter.');
     }
     $this->_db = $params['db'];
     unset($params['db']);
     $params = array_merge(array('table' => 'horde_locks'), $params);
     parent::__construct($params);
     /* Only do garbage collection 0.1% of the time we create an object. */
     if (substr(time(), -3) === '000') {
         register_shutdown_function(array($this, 'doGC'));
     }
 }
Example #5
0
File: Base.php Project: horde/horde
 /**
  * Returns whether a user is currently locked.
  *
  * @param string $userId         The user to check.
  * @param boolean $show_details  Return timeout too?
  *
  * @return boolean|array  If $show_details is a true, an array with
  *                        'locked' and 'lock_timeout' values. Whether the
  *                        user is locked, otherwise.
  * @throws Horde_Auth_Exception
  */
 public function isLocked($userId, $show_details = false)
 {
     if (!$this->_lock_api) {
         throw new Horde_Auth_Exception('Unsupported.');
     }
     try {
         $locks = $this->_lock_api->getLocks('horde_auth', 'login:'******'locked' => false, 'lock_timeout' => 0) : array('locked' => true, 'lock_timeout' => $locks[$lock_id]['lock_expiry_timestamp']);
     }
     return !empty($locks);
 }
Example #6
0
 /**
  * Checks for existing locks.
  *
  * First this checks for share locks and if none exists, checks for item
  * locks (if item_uid defined).  It will return the first lock found.
  *
  * @param Horde_Lock  $locks  The lock object.
  * @param string $item_uid    A uid of an item from this share.
  *
  * @return array   Hash with the found lock information in 'lock' and the
  *                 lock type ('share' or 'item') in 'type', or an empty
  *                 array if there are no locks.
  */
 public function checkLocks(Horde_Lock $locks, $item_uid = null)
 {
     $shareid = $this->_share->getId();
     $locktype = Horde_Lock::TYPE_EXCLUSIVE;
     // Check for share locks
     try {
         $result = $locks->getLocks($this->_share->getShareOb()->getApp(), $shareid, $locktype);
     } catch (Horde_Lock_Exception $e) {
         Horde::log($e, 'ERR');
         throw new Horde_Exception_Wrapped($e);
     }
     if (empty($result) && !empty($item_uid)) {
         // Check for item locks
         $locktargettype = 'item';
         try {
             $result = $locks->getLocks($this->_share->getShareOb()->getApp() . ':' . $shareid, $item_uid, $locktype);
         } catch (Horde_Lock_Exception $e) {
             Horde::log($e, 'ERR');
             throw new Horde_Exception($e->getMessage());
         }
     } else {
         $locktargettype = 'share';
     }
     if (empty($result)) {
         return array();
     }
     return array('type' => $locktargettype, 'lock' => reset($result));
 }