* @param integer $queryId A query id.
*
* @return Whups_Query The matching query or null if not found.
+ * @throws Whups_Exception
*/
function getQuery($queryId)
{
- $share = $this->_shareManager->getShareById($queryId);
- if (is_a($share, 'PEAR_Error')) {
- return $share;
+ try {
+ $share = $this->_shareManager->getShareById($queryId);
+ } catch (Horde_Share_Exception $e) {
+ throw new Whups_Exception($e);
}
-
return $this->_getQuery($share);
}
* @param string $slug A query slug.
*
* @return Whups_Query The matching query or null if not found.
+ * @throws Whups_Exception
*/
function getQueryBySlug($slug)
{
- $shares = $this->_shareManager->listShares(Horde_Auth::getAuth(), Horde_Perms::READ,
- array('slug' => $slug));
- if (is_a($shares, 'PEAR_Error')) {
- return $shares;
+ try {
+ $shares = $this->_shareManager->listShares(Horde_Auth::getAuth(), Horde_Perms::READ,
+ array('slug' => $slug));
+ } catch (Horde_Share_Exception $e) {
+ throw new Whups_Exception($e);
}
if (!count($shares)) {
return;
function _getQuery($share)
{
$queryDetails = $GLOBALS['whups_driver']->getQuery($share->getId());
- if (is_a($queryDetails, 'PEAR_Error')) {
+ if ($queryDetails instanceof PEAR_Error) {
return $queryDetails;
}
*/
function hasPermission($queryId, $userid, $permission, $creator = null)
{
- $share = $this->_shareManager->getShareById($queryId);
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $this->_shareManager->getShareById($queryId);
+ } catch (Horde_Share_Exception $e) {
// If the share doesn't exist yet, then it has open perms.
return true;
}
*/
function listQueries($user, $return_slugs = false)
{
- $shares = $this->_shareManager->listShares($user);
- if (is_a($shares, 'PEAR_Error')) {
- return $shares;
+ try {
+ $shares = $this->_shareManager->listShares($user);
+ } catch (Horde_Share_Exception $e) {
+ throw new Whups_Exception($e):
}
$queries = array();
/**
* @param Whups_Query $query The query to save.
+ * @throws Whups_Exception
*/
function save($query)
{
if ($query->id) {
// Query already exists; get its share and update the name
// if necessary.
- $share = $this->_shareManager->getShareById($query->id);
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $this->_shareManager->getShareById($query->id);
+ } catch (Horde_Share_Exception $e) {
// Share has an id but doesn't exist; just throw an
// error.
- return $share;
+ throw new Whups_Exception($e);
}
if ($share->get('name') != $query->name ||
$share->get('slug') != $query->slug) {
$share = $this->_shareManager->newShare(md5(microtime()));
$share->set('name', $query->name);
$share->set('slug', $query->slug);
- $result = $this->_shareManager->addShare($share);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ try {
+ $this->_shareManager->addShare($share);
+ } catch (Horde_Share_Exception $e) {
+ throw new Whups_Exception($e);
}
$query->id = $share->getId();
}
return;
}
- $share = $this->_shareManager->getShareById($query->id);
- if (is_a($share, 'PEAR_Error')) {
- return $share;
- }
-
- $result = $this->_shareManager->removeShare($share);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ try {
+ $share = $this->_shareManager->getShareById($query->id);
+ $this->_shareManager->removeShare($share);
+ } catch (Horde_Share_Exception $e) {
+ throw new Whups_Exception($e);
}
-
$result = $GLOBALS['whups_driver']->deleteQuery($query->id);
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
return $result;
}