Return a list of valid locks with the option to limit the results
by principal, scope and/or type.
abstract public getLocks ( string $scope = null, string $principal = null, integer $type = null ) : array | ||
$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 | Principal for which to check for locks |
$type | integer | Only return locks of the given type. Defaults to null, or all locks |
return | array | Array of locks with the ID as the key and the lock details as the value. If there are no current locks this will return an empty array. |
/** * Returns a list of Sabre\DAV\Locks\LockInfo objects * * This method should return all the locks for a particular uri, including * locks that might be set on a parent uri. * * If returnChildLocks is set to true, this method should also look for * any locks in the subtree of the uri for locks. * * @param string $uri * @param bool $returnChildLocks * @return array */ public function getLocks($uri, $returnChildLocks) { list($app) = explode('/', $uri); try { // @todo use $returnChildLocks when we implemented sub-tree // searching in Horde_Lock $locks = $this->_lock->getLocks($app, $uri); } catch (Horde_Lock_Exception $e) { throw new DAV\Exception($e->getMessage(), $e->getCode(), $e); } $infos = array(); foreach ($locks as $lock) { $info = new Locks\LockInfo(); $info->owner = $lock['lock_owner']; $info->token = $lock['lock_id']; $info->timeout = $lock['lock_expiry_timestamp']; $info->created = $lock['lock_origin_timestamp']; $info->scope = $lock['lock_type'] == Horde_Lock::TYPE_EXCLUSIVE ? Locks\LockInfo::EXCLUSIVE : Locks\LockInfo::SHARED; $info->uri = $lock['lock_principal']; $infos[] = $info; } return $infos; }
/** * 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); }
/** * 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)); }
/** * Constructs a standard page class to represent a wiki page. * * @param string $pagename The name of the page to represent. */ public function __construct($pagename) { if (is_array($pagename)) { $this->_page = $pagename; return; } $page = null; try { $page = $GLOBALS['wicked']->retrieveByName($pagename); } catch (Wicked_Exception $e) { // If we can't load $pagename, see if there's default data for it. // Protect against directory traversion. $pagepath = realpath(WICKED_BASE . '/data/' . $GLOBALS['conf']['wicked']['format']); $pagefile = realpath($pagepath . '/' . $pagename); if ($pagefile && Horde_String::common($pagefile, $pagepath) == $pagepath && substr($pagename, 0, 1) != '.' && file_exists($pagefile) && ($text = file_get_contents($pagefile))) { try { $GLOBALS['wicked']->newPage($pagename, $text); try { $page = $GLOBALS['wicked']->retrieveByName($pagename); } catch (Wicked_Exception $e) { $GLOBALS['notification']->push(sprintf(_("Unable to create %s"), $pagename), 'horde.error'); } } catch (Wicked_Exception $e) { } } } if ($page) { $this->_page = $page; } else { if ($pagename == 'Wiki/Home') { $GLOBALS['notification']->push(_("Unable to create Wiki/Home. The wiki is not configured."), 'horde.error'); } $this->_page = array(); } // Make sure 'wicked' permission exists. Set reasonable defaults if // necessary. $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); $corePerms = $GLOBALS['injector']->getInstance('Horde_Core_Perms'); if (!$perms->exists('wicked')) { $perm = $corePerms->newPermission('wicked'); $perm->addGuestPermission(Horde_Perms::SHOW | Horde_Perms::READ, false); $perm->addDefaultPermission(Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE, false); $perms->addPermission($perm); } // Make sure 'wicked:pages' exists. Copy from 'wicked' if it does not // exist. if (!$perms->exists('wicked:pages')) { $perm = $corePerms->newPermission('wicked:pages'); $copyFrom = $perms->getPermission('wicked'); $perm->addGuestPermission($copyFrom->getGuestPermissions(), false); $perm->addDefaultPermission($copyFrom->getDefaultPermissions(), false); $perm->addCreatorPermission($copyFrom->getCreatorPermissions(), false); foreach ($copyFrom->getUserPermissions() as $user => $uperm) { $perm->addUserPermission($user, $uperm, false); } foreach ($copyFrom->getGroupPermissions() as $group => $gperm) { $perm->addGroupPermission($group, $gperm, false); } $perms->addPermission($perm); } if ($GLOBALS['conf']['lock']['driver'] != 'none') { $this->supportedModes[Wicked::MODE_LOCKING] = $this->supportedModes[Wicked::MODE_UNLOCKING] = true; $this->_locks = $GLOBALS['injector']->getInstance('Horde_Lock'); $locks = $this->_locks->getLocks('wicked', $pagename, Horde_Lock::TYPE_EXCLUSIVE); if ($locks) { $this->_lock = reset($locks); } } }