*
* @param array $params Parameters for the specific Horde_Lock driver
*
- * @return Horde_Lock Instance of Horde_Lock on success or PEAR_Error
+ * @return Horde_Lock Instance of Horde_Lock
*/
public function __construct($params)
{
*
* @param string $lockid Lock ID to look up
*
- * @return mixed Array of lock information on success; PEAR_Error
- * on failure.
+ * @return mixed Array of lock information
+ * @throws Horde_Log_Exception
*/
public function getLockInfo($lockid)
{
- return PEAR::raiseError(_("No lock driver configured!"));
+ throw new Horde_Log_Exception(_("No lock driver configured!"));
}
/**
* @param int $type Only return locks of the given type.
* Defaults to null, or all locks
*
- * @return mixed Array of locks with the ID as the key and the lock details
+ * @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. On failure a PEAR_Error object
- * will be returned.
+ * return an empty array.
+ *
+ * @throws Horde_Log_Exception
*/
public function getLocks($scope = null, $principal = null, $type = null)
{
- return PEAR::raiseError(_("No lock driver configured!"));
+ throw new Horde_Log_Exception(_("No lock driver configured!"));
}
/**
* lock.
* @param int $extend Extend lock this many seconds from now.
*
- * @return mixed True on success; PEAR_Error on failure.
+ * @return boolean
+ * @throws Horde_Log_Exception
*/
public function resetLock($lockid, $extend)
{
- return PEAR::raiseError(_("No lock driver configured!"));
+ throw new Horde_Log_Exception(_("No lock driver configured!"));
}
/**
* will be considered valid until they are
* cleared or expire.
*
- * @return mixed A string lock ID on success; PEAR_Error on failure.
+ * @return mixed A string lock ID.
+ * @throws Horde_Log_Exception
*/
public function setLock($requestor, $scope, $principal,
$lifetime = 1, $exclusive = HORDE_LOCK_TYPE_SHARED)
{
- return PEAR::raiseError(_("No lock driver configured!"));
+ throw new Horde_Log_Exception(_("No lock driver configured!"));
}
/**
* @param string $lockid The lock ID as generated by a previous call
* to setLock()
*
- * @return mixed True on success; PEAR_Error on failure.
+ * @return boolean
+ * @throws Horde_Log_Exception
*/
public function clearLock($lockid)
{
- return PEAR::raiseError(_("No lock driver configured!"));
+ throw new Horde_Log_Exception(_("No lock driver configured!"));
}
/**
* @param array $params A hash containing any additional configuration or
* connection parameters a subclass might need.
*
- * @return Horde_Lock The newly created concrete Lock instance, or a
- * PEAR_Error object on error.
+ * @return Horde_Lock The newly created concrete Lock instance.
+ * @throws Horde_Log_Exception
*/
public function factory($driver, $params = null)
{
if (class_exists($class)) {
$lock = new $class($params);
} else {
- $lock = PEAR::raiseError('Horde_Lock Driver (' . $class . ') not found' . ($include_error ? ': ' . $include_error : '') . '.');
+ throw new Horde_Log_Exception('Horde_Lock Driver (' . $class . ') not found' . ($include_error ? ': ' . $include_error : '') . '.');
}
return $lock;
* @param array $params A hash containing any additional configuration or
* connection parameters a subclass might need.
*
- * @return Horde_Lock The concrete Horde_Lock reference or PEAR_Error
- * on failure.
+ * @return Horde_Lock The concrete Horde_Lock reference
+ * @throws Horde_Log_Exception
*/
public function &singleton($driver, $params = null)
{
/**
* Return an array of information about the requested lock.
*
- * @param string $lockid Lock ID to look up
- *
- * @return mixed Array of lock information on success; false if no
- * valid lock exists; PEAR_Error on failure.
+ * @see Horde_Lock::getLockInfo
*/
public function getLockInfo($lockid)
{
if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal database error. Details have been logged for the administrator."));
+ throw new Horde_Lock_Exception(_("Internal database error. Details have been logged for the administrator."));
}
$now = time();
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$result = $this->_db->query($sql, $values);
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
$locks = array();
* Return a list of valid locks with the option to limit the results
* by principal, scope and/or type.
*
- * @param string $scope The scope of the lock. Typically the name of
- * the application requesting the lock or some
- * other identifier used to group locks together.
- * @param string $principal Principal for which to check for locks
- * @param int $type Only return locks of the given type.
- * Defaults to null, or all locks
- *
- * @return mixed 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. On failure a PEAR_Error object
- * will be returned.
+ * @see Horde_Lock::getLocks
*/
public function getLocks($scope = null, $principal = null, $type = null)
{
if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal database error. Details have been logged for the administrator."));
+ throw new Horde_Lock_Exception(_("Internal database error. Details have been logged for the administrator."));
}
$now = time();
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$result = $this->_db->query($sql, $values);
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
$locks = array();
/**
* Extend the valid lifetime of a valid lock to now + $newtimeout.
*
- * @param string $lockid Lock ID to reset. Must be a valid, non-expired
- * lock.
- * @param int $extend Extend lock this many seconds from now.
- *
- * @return mixed True on success; false on expired lock;
- * PEAR_Error on failure.
+ * @see Horde_Lock::resetLock
*/
public function resetLock($lockid, $extend)
{
if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal database error. Details have been logged for the administrator."));
+ throw new Horde_Lock_Exception(_("Internal database error. Details have been logged for the administrator."));
}
$now = time();
$sql, __FILE__, __LINE__, PEAR_LOG_DEBUG);
$result = $this->_write_db->query($sql, $values);
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
-
Horde::logMessage(sprintf('Lock %s reset successfully.', $lockid), __FILE__, __LINE__, PEAR_LOG_INFO);
return true;
} elseif (is_a($lockinfo, 'PEAR_Error')) {
- return $lockinfo;
+ throw new Horde_Lock_Exception($lockinfo->getMessage());
} else {
// $lockinfo is false indicating the lock is no longer valid.
return false;
* that the calling application has done all necessary security checks
* before requesting a lock be granted.
*
- * @param string $requestor User ID of the lock requestor.
- * @param string $scope The scope of the lock. Typically the name of
- * the application requesting the lock or some
- * other identifier used to group locks together.
- * @param string $principal A principal on which a lock should be granted.
- * The format can be any string but is suggested
- * to be in URI form.
- * @param int $lifetime Time (in seconds) for which the lock will be
- * considered valid.
- * @param string type One of HORDE_LOCK_TYPE_SHARED or
- * HORDE_LOCK_TYPE_EXCLUSIVE.
- * - An exclusive lock will be enforced strictly
- * and must be interpreted to mean that the
- * resource can not be modified. Only one
- * exclusive lock per principal is allowed.
- * - A shared lock is one that notifies other
- * potential lock requestors that the resource
- * is in use. This lock can be overridden
- * (cleared or replaced with a subsequent
- * call to setLock()) by other users. Multiple
- * users may request (and will be granted) a
- * shared lock on a given principal. All locks
- * will be considered valid until they are
- * cleared or expire.
- *
- * @return mixed A string lock ID on success; PEAR_Error on failure.
+ * @see Horde_Lock::setLock
*/
public function setLock($requestor, $scope, $principal,
$lifetime = 1, $type = HORDE_LOCK_TYPE_SHARED)
{
if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal database error. Details have been logged for the administrator."));
+ throw new Horde_Lock_Exception(_("Internal database error. Details have been logged for the administrator."));
}
$oldlocks = $this->getLocks($scope, $principal, HORDE_LOCK_TYPE_EXCLUSIVE);
if (is_a($oldlocks, 'PEAR_Error')) {
- return $oldlocks;
+ throw new Horde_Lock_Exception($oldlocks->getMessage());
}
if (count($oldlocks) != 0) {
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$result = $this->_write_db->query($sql, $values);
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
Horde::logMessage(sprintf('Lock %s set successfully by %s in scope %s on "%s"', $lockid, $requestor, $scope, $principal), __FILE__, __LINE__, PEAR_LOG_INFO);
* that the calling application has done all necessary security checks
* before requesting a lock be cleared.
*
- * @param string $lockid The lock ID as generated by a previous call
- * to setLock()
- *
- * @return mixed True on success; PEAR_Error on failure.
+ * @see Horde_Lock::clearLock
*/
public function clearLock($lockid)
{
if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal database error. Details have been logged for the administrator."));
+ throw new Horde_Lock_Exception(_("Internal database error. Details have been logged for the administrator."));
}
if (empty($lockid)) {
- return PEAR::raiseError(_("Must supply a valid lock ID."));
+ throw new Horde_Lock_Exception(_("Must supply a valid lock ID."));
}
// Since we're trying to clear the lock we don't care
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$result = $this->_write_db->query($sql, $values);
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
Horde::logMessage(sprintf('Lock %s cleared successfully.', $lockid), __FILE__, __LINE__, PEAR_LOG_INFO);
'Lock SQL', array('driver' => 'lock'));
if (is_a($result, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
+ throw new Horde_Lock_Exception($result->getMessage());
}
require_once 'DB.php';
);
if (is_a($this->_write_db, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $this->_write_db;
+ throw new Horde_Lock_Exception($this->_write_db->getMessage());
}
// Set DB portability options.
);
if (is_a($this->_db, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $this->_db;
+ throw new Horde_Lock_Exception($this->_db->getMessage());
}
// Set DB portability options.