* <pre>
* (integer)selected The gallery_id of the gallery that is selected
* (integer)perm The permissions filter to use [Horde_Perms::SHOW]
- * (mixed)filter Restrict the galleries returned to those matching
+ * (mixed)attributes Restrict the galleries returned to those matching
* the filters. Can be an array of attribute/values
* pairs or a gallery owner username.
- * (boolean)allLevels
+ * (boolean)all_levels
* (integer)parent The parent share to start listing at.
* (integer)from The gallery to start listing at.
* (integer)count The number of galleries to return.
*/
static public function selectGalleries($params = array())
{
- $params = new Horde_Support_Array($params);
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Injector_Factory_Storage')
->create()
->listGalleries($params);
+ $params = new Horde_Support_Array($params);
$tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('gallery_tree', 'Select');
/* Remove the ignored gallery, make sure it's also not the selected
$storage = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create();
if (empty($path)) {
$owners = array();
- $galleries = $storage->listGalleries(array('allLevels' => false));
+ $galleries = $storage->listGalleries(array('all_levels' => false));
foreach ($galleries as $gallery) {
$owners[$gallery->data['share_owner'] ? $gallery->data['share_owner'] : '-system-'] = true;
}
} else {
if (count($parts) == 1) {
// This request is for all galleries owned by the requested user.
- $galleries = $storage->listGalleries(array('filter' => $parts[0],
- 'allLevels' => false));
+ $galleries = $storage->listGalleries(array('attributes' => $parts[0],
+ 'all_levels' => false));
$images = array();
} elseif ($this->galleryExists(null, end($parts))) {
// This request if for a certain gallery, list all sub-galleries
throw new Horde_Exception_NotFound(_("Invalid gallery specified."));
}
$galleries = $storage->listGalleries(array('parent' => $gallery_id,
- 'allLevels' => false));
+ 'all_levels' => false));
$images = $this->listImages(null, $gallery_id, Horde_Perms::SHOW, 'mini');
} elseif (count($parts) > 2 &&
* <pre>
* (string)scope The application scope, if not default.
* (integer)perm The permissions filter to use [Horde_Perms::SHOW]
- * (mixed)filter Restrict the galleries returned to those matching
+ * (mixed)attributes Restrict the galleries returned to those matching
* the filters. Can be an array of attribute/values
* pairs or a gallery owner username.
* (integer)parent The parent share to start listing at.
- * (boolean)allLevels If set, return all levels below parent, not just
+ * (boolean)all_levels If set, return all levels below parent, not just
* direct children [TRUE]
* (integer)from The gallery to start listing at.
* (integer)count The number of galleries to return.
try {
$galleries = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')
->create()->listGalleries(array('perm' => Horde_Perms::EDIT,
- 'filter' => $GLOBALS['registry']->getAuth(),
- 'allLevels' => false,
- 'count' => empty($this->_params['limit']) ? 0 : $this->_params['limit'],
- 'sort_by' => 'last_modified',
- 'direction' => Ansel::SORT_DESCENDING));
+ 'attributes' => $GLOBALS['registry']->getAuth(),
+ 'all_levels' => false,
+ 'count' => empty($this->_params['limit']) ? 0 : $this->_params['limit'],
+ 'sort_by' => 'last_modified',
+ 'direction' => Ansel::SORT_DESCENDING));
} catch (Ansel_Exception $e) {
return $e->getMessage();
{
/* Pass on up the chain */
parent::__construct($attributes);
- $this->setShareOb($GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->shares);
- $mode = isset($attributes['attribute_view_mode']) ? $attributes['attribute_view_mode'] : 'Normal';
- $this->_setModeHelper($mode);
+ $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->shares->initShareObject($this);
+ $this->_setModeHelper(isset($attributes['attribute_view_mode']) ? $attributes['attribute_view_mode'] : 'Normal');
}
/**
try {
$this->save();
} catch (Horde_Share_Exception $e) {
- Horde::logMessage($e->getMessage, 'ERR');
- throw Ansel_Exception($e);
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Ansel_Exception($e);
}
/* Make sure we get rid of key image/stacks if no more images */
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Injector_Factory_Storage')
->create()
- ->listGalleries(array('parent' => $this, 'allLevels' => false));
+ ->listGalleries(array('parent' => $this, 'all_levels' => false));
foreach ($galleries as $galleryId => $gallery) {
if ($default_img = $gallery->getKeyImage($style)) {
/* Update the backend, but only this current change */
if ($update) {
- $db = $this->getShareOb()->getWriteDb();
+ $db = $this->getShareOb()->getStorage();
// Manually convert the charset since we're not going through save()
$data = $this->getshareOb()->toDriverCharset(array($driver_key => $value));
- $query = $db->prepare('UPDATE ' . $this->getShareOb()->getTable() . ' SET ' . $driver_key . ' = ? WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
+ $sql = 'UPDATE ' . $this->getShareOb()->getTable() . ' SET ' . $driver_key . ' = ? WHERE share_id = ?';
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
}
- $result = $query->execute(array($data[$driver_key], $this->id));
- $query->free();
- if ($result instanceof PEAR_Error) {
- throw new Horde_Exception($result->getMessage());
- }
-
+ $db->update($sql, array($data[$driver_key], $this->id));
}
return true;
return $this->_modeHelper->getGalleryCrumbData();
}
- /**
- *
- */
- public function __sleep()
- {
- $properties = get_object_vars($this);
- unset($properties['_shareOb']);
- unset($properties['_modeHelper']);
- $properties = array_keys($properties);
- return $properties;
- }
-
- public function __wakeup()
+ public function unserialize($data)
{
- $this->setShareOb($GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->shares);
- $mode = $this->get('view_mode');
- $this->_setModeHelper($mode);
+ parent::unserialize($data);
+ $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->shares->initShareObject($this);
+ $this->_setModeHelper($this->get('view_mode'));
}
}
/**
* Return a count of the number of children this share has
*
- * @param integer $perm A Horde_Perms::* constant
+ * @param string $user The user to use for checking perms
+ * @param integer $perm A Horde_Perms::* constant
* @param boolean $allLevels Count grandchildren or just children
*
* @return mixed The number of child shares || PEAR_Error
*/
- public function countChildren($perm = Horde_Perms::SHOW, $allLevels = true)
+ public function countChildren($user, $perm = Horde_Perms::SHOW, $allLevels = true)
{
- return $this->_gallery->getShareOb()->countShares($GLOBALS['registry']->getAuth(), $perm, null, $this, $allLevels);
+ return $this->_gallery->getShareOb()->countShares($user, $perm, null, $this, $allLevels);
}
/**
if ($num_galleries > $from) {
$galleries = $storage->listGalleries(
array('parent' => $this->_gallery,
- 'allLevels' => false,
+ 'all_levels' => false,
'from' => $from,
'count' => $to));
}
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Injector_Factory_Storage')
->create()
- ->listGalleries(array('parent' => $parent, 'allLevels' => false));
+ ->listGalleries(array('parent' => $parent, 'all_levels' => false));
foreach ($galleries as $gallery) {
if ($gallery->countImages()) {
*
* @return Ansel_Storage
*/
- public function __construct(Horde_Share_Sql_Hierarchical $shareOb)
+ public function __construct(Horde_Core_Share_Driver $shareOb)
{
/* This is the only supported share backend for Ansel */
$this->_shares = $shareOb;
/* Create the gallery */
try {
- $gallery = $this->_shares->newShare('');
+ $gallery = $this->_shares->newShare($GLOBALS['registry']->getAuth(), '');
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e->getMessage, 'ERR');
throw new Ansel_Exception($e);
public function removeGallery(Ansel_Gallery $gallery)
{
/* Get any children and empty them */
- $children = $gallery->getChildren(null, true);
+ $children = $gallery->getChildren(null, null, true);
foreach ($children as $child) {
$this->emptyGallery($child);
$child->setTags(array());
/* See if we need to clear the has_subgalleries field */
if ($parent instanceof Ansel_Gallery) {
- if (!$parent->countChildren(Horde_Perms::SHOW, false)) {
+ if (!$parent->countChildren($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, false)) {
$parent->set('has_subgalleries', 0, true);
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $parent->id);
* @param array $params Optional parameters:
* <pre>
* (integer)perm The permissions filter to use [Horde_Perms::SHOW]
- * (mixed)filter Restrict the galleries returned to those matching
+ * (mixed)attributes Restrict the galleries returned to those matching
* the filters. Can be an array of attribute/values
* pairs or a gallery owner username.
* (integer)parent The parent share to start listing at.
- * (boolean)allLevels If set, return all levels below parent, not just
+ * (boolean)all_levels If set, return all levels below parent, not just
* direct children [TRUE]
* (integer)from The gallery to start listing at.
* (integer)count The number of galleries to return.
*/
public function listGalleries($params = array())
{
- $params = new Horde_Support_Array($params);
-
try {
- $shares = $this->_shares->listShares(
- $GLOBALS['registry']->getAuth(),
- $params->get('perm', Horde_Perms::SHOW),
- $params->get('filter', null),
- $params->get('from', 0),
- $params->get('count', 0),
- $params->get('sort_by', null),
- $params->get('direction', Ansel::SORT_ASCENDING),
- $params->get('parent', null),
- $params->get('allLevels', true));
+ $shares = $this->_shares->listShares($GLOBALS['registry']->getAuth(), $params);
} catch (Horde_Share_Exception $e) {
throw new Ansel_Exception($e);
}
*/
public function getRandomGallery($params = array())
{
- $params = new Horde_Support_Array($params);
$galleries = $this->listGalleries($params);
if (!$galleries) {
return false;
}
-
$gallery_key = array_rand($galleries);
+
return $galleries[$gallery_key];
}
public function getRecentImagesGeodata($user = null, $start = 0, $count = 8)
{
$galleries = $this->listGalleries(array('perm' => Horde_Perms::EDIT,
- 'filter' => $user));
+ 'attributes' => $user));
if (empty($galleries)) {
return array();
}
} else {
$this->_galleryList = $ansel_storage->listGalleries(
array('perm' => Horde_Perms::SHOW,
- 'filter' => $filter,
- 'allLevels' => false,
+ 'attributes' => $filter,
+ 'all_levels' => false,
'from' => $this->_page * $this->_g_perPage,
'count' => $this->_g_perPage,
'sort_by' => $this->_sortBy,
try {
$galleries = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')
->create()
- ->listGalleries(array('filter' => $owner));
+ ->listGalleries(array('attributes' => $owner));
} catch (Ansel_Exception $e) {
Horde::logMessage($e, 'ERR');
return '';
try {
$share = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->getGallery(Horde_Util::getFormData('cid'));
$form = 'edit.inc';
- $perm = &$share->getPermission();
- } catch (Horde_Share_Exception $e) {
+ $perm = $share->getPermission();
+ } catch (Horde_Exception_NotFound $e) {
if (($share_name = Horde_Util::getFormData('share')) !== null) {
try {
$share = $GLOBALS['injector']->getInstance('Ansel_Injector_Factory_Storage')->create()->shares->getShare($share_name);
$shares = $GLOBALS['injector']
->getInstance('Ansel_Injector_Factory_Storage')
->create()
- ->listGalleries(array('filter' => $id));
+ ->listGalleries(array('attributes' => $id));
foreach ($shares as $gallery) {
if ($gallery->isOldEnough() && !$gallery->hasPasswd()) {
$galleries[] = $gallery->id;
if ($num_galleries < 5) {
$mini_galleries = $GLOBALS['injector']->
getInstance('Ansel_Injector_Factory_Storage')->
- create()->listGalleries(array('filter' => $group, 'allLevels' => false));
+ create()->listGalleries(array('attributes' => $group, 'all_levels' => false));
} else {
$mini_galleries = $GLOBALS['injector']
->getInstance('Ansel_Injector_Factory_Storage')
->create()
- ->listGalleries(array('filter' => $group,
+ ->listGalleries(array('attributes' => $group,
'from' => rand(0, $num_galleries - 4),
'count' => 4));
}
// Delete groups
if ($GLOBALS['conf']['friends']) {
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
- $groups = $shares->listShares($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, true);
+ $groups = $shares->listShares($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::SHOW));
foreach ($groups as $share) {
$result = $shares->removeShare($share);
if ($result instanceof PEAR_Error) {
protected function _getGroups()
{
$GLOBALS['folks_shares'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
- $groups = $GLOBALS['folks_shares']->listShares($this->_user, Horde_Perms::READ);
+ $groups = $GLOBALS['folks_shares']->listShares($this->_user, array('perm' => Horde_Perms::READ));
$list = array();
foreach ($groups as $group) {
$actionID = Horde_Util::getFormData('actionID', 'edit');
switch ($actionID) {
case 'edit':
- $share = &$shares->getShareById(Horde_Util::getFormData('cid'));
- if (!is_a($share, 'PEAR_Error')) {
- $perm = &$share->getPermission();
- } elseif (($category = Horde_Util::getFormData('share')) !== null) {
- $share = &$shares->getShare($category);
- if (!is_a($share, 'PEAR_Error')) {
- $perm = &$share->getPermission();
+ try {
+ $share = $shares->getShareById(Horde_Util::getFormData('cid'));
+ $perm = $share->getPermission();
+ } catch (Horde_Exception_NotFound $e) {
+ if (($category = Horde_Util::getFormData('share')) !== null) {
+ $share = $shares->getShare($category);
+ $perm = $share->getPermission();
}
}
- if (is_a($share, 'PEAR_Error')) {
- $notification->push($share, 'horde.error');
- } elseif (!$GLOBALS['registry']->getAuth() ||
- (isset($share) && $GLOBALS['registry']->getAuth() != $share->get('owner'))) {
+ if (!$GLOBALS['registry']->getAuth() ||
+ (isset($share) && $GLOBALS['registry']->getAuth() != $share->get('owner'))) {
exit('permission denied');
}
break;
case 'editform':
- $share = &$shares->getShareById(Horde_Util::getFormData('cid'));
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $shares->getShareById(Horde_Util::getFormData('cid'));
+ } catch (Horde_Exception_NotFound $e) {
$notification->push(_("Attempt to edit a non-existent share."), 'horde.error');
- } else {
+ }
+ if ($share) {
if (!$GLOBALS['registry']->getAuth() ||
$GLOBALS['registry']->getAuth() != $share->get('owner')) {
exit('permission denied');
}
- $perm = &$share->getPermission();
+ $perm = $share->getPermission();
// Process owner and owner permissions.
$old_owner = $share->get('owner');
if (!class_exists($class)) {
throw new Horde_Exception(sprintf(Horde_Core_Translation::t("\"%s\" share driver not found."), $driver));
}
-
- $ob = new $class($app, $this->_injector->getInstance('Horde_Perms'));
+ $sob = new $class($app, $GLOBALS['registry']->getAuth(), $this->_injector->getInstance('Horde_Perms'), $this->_injector->getInstance('Horde_Group'));
+ $ob = new Horde_Core_Share_Driver($sob);
}
if (!empty($GLOBALS['conf']['share']['cache'])) {
--- /dev/null
+<?php
+/**
+ * Horde specific wrapper for Horde_Share drivers. Adds serializable interface,
+ * Horde hook calls etc...
+ *
+ * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you did
+ * not receive this file, see http://opensource.org/licenses/lgpl-2.1.php
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @license http://opensource.org/licenses/lgpl-2.1.php LGPL
+ * @package Core
+ */
+class Horde_Core_Share_Driver implements Serializable
+{
+ /** Serializable version **/
+ const VERSION = 1;
+
+ /**
+ * The composed Horde_Share driver
+ *
+ * @var Horde_Share
+ */
+ protected $_share;
+
+ /**
+ * Maps the concrete share class to the required storage adapter.
+ *
+ * @var array
+ */
+ protected $_storageMap = array(
+ 'Horde_Share_Sql' => 'Horde_Db_Adapter',
+ 'Horde_Share_Sql_Hierarchical' => 'Horde_Db_Adapter',
+ 'Horde_Share_Kolab' => 'Horde_Kolab_Storage');
+
+ /**
+ */
+ public function __construct(Horde_Share $share)
+ {
+ $this->_share = $share;
+ $this->_share->setStorage($GLOBALS['injector']->getInstance($this->_storageMap[get_class($this->_share)]));
+ $this->_share->addCallback('add', array($this, 'shareAddCallback'));
+ $this->_share->addCallback('modify', array($this, 'shareModifyCallback'));
+ $this->_share->addCallback('remove', array($this, 'shareRemoveCallback'));
+ $this->_share->addCallback('list', array($this, 'shareListCallback'));
+
+ try {
+ Horde::callHook('share_init', array($this, $this->_share->getApp()));
+ } catch (Horde_Exception_HookNotSet $e) {}
+ }
+
+ /**
+ * Delegate method calls to the composed share object.
+ *
+ * @param string $method The method name
+ * @param array $args The method arguments
+ *
+ * @return mixed The result of the method call
+ */
+ public function __call($method, $args)
+ {
+ return call_user_func_array(array($this->_share, $method), $args);
+ }
+
+ /**
+ * Serializes the object.
+ *
+ * @return string The serialized object.
+ */
+ public function serialize()
+ {
+ $data = array(
+ self::VERSION,
+ $this->_share);
+
+ return serialize($data);
+ }
+
+ /**
+ * Reconstructs object from serialized properties.
+ *
+ * @param <type> $serialized
+ */
+ public function unserialize($data)
+ {
+ // Rebuild the object
+ $data = @unserialize($data);
+ if (!is_array($data) ||
+ !isset($data[0]) ||
+ ($data[0] != self::VERSION)) {
+ throw new Exception('Cache version change');
+ }
+ $this->_share = $data[1];
+
+ // Set the storage adapter.
+ $this->_share->setStorage($GLOBALS['injector']->getInstance($this->_storageMap[get_class($this->_share)]));
+
+ // Call the init hook
+ try {
+ Horde::callHook('share_init', array($this, $this->_share->getApp()));
+ } catch (Horde_Exception_HookNotSet $e) {}
+ }
+
+ /**
+ * Lock an item belonging to a share, or an entire share itself.
+ *
+ * @param Horde_Lock $locks The lock object
+ * @param Horde_Share_Object $share The share 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_Prior($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_Prior($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);
+ }
+ }
+
+ /**
+ * Removes the lock for a lock ID.
+ *
+ * @param Horde_Lock $locks The lock object
+ * @param string $lockid The lock ID as generated by a previous call
+ * to lock().
+ *
+ * @return boolean
+ */
+ public function unlock(Horde_Lock $locks, $lockid)
+ {
+ return $locks->clearLock($lockid);
+ }
+
+ /**
+ * 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::logMessage($e, 'ERR');
+ throw new Horde_Exception_Prior($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::logMessage($e, 'ERR');
+ throw new Horde_Exception($e->getMessage());
+ }
+ } else {
+ $locktargettype = 'share';
+ }
+
+ if (empty($result)) {
+ return array();
+ }
+
+ return array('type' => $locktargettype,
+ 'lock' => reset($result));
+ }
+
+ /**
+ * share_list callback
+ *
+ * @param string $userid The userid listShares was called with
+ * @param array $shares The result of the listShares() call
+ * @param array $params The params that listShares() was called with
+ *
+ * @return array An array of share objects
+ */
+ public function shareListCallback($userid, $shares, $params = array())
+ {
+ try {
+ $params = new Horde_Support_Array($params);
+ return Horde::callHook('share_list', array($userid, $params['perm'], $params['attributes'], $shares));
+ } catch (Horde_Exception_HookNotSet $e) {}
+
+ return $shares;
+ }
+
+ /**
+ * Adds the share_add hook before delegating to the share object.
+ *
+ * @param Horde_Share_Object The share object being added
+ */
+ public function shareAddCallback(Horde_Share_Object $share)
+ {
+ try {
+ Horde::callHook('share_add', array($share));
+ } catch (Horde_Exception_HookNotSet $e) {}
+ }
+
+ /**
+ * Calls the share_remove hook before delegating to the share object.
+ *
+ * @see Horde_Share::removeShare
+ */
+ public function shareRemoveCallback(Horde_Share_Object $share)
+ {
+ try {
+ Horde::callHook('share_remove', array($share));
+ } catch (Horde_Exception_HookNotSet $e) {}
+ }
+
+ public function shareModifyCallback(Horde_Share_Object $share)
+ {
+ try {
+ Horde::callHook('share_modify', array($this));
+ } catch (Horde_Exception_HookNotSet $e) {}
+ }
+
+}
\ No newline at end of file
<email>slusarz@horde.org</email>
<active>yes</active>
</developer>
- <date>2010-10-25</date>
- <time>14:04:39</time>
+ <date>2010-11-04</date>
+ <time>01:53:57</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
<file name="Identity.php" role="php" />
<file name="Ui.php" role="php" />
</dir> <!-- /lib/Horde/Core/Prefs -->
+ <dir name="Share">
+ <file name="Driver.php" role="php" />
+ </dir> <!-- /lib/Horde/Core/Share -->
<dir name="Text">
<dir name="Filter">
<file name="Bbcode.php" role="php" />
<file name="AllTests.php" role="test" />
<file name="Autoload.php" role="test" />
<file name="phpunit.xml" role="test" />
- <file name="url.phpt" role="test" />
+ <file name="UrlTest.php" role="test" />
</dir> <!-- /test/Horde/Core -->
</dir> <!-- /test/Horde -->
</dir> <!-- /test -->
<install as="Horde/Core/Prefs/Ui.php" name="lib/Horde/Core/Prefs/Ui.php" />
<install as="Horde/Core/Prefs/Storage/Session.php" name="lib/Horde/Core/Prefs/Storage/Session.php" />
<install as="Horde/Core/Prefs/Ui/Widgets.php" name="lib/Horde/Core/Prefs/Ui/Widgets.php" />
+ <install as="Horde/Core/Share/Driver.php" name="lib/Horde/Core/Share/Driver.php" />
<install as="Horde/Core/Text/Filter/Bbcode.php" name="lib/Horde/Core/Text/Filter/Bbcode.php" />
<install as="Horde/Core/Text/Filter/Emails.php" name="lib/Horde/Core/Text/Filter/Emails.php" />
<install as="Horde/Core/Text/Filter/Emoticons.php" name="lib/Horde/Core/Text/Filter/Emoticons.php" />
<install as="Horde/Core/AllTests.php" name="test/Horde/Core/AllTests.php" />
<install as="Horde/Core/Autoload.php" name="test/Horde/Core/Autoload.php" />
<install as="Horde/Core/phpunit.xml" name="test/Horde/Core/phpunit.xml" />
- <install as="Horde/Core/url.phpt" name="test/Horde/Core/url.phpt" />
+ <install as="Horde/Core/UrlTest.php" name="test/Horde/Core/UrlTest.php" />
<install as="Horde/Core/Factory/KolabServerTest.php" name="test/Horde/Core/Factory/KolabServerTest.php" />
<install as="Horde/Core/Factory/KolabSessionTest.php" name="test/Horde/Core/Factory/KolabSessionTest.php" />
</filelist>
<release>beta</release>
<api>beta</api>
</stability>
- <date>2010-10-25</date>
+ <date>2010-11-04</date>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
* Add Horde_Session.
if (empty($contact_shares)) {
$scope = $GLOBALS['registry']->hasInterface('contacts');
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
- $this->_contact_shares = $shares->listShares($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, $GLOBALS['registry']->getAuth());
+ $this->_contact_shares = $shares->listShares($GLOBALS['registry']->getAuth(),
+ array('perm' => Horde_Perms::SHOW, 'attributes' => $GLOBALS['registry']->getAuth()));
}
// Contruct a list of owner ids to use
foreach ($this->_contact_shares as $id => $share) {
*
* @return mixed Array describing any shares added or removed | PEAR_Error.
*/
- function synchShares(&$share_obj, $serverInfo)
+ function synchShares($share_obj, $serverInfo)
{
$found_shares = array();
$return = array('added' => array(), 'removed' => array());
}
}
- $shares = &$share_obj->listShares($GLOBALS['registry']->getAuth());
+ $shares = $share_obj->listShares($GLOBALS['registry']->getAuth());
// A share for each IMSP adress book we can see.
foreach ($abooks as $abook_uid) {
$found = false;
}
// Now prune any shares that no longer exist on the IMSP server.
- $existing = $share_obj->listShares($GLOBALS['registry']->getAuth(), Horde_Perms::READ);
+ $existing = $share_obj->listShares($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::READ));
foreach ($existing as $key => $share) {
$temp = unserialize($share->get('params'));
if (is_array($temp)) {
*
* @return mixed True | PEAR_Error
*/
- function _createShare(&$share_obj, $params, $shareparams)
+ function _createShare($share_obj, $params, $shareparams)
{
- $share = &$share_obj->newShare($params['uid']);
+ $share = $share_obj->newShare($GLOBALS['registry']->getAuth(), $params['uid']);
if (is_a($share, 'PEAR_Error')) {
return $share;
}
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jan Schneider <jan@horde.org>
* @author Gunnar Wrobel <wrobel@pardus.de>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Horde_Share
*/
class Horde_Share
protected $_permsObject;
/**
- * Constructor.
+ * The current user
*
- * @param string $app The application that the shares belong
- * to.
- * @param Horde_Perms $perms The permissions object
+ * @var string
*/
- public function __construct($app, Horde_Perms $perms)
- {
- $this->_app = $app;
- $this->_permsObject = $perms;
- $this->__wakeup();
- }
+ protected $_user;
/**
- * Initializes the object.
+ * The Horde_Group driver
*
- * @throws Horde_Exception
+ * @var Horde_Group
*/
- public function __wakeup()
+ protected $_groups;
+
+ /**
+ * Configured callbacks. We currently support:
+ *<pre>
+ * add - Called immediately before a new share is added. Receives the
+ * share object as a parameter.
+ * modify - Called immediately before a share object's changes are saved
+ * to storage. Receives the share object as a parameter.
+ * remove - Called immediately before a share is removed from storage.
+ * Receives the share object as a parameter.
+ * list - Called immediately after a list of shares is received from
+ * storage. Passed the userid, share list, and any parameters
+ * passed to the listShare call. Should return the (possibly
+ * modified) share list. @see Horde_Share::listShares() for more
+ * info.
+ *</pre>
+ *
+ * @var array
+ */
+ protected $_callbacks;
+
+ /**
+ * Constructor.
+ *
+ * @param string $app The application that the shares belong to
+ * @param string $user The current user
+ * @param Horde_Perms $perms The permissions object
+ * @param Horde_Group $groups The Horde_Group object
+ *
+ */
+ public function __construct($app, $user, Horde_Perms $perms, Horde_Group $groups)
{
- try {
- Horde::callHook('share_init', array($this, $this->_app));
- } catch (Horde_Exception_HookNotSet $e) {}
+ $this->_app = $app;
+ $this->_user = $user;
+ $this->_permsObject = $perms;
+ $this->_groups = $groups;
}
/**
- * Returns the properties that need to be serialized.
- *
- * @return array List of serializable properties.
+ * (re)connect the share object to this share driver. Userful for when
+ * share objects are unserialized from a cache separate from the share
+ * driver.
+ *
+ * @param Horde_Share_Object $object
*/
- public function __sleep()
+ public function initShareObject($object)
{
- $properties = get_object_vars($this);
- unset($properties['_sortList']);
- $properties = array_keys($properties);
- return $properties;
+ // noop
}
/**
/**
* Returns an array of all shares that $userid has access to.
*
- * @param string $userid The userid of the user to check access for.
- * @param integer $perm The level of permissions required.
- * @param mixed $attributes Restrict the shares counted to those
- * matching $attributes. An array of
- * attribute/values pairs or a share owner
- * username.
+ * @param string $userid The userid of the user to check access for.
+ * @param array $params Additional parameters for the search.
+ *<pre>
+ * 'perm' Require this level of permissions. Horde_Perms constant.
+ * 'attribtues' Restrict shares to these attributes. A hash or username.
+ * 'from' Offset. Start at this share
+ * 'count' Limit. Only return this many.
+ * 'sort_by' Sort by attribute.
+ * 'direction' Sort by direction.
+ *</pre>
*
* @return array The shares the user has access to.
*/
- public function listShares($userid, $perm = Horde_Perms::SHOW, $attributes = null,
- $from = 0, $count = 0, $sort_by = null, $direction = 0)
+ public function listShares($userid, $params = array())
{
- $shares = $this->_listShares($userid, $perm, $attributes, $from,
- $count, $sort_by, $direction);
+ $params = array_merge(array('perm' => Horde_Perms::SHOW,
+ 'attributes' => null,
+ 'from' => 0,
+ 'count' => 0,
+ 'sort_by' => null,
+ 'direction' => 0),
+ $params);
+
+ $shares = $this->_listShares($userid, $params);
if (!count($shares)) {
return $shares;
}
$this->_sortList = null;
}
- try {
- return Horde::callHook('share_list', array($userid, $perm, $attributes, $shares));
- } catch (Horde_Exception_HookNotSet $e) {}
+ // Run the results through the callback, if configured.
+ if (!empty($this->_callbacks['list'])) {
+ return call_user_func_array($this->_callbacks['list'], array($userid, $shares, $params));
+ }
return $shares;
}
/**
* Returns a new share object.
*
+ * @param string $owner The share owner name.
* @param string $name The share's name.
*
* @return Horde_Share_Object A new share object.
* @throws Horde_Share_Exception
*/
- public function newShare($name)
+ public function newShare($owner, $name)
{
if (empty($name)) {
throw new Horde_Share_Exception('Share names must be non-empty');
}
$share = $this->_newShare($name);
- $share->setShareOb($this);
- $share->set('owner', $GLOBALS['registry']->getAuth());
+ $this->initShareObject($share);
+ $share->set('owner', $owner);
return $share;
}
*/
public function addShare(Horde_Share_Object $share)
{
- try {
- Horde::callHook('share_add', array($share));
- } catch (Horde_Exception_HookNotSet $e) {}
+ // Run the results through the callback, if configured.
+ if (!empty($this->_callbacks['add'])) {
+ call_user_func($this->_callbacks['add'], $share);
+ }
$result = $this->_addShare($share);
*/
public function removeShare(Horde_Share_Object $share)
{
- try {
- Horde::callHook('share_remove', array($share));
- } catch (Horde_Exception_HookNotSet $e) {}
+ // Run the results through the callback, if configured.
+ if (!empty($this->_callbacks['remove'])) {
+ return call_user_func($this->_callbacks['remove'], $share);
+ }
/* Remove share from the caches. */
$id = $share->getId();
{
// noop
}
-
+
+ /**
+ * Add a callback to the collection
+ *
+ * @param string $type
+ * @param array $callback
+ */
+ public function addCallback($type, $callback)
+ {
+ $this->_callbacks[$type] = $callback;
+ }
+
+ /**
+ * Give public access to call the share callbacks. Needed to run the
+ * callbacks from the Horde_Share_Object objects.
+ *
+ * @param string $type The callback to run
+ * @param array $params The parameters to pass to the callback.
+ *
+ * @return mixed
+ */
+ public function runCallback($type, $params)
+ {
+ if (!empty($this->_callbacks[$type])) {
+ return call_user_func_array($this->_callbacks[$type], $params);
+ }
+ }
+
/**
* Utility function to be used with uasort() for sorting arrays of
* Horde_Share objects.
*
* @param Horde_Share_Object_datatree $share The new share object.
*/
- protected function _addShare(&$share)
+ protected function _addShare($share)
{
return $this->_datatree->add($share->datatreeObject);
}
*
* @param Horde_Share_Object_datatree $share The share to remove.
*/
- protected function _removeShare(&$share)
+ protected function _removeShare($share)
{
return $this->_datatree->remove($share->datatreeObject);
}
*/
class Horde_Share_kolab extends Horde_Share
{
+ const VERSION = 1;
+
/**
* Our Kolab folder list handler
*
*/
protected $_session;
- /**
- * Initializes the object.
- *
- * @throws Horde_Exception
- */
- public function __wakeup()
- {
- if (empty($GLOBALS['conf']['kolab']['enabled'])) {
- throw new Horde_Exception('You must enable the kolab settings to use the Kolab Share driver.');
- }
-
- $this->_type = $this->_getFolderType($this->_app);
- if ($this->_type instanceof PEAR_Error) {
- return $this->_type;
- }
-
- $this->_list = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
-
- parent::__wakeup();
- }
private function _getFolderType($app)
{
}
}
+// /**
+// * Returns the properties that need to be serialized.
+// *
+// * @return array List of serializable properties.
+// */
+// public function __sleep()
+// {
+// $properties = get_object_vars($this);
+// unset($properties['_sortList'], $properties['_list']);
+// $properties = array_keys($properties);
+// return $properties;
+// }
+// /**
+// * Initializes the object.
+// *
+// * @throws Horde_Exception
+// */
+// public function __wakeup()
+// {
+// if (empty($GLOBALS['conf']['kolab']['enabled'])) {
+// throw new Horde_Exception('You must enable the kolab settings to use the Kolab Share driver.');
+// }
+// $this->_type = $this->_getFolderType($this->_app);
+// $this->_list = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
+//
+// parent::__wakeup();
+// }
+
+ /**
+ * Serialize the object. You *MUST* call setStorage() after unserialized.
+ *
+ * @return string
+ */
+ public function serialize()
+ {
+ $data = array(
+ self::VERSION,
+ $this->_app,
+ $this->_root,
+ $this->_cache,
+ $this->_shareMap,
+ $this->_listcache,
+ $this->_shareObject,
+ $this->_permsObject,
+ $this->_type,
+ $this->_listCacheValidity,
+ $this->_session);
+
+ return serialize($data);
+ }
+
+ /**
+ * Reconstruct object from serialized data. You MUST call setStorage()
+ * after unserialize.
+ *
+ * @param <type> $data
+ */
+ public function unserialize($data)
+ {
+ // Rebuild the object
+ $data = @unserialize($data);
+ if (!is_array($data) ||
+ !isset($data[0]) ||
+ ($data[0] != self::VERSION)) {
+ throw new Exception('Cache version change');
+ }
+ $this->_app = $data[1];
+ $this->_root = $data[2];
+ $this->_cache = $data[3];
+ $this->_shareMap = $data[4];
+ $this->_listcache = $data[5];
+ $this->_shareObject = $data[6];
+ $this->_permsObject = $data [7];
+ $this->_type = $data[8];
+ $this->_listCacheValidity = $data[9];
+ $this->_session = $data[10];
+
+ foreach (array_keys($this->_cache) as $name) {
+ $this->_initShareObject($this->_cache[$name]);
+ }
+ }
+
+ /**
+ * (re)connect the share object to this share driver. Userful for when
+ * share objects are unserialized from a cache separate from the share
+ * driver.
+ *
+ * @param Horde_Share_Object $object
+ */
+ public function initShareObject($object)
+ {
+ $object->setShareOb($this);
+ }
+
/**
- * Returns the properties that need to be serialized.
+ * Set the kolab storage backend.
*
- * @return array List of serializable properties.
+ * @param Horde_Kolab_Storage $driver
*/
- public function __sleep()
+ public function setStorage(Horde_Kolab_Storage $driver)
+ {
+ $this->_list = $driver;
+ }
+
+ public function getStorage()
{
- $properties = get_object_vars($this);
- unset($properties['_sortList'], $properties['_list']);
- $properties = array_keys($properties);
- return $properties;
+ return $this->_list;
}
/**
* Returns an array of all shares that $userid has access to.
*
* @param string $userid The userid of the user to check access for.
- * @param integer $perm The level of permissions required.
- * @param mixed $attributes Restrict the shares counted to those
- * matching $attributes. An array of
- * attribute/values pairs or a share owner
- * username.
+ * @param array $params @see Horde_Share::listShares
*
* @return array The shares the user has access to.
*/
- protected function _listShares($userid, $perm = Horde_Perms::SHOW,
- $attributes = null, $from = 0, $count = 0,
- $sort_by = null, $direction = 0)
+ protected function _listShares($userid, $params = array())
{
- $key = serialize(array($this->_type, $userid, $perm, $attributes));
+ $key = serialize(array($this->_type, $userid, $params['perm'], $params['attributes']));
if ($this->_list === false) {
$this->_listCache[$key] = array();
} else if (empty($this->_listCache[$key])
$shares = array();
foreach ($sharelist as $folder) {
$id = $folder->getShareId();
- $share = &$this->getShare($id);
+ $share = $this->getShare($id);
$keep = true;
- if (!$share->hasPermission($userid, $perm)) {
+ if (!$share->hasPermission($userid, $params['perm'])) {
$keep = false;
}
- if (isset($attributes) && $keep) {
- if (is_array($attributes)) {
- foreach ($attributes as $key => $value) {
+ if (isset($params['attributes']) && $keep) {
+ if (is_array($params['attributes'])) {
+ foreach ($params['attributes'] as $key => $value) {
if (!$share->get($key) == $value) {
$keep = false;
break;
}
}
- } elseif (!$share->get('owner') == $attributes) {
+ } elseif (!$share->get('owner') == $params['attributes']) {
$keep = false;
}
}
protected function _countShares($userid, $perm = Horde_Perms::SHOW,
$attributes = null)
{
- $shares = $this->_listShares($userid, $perm, $attributes);
+ $shares = $this->_listShares($userid, array('perm' => $perm, 'attributes' => $attributes));
return count($shares);
}
}
/** Okay, no default folder yet */
- $share = $this->newShare($GLOBALS['registry']->getAuth());
+ $share = $this->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth());
/** The value does not matter here as the share will rewrite it */
$share->set('name', '');
class Horde_Share_Object
{
/**
- * The Horde_Share object which this share came from - needed for updating
- * data in the backend to make changes stick, etc.
+ * The Horde_Share object which this share is associated with.
*
* @var Horde_Share
*/
protected $_shareOb;
/**
- * Returns the properties that need to be serialized.
+ * Associates a Share object with this share.
*
- * @return array List of serializable properties.
+ * @param Horde_Share $shareOb The Share object.
*/
- public function __sleep()
+ public function setShareOb(Horde_Share $shareOb)
{
- $properties = get_object_vars($this);
- unset($properties['_shareOb']);
- $properties = array_keys($properties);
- return $properties;
+ $this->_shareOb = $shareOb;
}
/**
- * Associates a Share object with this share.
+ * Sets any additional storage driver this object may need.
*
- * @param Horde_Share $shareOb The Share object.
+ * @param mixed $driver The storage driver.
*/
- public function setShareOb(Horde_Share $shareOb)
+ public function setStorage($driver)
{
- $this->_shareOb = $shareOb;
+ // Noop
}
/**
* @param string $attribute The attribute to set.
* @param mixed $value The value for $attribute.
*
- * @return mixed True if setting the attribute did succeed, a PEAR_Error
- * otherwise.
+ * @return boolean
*/
public function set($attribute, $value)
{
*/
public function save()
{
- try {
- Horde::callHook('share_modify', array($this));
- } catch (Horde_Exception_HookNotSet $e) {}
-
+ $this->_shareOb->runCallback('modify', array($this));
return $this->_save();
}
}
/**
- * Locks an item from this share, or the entire share if no item defined.
- *
- * @param Horde_Lock $locks The Horde_Lock object
- * @param string $item_uid A uid of an item from this share.
- *
- * @return mixed A lock ID on success, PEAR_Error on failure, 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
- * @throws Horde_Share_Exception
- */
- public function lock(Horde_Lock $locks, $item_uid = null)
- {
- $shareid = $this->getId();
-
- // Default parameters.
- $locktype = Horde_Lock::TYPE_EXCLUSIVE;
- $timeout = 600;
- $itemscope = $this->_shareOb->getApp() . ':' . $shareid;
-
- if (!empty($item_uid)) {
- // Check if the share is locked. Share locks are placed at app
- // scope.
- try {
- $result = $locks->getLocks($this->_shareOb->getApp(), $shareid, $locktype);
- } catch (Horde_Lock_Exception $e) {
- throw new Horde_Share_Exception($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, $item_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_Share_Exception($e);
- }
- if (!empty($result)) {
- // Lock found.
- return false;
- }
- // Try to place the share lock
- return $locks->setLock($GLOBALS['registry']->getAuth(), $this->_shareOb->getApp(),
- $shareid, $timeout, $locktype);
- }
- }
-
- /**
- * Removes the lock for a lock ID.
- *
- * @param Horde_Lock $locks The lock object
- * @param string $lockid The lock ID as generated by a previous call
- * to lock().
- *
- * @return mixed True on success, PEAR_Error on failure.
- */
- public function unlock(Horde_Lock $locks, $lockid)
- {
- return $locks->clearLock($lockid);
- }
-
- /**
- * Checks for existing locks.
+ * Returns the permission of this share.
*
- * 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 mixed 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, or a PEAR_Error on failure.
+ * @return Horde_Perms_Permission Permission object that represents the
+ * permissions on this share.
*/
- public function checkLocks(Horde_Lock $locks, $item_uid = null)
+ public function getPermission()
{
- $shareid = $this->getId();
- $locktype = Horde_Lock::TYPE_EXCLUSIVE;
-
- // Check for share locks
- try {
- $result = $locks->getLocks($this->_shareOb->getApp(), $shareid, $locktype);
- } catch (Horde_Lock_Exception $e) {
- Horde::logMessage($e, 'ERR');
- throw new Horde_Share_Exception($e);
- }
-
- if (empty($result) && !empty($item_uid)) {
- // Check for item locks
- $locktargettype = 'item';
- try {
- $result = $locks->getLocks($this->_shareOb->getApp() . ':' . $shareid, $item_uid, $locktype);
- } catch (Horde_Lock_Exception $e) {
- Horde::logMessage($e, 'ERR');
- throw new Horde_Share_Exception($e->getMessage());
- }
- } else {
- $locktargettype = 'share';
- }
-
- if (empty($result)) {
- return array();
- }
-
- return array('type' => $locktargettype,
- 'lock' => reset($result));
}
}
* @author Gunnar Wrobel <wrobel@pardus.de>
* @package Horde_Share
*/
-class Horde_Share_Object_Kolab extends Horde_Share_Object
+class Horde_Share_Object_Kolab extends Horde_Share_Object implements Serializable
{
+ /** Serializable version **/
+ const VERSION = 1;
+
/**
* The Kolab folder this share is based on.
*
protected $_list;
/**
- * The session handler.
- *
- * @var Horde_Kolab_Session
- */
- private $_session;
-
- /**
* Constructor.
*
* Sets the folder name.
*/
public function setShareOb($shareOb)
{
- /** Ignore the parent as we don't need it */
+ $this->_list = $shareOb->getStorage();
+ if (isset($this->_folder_name)) {
+ $this->_folder = $this->_list->getFolder($this->_folder_name);
+ }
+ }
+
+ public function serialize()
+ {
+ $data = array(
+ self::VERSION,
+ $this->_data,
+ $this->_folder_name
+ );
}
/**
- * Initializes the object.
+ * Unserialize object. You MUST call setShareOb() after unserializtion.
+ * @param <type> $data
*/
- public function __wakeup()
+ public function unserialize($data)
{
- $this->_list = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
- if (isset($this->_folder_name)) {
- $this->_folder = $this->_list->getFolder($this->_folder_name);
+ $data = @unserialize($data);
+ if (!is_array($data) ||
+ !isset($data[0]) ||
+ ($data[0] != self::VERSION)) {
+ throw new Exception('Cache version change');
}
+
+ $this->_data = $data[1];
+ $this->_folder_name = $data[2];
}
/**
- * Returns the properties that need to be serialized.
+ * Sets the kolab storage object.
*
- * @return array List of serializable properties.
+ * @param Horde_Kolab_Storage $driver
*/
- public function __sleep()
+ public function setStorage($driver)
{
- $properties = get_object_vars($this);
- unset($properties['_shareOb'], $properties['_list'],
- $properties['_folder']);
- $properties = array_keys($properties);
- return $properties;
+ $this->_list = $driver;
}
/**
* the sql driver.
*
* @author Duck <duck@obala.net>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Horde_Share
*/
class Horde_Share_Object_Sql extends Horde_Share_Object
{
+ /** Serializable version **/
+ const VERSION = 1;
+
/**
* The actual storage object that holds the data.
*
* @TODO: Check visibility - should be protected/private
- * @var mixed
+ * @var array
*/
public $data = array();
}
/**
+ * Serialize this object. You *MUST* call setShareOb() after unserializing.
+ *
+ * @return string The serialized data.
+ */
+ public function serialize()
+ {
+ $data = array(
+ self::VERSION,
+ $data
+ );
+
+ return serialize($data);
+ }
+
+ /**
+ * Reconstruct the object from serialized data.
+ *
+ * You *MUST* call setShareOb() after unserializing.
+ *
+ * @param string $data The serialized data.
+ */
+ public function unserialize($data)
+ {
+ $data = @unserialize($data);
+ if (!is_array($data) ||
+ !isset($data[0]) ||
+ ($data[0] != self::VERSION)) {
+ throw new Exception('Cache version change');
+ }
+
+ $this->data = $data[1];
+ }
+
+ /**
* Sets an attribute value in this object.
*
* @param string $attribute The attribute to set.
* @param mixed $value The value for $attribute.
*
- * @return mixed True if setting the attribute did succeed, a PEAR_Error
- * otherwise.
+ * @return boolean
*/
public function _set($attribute, $value)
{
*/
protected function _save()
{
- $db = $this->_shareOb->getWriteDb();
+ $db = $this->_shareOb->getStorage();
$table = $this->_shareOb->getTable();
$fields = array();
$params = array();
+ // Build the parameter arrays for the sql statement.
foreach ($this->_shareOb->toDriverCharset($this->data) as $key => $value) {
if ($key != 'share_id' && $key != 'perm' && $key != 'share_flags') {
$fields[] = $key;
}
$params[] = $flags;
+ // Insert new share record, or update existing
if (empty($this->data['share_id'])) {
- $share_id = $db->nextId($table);
- if ($share_id instanceof PEAR_Error) {
- Horde::logMessage($share_id, 'ERR');
- throw new Horde_Share_Exception($share_id->getMessage());
+ $sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (?' . str_repeat(', ?', count($fields) - 1) . ')';
+ try {
+ $this->data['share_id'] = $db->insert($sql, $params);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Share_Exception($e);
}
-
- $this->data['share_id'] = $share_id;
- $fields[] = 'share_id';
- $params[] = $this->data['share_id'];
-
- $query = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (?' . str_repeat(', ?', count($fields) - 1) . ')';
} else {
- $query = 'UPDATE ' . $table . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE share_id = ?';
+ $sql = 'UPDATE ' . $table . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE share_id = ?';
$params[] = $this->data['share_id'];
+ try {
+ $db->update($sql, $params);
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Share_Exception($e);
+ }
}
- $stmt = $db->prepare($query, null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute($params);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- }
- $stmt->free();
// Update the share's user permissions
- $stmt = $db->prepare('DELETE FROM ' . $table . '_users WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($this->data['share_id']));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- }
- $stmt->free();
-
+ $db->delete('DELETE FROM ' . $table . '_users WHERE share_id = ?', array($this->data['share_id']));
if (!empty($this->data['perm']['users'])) {
$data = array();
foreach ($this->data['perm']['users'] as $user => $perm) {
- $stmt = $db->prepare('INSERT INTO ' . $table . '_users (share_id, user_uid, perm) VALUES (?, ?, ?)', null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($this->data['share_id'], $user, $perm));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- }
- $stmt->free();
+ $db->insert('INSERT INTO ' . $table . '_users (share_id, user_uid, perm) VALUES (?, ?, ?)', array($this->data['share_id'], $user, $perm));
}
}
// Update the share's group permissions
- $stmt = $db->prepare('DELETE FROM ' . $table . '_groups WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($this->data['share_id']));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- }
- $stmt->free();
-
+ $db->delete('DELETE FROM ' . $table . '_groups WHERE share_id = ?', array($this->data['share_id']));
if (!empty($this->data['perm']['groups'])) {
$data = array();
foreach ($this->data['perm']['groups'] as $group => $perm) {
- $stmt = $db->prepare('INSERT INTO ' . $table . '_groups (share_id, group_uid, perm) VALUES (?, ?, ?)', null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($this->data['share_id'], $group, $perm));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- }
- $stmt->free();
+ $db->insert('INSERT INTO ' . $table . '_groups (share_id, group_uid, perm) VALUES (?, ?, ?)', array($this->data['share_id'], $group, $perm));
}
}
* @param boolean $update Should the share be saved
* after this operation?
*
- * @TODO: Look at storing the Perm object itself, instead of the data
- * (Make it easier to inject the perm object instead of instantiating
- * it in the library).
- *
- * @return boolean True if no error occured, PEAR_Error otherwise
+ * @return boolean
*/
public function setPermission($perm, $update = true)
{
class Horde_Share_Object_Sql_Hierarchical extends Horde_Share_Object_Sql
{
/**
- * Constructor. This is here primarily to make calling the parent
- * constructor(s) from any subclasses cleaner.
+ * Constructor.
+ *
+ * @param array $data
*
- * @param unknown_type $data
* @return Horde_Share_Object_sql_hierarchical
*/
public function __construct($data)
parent::__construct($data);
}
- public function inheritPermissions()
- {
- throw new Horde_Share_Exception('Not implemented.');
- }
-
/**
* Return a count of the number of children this share has
*
- * @param integer $perm A Horde_Perms::* constant
+ * @param string $user The user to use for checking perms
+ * @param integer $perm A Horde_Perms::* constant
* @param boolean $allLevels Count grandchildren or just children
*
- * @return mixed The number of child shares || PEAR_Error
+ * @return integer The number of child shares
*/
- public function countChildren($perm = Horde_Perms::SHOW, $allLevels = true)
+ public function countChildren($user, $perm = Horde_Perms::SHOW, $allLevels = true)
{
- return $this->_shareOb->countShares($GLOBALS['registry']->getAuth(), $perm, null, $this, $allLevels);
+ return $this->_shareOb->countShares($user, $perm, null, $this, $allLevels);
}
/**
* Get all children of this share.
*
- * @param int $perm Horde_Perms::* constant. If NULL will return
+ * @param string $user The user to use for checking perms
+ * @param integer $perm Horde_Perms::* constant. If NULL will return
* all shares regardless of permissions.
* @param boolean $allLevels Return all levels.
*
- * @return mixed An array of Horde_Share_Object objects || PEAR_Error
+ * @return array An array of Horde_Share_Object objects
*/
- public function getChildren($perm = Horde_Perms::SHOW, $allLevels = true)
+ public function getChildren($user, $perm = Horde_Perms::SHOW, $allLevels = true)
{
- return $this->_shareOb->listShares($GLOBALS['registry']->getAuth(), $perm, null, 0, 0,
- null, 1, $this, $allLevels, is_null($perm));
-
+ return $this->_shareOb->listShares(
+ $user, array('perm' => $perm,
+ 'direction' => 1,
+ 'parent' => $this,
+ 'all_levels' => $allLevels,
+ 'ignore_perms' => is_null($perm)));
}
/**
* Returns a child's direct parent
*
- * @return mixed The direct parent Horde_Share_Object or PEAR_Error
+ * @return Horde_Share_Object The direct parent Horde_Share_Object
*/
public function getParent()
{
{
$parents = array();
$share = $this->getParent();
- while (is_a($share, 'Horde_Share_Object')) {
+ while ($share instanceof Horde_Share_Object) {
$parents[] = $share;
$share = $share->getParent();
}
+
return array_reverse($parents);
}
*
* @param mixed $parent A Horde_Share object or share id for the parent.
*
- * @return mixed true || PEAR_Error
+ * @return boolean
*/
public function setParent($parent)
{
if (!is_null($parent) && !is_a($parent, 'Horde_Share_Object')) {
$parent = $this->_shareOb->getShareById($parent);
- if ($parent instanceof PEAR_Error) {
- Horde::logMessage($parent, 'ERR');
- throw new Horde_Share_Exception($parent->getMessage());
- }
}
/* If we are an existing share, check for any children */
if ($this->getId()) {
- $children = $this->_shareOb->listShares(
- $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT, null, 0, 0, null, 0,
- $this->getId());
+ $children = $this->_shareOb->listShares(null,
+ array('perm' => Horde_Perms::EDIT,
+ 'parent' => $this,
+ 'all_levels' => true,
+ 'ignore_perms' => true));
} else {
$children = array();
}
$parent_string = null;
}
$this->data['share_parents'] = $parent_string;
- $query = $this->_shareOb->getWriteDb()->prepare('UPDATE ' . $this->_shareOb->getTable() . ' SET share_parents = ? WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
- $result = $query->execute(array($this->data['share_parents'], $this->getId()));
- $query->free();
- if ($result instanceof PEAR_Error) {
- throw new Horde_Share_Exception($result->getMessage());
+ $sql = 'UPDATE ' . $this->_shareOb->getTable() . ' SET share_parents = ? WHERE share_id = ?';
+ try {
+ $this->_shareOb->getStorage()->update($sql, array($this->data['share_parents'], $this->getId()));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Share_Exception($e->getMessage());
}
/* Now we can reset the children's parent */
* Returns the permission of this share.
*
* @return Horde_Perms_Permission Permission object that represents the
- * permissions on this share.
+ * permissions on this share.
*/
public function getPermission()
{
}
}
-
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Duck <duck@obala.net>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Horde_Share
*/
/**
* @package Horde_Share
*/
-class Horde_Share_Sql extends Horde_Share
+class Horde_Share_Sql extends Horde_Share implements Serializable
{
/* Share has user perms */
const SQL_FLAG_USERS = 1;
/* Share has group perms */
const SQL_FLAG_GROUPS = 2;
+ /* Serializable version */
+ const VERSION = 1;
+
/**
* Handle for the current database connection.
- * @TODO: port to Horde_Db
*
- * @var MDB2
+ * @var Horde_Db_Adapter
*/
protected $_db;
/**
- * Handle for the current database connection, used for writing. Defaults
- * to the same handle as $db if a separate write database is not required.
+ * Main share table for the current scope.
*
- * @var MDB2
+ * @var string
*/
- protected $_write_db;
+ protected $_table;
/**
- * SQL connection parameters
+ * The Horde_Share_Object subclass to instantiate objects as
+ *
+ * @var string
*/
- protected $_params = array();
+ protected $_shareObject = 'Horde_Share_Object_Sql';
/**
- * Main share table for the current scope.
*
- * @var string
+ * @see Horde_Share::__construct()
*/
- protected $_table;
+ public function __construct($app, $user, Horde_Perms $perms, Horde_Group $groups)
+ {
+ parent::__construct($app, $user, $perms, $groups);
+ $this->_table = $this->_app . '_shares';
+ }
/**
- * The Horde_Share_Object subclass to instantiate objects as
+ * Serializes the object. Includes all properties except _table (this can
+ * be determined by _app), and _db (which is injected when unserialized).
+ * Note that you MUST set the db adapter after unserializing, but calling
+ * the setDb() method.
*
- * @var string
+ * @return string The serialized object.
*/
- protected $_shareObject = 'Horde_Share_Object_Sql';
+ public function serialize()
+ {
+ $data = array(
+ self::VERSION,
+ $this->_app,
+ $this->_root,
+ $this->_cache,
+ $this->_shareMap,
+ $this->_listcache,
+ $this->_shareObject,
+ $this->_permsObject);
+
+ return serialize($data);
+ }
/**
- * Initializes the object.
+ * Reconstructs object from serialized properties.
+ * Note: You MUST set the db adapter via setDb() after unserializing this
+ * object.
+ *
+ * @param string $serialized
*/
- public function __wakeup()
+ public function unserialize($data)
{
+ $data = @unserialize($data);
+ if (!is_array($data) ||
+ !isset($data[0]) ||
+ ($data[0] != self::VERSION)) {
+ throw new Exception('Cache version change');
+ }
+
+ $this->_app = $data[1];
+ $this->_root = $data[2];
+ $this->_cache = $data[3];
+ $this->_shareMap = $data[4];
+ $this->_listcache = $data[5];
+ $this->_shareObject = $data[6];
+ $this->_permsObject = $data [7];
+
$this->_table = $this->_app . '_shares';
- $this->_connect();
foreach (array_keys($this->_cache) as $name) {
- $this->_cache[$name]->setShareOb($this);
+ $this->initShareObject($this->_cache[$name]);
}
-
- parent::__wakeup();
}
/**
- * Returns the properties that need to be serialized.
+ * (re)connect the share object to this share driver. Userful for when
+ * share objects are unserialized from a cache separate from the share
+ * driver.
*
- * @return array List of serializable properties.
+ * @param Horde_Share_Object $object
*/
- public function __sleep()
+ public function initShareObject($object)
{
- $properties = get_object_vars($this);
- unset($properties['_sortList'],
- $properties['_db'],
- $properties['_write_db']);
- return array_keys($properties);
+ $object->setShareOb($this);
}
/**
* Get storage table
+ *
+ * @return string
*/
public function getTable()
{
}
/**
- * Refetence to write db
+ *
+ * @return Horde_Db_Adapter_Base
*/
- public function getWriteDb()
- {
- return $this->_write_db;
- }
-
- public function getReadDb()
+ public function getStorage()
{
return $this->_db;
}
/**
* Finds out if the share has user set
+ * @TODO: fix method prefix or make protected
+ * @param boolean
*/
public function _hasUsers($share)
{
protected function _getShareUsers(&$share)
{
if ($this->_hasUsers($share)) {
- $stmt = $this->_db->prepare('SELECT user_uid, perm FROM ' . $this->_table . '_users WHERE share_id = ?');
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($share['share_id']));
- if ( $result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ try {
+ $rows = $this->_db->selectAll('SELECT user_uid, perm FROM ' . $this->_table . '_users WHERE share_id = ?', array($share['share_id']));
+ foreach ($rows as $row) {
$share['perm']['users'][$row['user_uid']] = (int)$row['perm'];
}
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
- $stmt->free();
- $result->free();
}
}
* Get groups permissions
*
* @param array $share Share data array
+ *
* @throws Horde_Share_Exception
*/
protected function _getShareGroups(&$share)
{
if ($this->_hasGroups($share)) {
- // Get groups permissions
- $stmt = $this->_db->prepare('SELECT group_uid, perm FROM ' . $this->_table . '_groups WHERE share_id = ?');
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($share['share_id']));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ try {
+ $rows = $this->_db->selectAll('SELECT group_uid, perm FROM ' . $this->_table . '_groups WHERE share_id = ?', array($share['share_id']));
+ foreach ($rows as $row) {
$share['perm']['groups'][$row['group_uid']] = (int)$row['perm'];
}
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
- $stmt->free();
- $result->free();
}
}
* @param string $name The name of the share to retrieve.
*
* @return Horde_Share_Object_sql The requested share.
+ * @throws Horde_Exception_NotFound
+ * @throws Horde_Share_Exception
*/
protected function _getShare($name)
{
- $stmt = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_name = ?');
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $results = $stmt->execute(array($name));
- if ($results instanceof PEAR_Error) {
- Horde::logMessage($results, 'ERR');
- throw new Horde_Share_Exception($results->getMessage());
- }
- $data = $results->fetchRow(MDB2_FETCHMODE_ASSOC);
- if ($data instanceof PEAR_Error) {
- Horde::logMessage($data, 'ERR');
- throw new Horde_Share_Exception($data->getMessage());
- } elseif (empty($data)) {
- throw new Horde_Share_Exception(sprintf(Horde_Share_Translation::t("Share \"%s\" does not exist."), $name));
- }
- $stmt->free();
- $results->free();
-
- // Convert charset
- $data = $this->_fromDriverCharset($data);
-
- // Populate the perms array
+ try {
+ $results = $this->_db->selectOne('SELECT * FROM ' . $this->_table . ' WHERE share_name = ?', array($name));
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ if (!$results) {
+ throw new Horde_Exception_NotFound();
+ }
+ $data = $this->_fromDriverCharset($results);
$this->_loadPermissions($data);
return new $this->_shareObject($data);
* Returns a Horde_Share_Object_sql object corresponding to the given
* unique ID, with the details retrieved appropriately.
*
- * @param integer $cid The id of the share to retrieve.
+ * @param integer $id The id of the share to retrieve.
*
* @return Horde_Share_Object_sql The requested share.
* @throws Horde_Share_Exception
*/
protected function _getShareById($id)
{
- $params = array($id);
- $stmt = $this->_db->prepare('SELECT * FROM ' . $this->_table . ' WHERE share_id = ?');
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $results = $stmt->execute($params);
- if ($results instanceof PEAR_Error) {
- Horde::logMessage($results, 'ERR');
- throw new Horde_Share_Exception($results->getMessage());
+ try {
+ $results = $this->_db->selectOne('SELECT * FROM ' . $this->_table . ' WHERE share_id = ?', array($id));
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
- $data = $results->fetchRow(MDB2_FETCHMODE_ASSOC);
- if ($data instanceof PEAR_Error) {
- Horde::logMessage($data, 'ERR');
- throw new Horde_Share_Exception($data->getMessage());
- } elseif (empty($data)) {
- throw new Horde_Share_Exception(sprintf(Horde_Share_Translation::t("Share ID %d does not exist."), $id));
+ if (!$results) {
+ throw new Horde_Exception_NotFound();
}
-
- $stmt->free();
- $results->free();
-
- // Convert charset
- $data = $this->_fromDriverCharset($data);
-
- // Get permissions
+ $data = $this->_fromDriverCharset($results);
$this->_loadPermissions($data);
return new $this->_shareObject($data);
* to the given set of unique IDs, with the details retrieved
* appropriately.
*
- * @param array $cids The array of ids to retrieve.
+ * @param array $ids The array of ids to retrieve.
*
* @return array The requested shares.
*/
protected function _getShares($ids)
{
$shares = array();
- $query = 'SELECT * FROM ' . $this->_table . ' WHERE share_id IN (' . implode(', ', $ids) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (empty($result)) {
- return array();
+ try {
+ $rows = $this->_db->selectAll('SELECT * FROM ' . $this->_table . ' WHERE share_id IN (' . str_repeat('?', count($ids) - 1) . '?) ', $ids);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
$groups = array();
$users = array();
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$shares[(int)$share['share_id']] = $this->_fromDriverCharset($share);
if ($this->_hasUsers($share)) {
$users[] = (int)$share['share_id'];
$groups[] = (int)$share['share_id'];
}
}
- $result->free();
- // Get users permissions
+ // Get users' permissions
if (!empty($users)) {
- $query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users '
- . ' WHERE share_id IN (' . implode(', ', $users) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll('SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users WHERE share_id IN (' . str_repeat('?', count($users) - 1) . '?) ', $users);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
}
}
- // Get groups permissions
+ // Get groups' permissions
if (!empty($groups)) {
- $query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups'
- . ' WHERE share_id IN (' . implode(', ', $groups) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll('SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups WHERE share_id IN (' . str_repeat('?', count($groups) - 1) . '?) ', $groups);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
}
}
}
/**
- * Lists *all* shares for the current app/share, regardless of
- * permissions.
+ * Lists *all* shares for the current app/share, regardless of permissions.
*
* This is for admin functionality and scripting tools, and shouldn't be
* called from user-level code!
}
/**
- * Lists *all* shares for the current app/share, regardless of
- * permissions.
+ * Lists *all* shares for the current app/share, regardless of permissions.
*
* @return array All shares for the current app/share.
+ * @throws Horde_Share_Exception
*/
protected function _listAllShares()
{
$shares = array();
- $query = 'SELECT * FROM ' . $this->_table . ' ORDER BY share_name ASC';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (empty($result)) {
- return array();
+
+ try {
+ $rows = $this->_db->selectAll('SELECT * FROM ' . $this->_table . ' ORDER BY share_name ASC');
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$shares[(int)$share['share_id']] = $this->_fromDriverCharset($share);
}
- $result->free();
-
+
// Get users permissions
- $query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- return $result;
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll('SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users');
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e);
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
}
// Get groups permissions
- $query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll('SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups');
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
}
$sharelist = array();
/**
* Returns an array of all shares that $userid has access to.
*
- * @param string $userid The userid of the user to check access for.
- * @param integer $perm The level of permissions required.
- * @param mixed $attributes Restrict the shares counted to those
- * matching $attributes. An array of
- * attribute/values pairs or a share owner
- * username.
+ * @param string $userid The userid of the user to check access for.
+ * @param array $params Additional parameters for the search.
+ *<pre>
+ * 'perm' Require this level of permissions. Horde_Perms constant.
+ * 'attribtues' Restrict shares to these attributes. A hash or username.
+ * 'from' Offset. Start at this share
+ * 'count' Limit. Only return this many.
+ * 'sort_by' Sort by attribute.
+ * 'direction' Sort by direction.
+ *</pre>
*
* @return array The shares the user has access to.
- * @throws Horde_Share_Exception
*/
- public function listShares($userid, $perm = Horde_Perms::SHOW, $attributes = null,
- $from = 0, $count = 0, $sort_by = null, $direction = 0)
+ public function listShares($userid, $params = array())
{
+ //var_dump($params);
+ $params = array_merge(array('perm' => Horde_Perms::SHOW,
+ 'attributes' => null,
+ 'from' => 0,
+ 'count' => 0,
+ 'sort_by' => null,
+ 'direction' => 0),
+ $params);
$shares = array();
- if (is_null($sort_by)) {
+ if (is_null($params['sort_by'])) {
$sortfield = 's.share_name';
- } elseif ($sort_by == 'owner' || $sort_by == 'id') {
- $sortfield = 's.share_' . $sort_by;
+ } elseif ($params['sort_by'] == 'owner' || $params['sort_by'] == 'id') {
+ $sortfield = 's.share_' . $params['sort_by'];
} else {
- $sortfield = 's.attribute_' . $sort_by;
+ $sortfield = 's.attribute_' . $params['sort_by'];
}
$query = 'SELECT DISTINCT s.* '
- . $this->getShareCriteria($userid, $perm, $attributes)
+ . $this->getShareCriteria($userid, $params['perm'], $params['attributes'])
. ' ORDER BY ' . $sortfield
- . (($direction == 0) ? ' ASC' : ' DESC');
- if ($from > 0 || $count > 0) {
- $this->_db->setLimit($count, $from);
- }
-
- // Fix field names for sqlite. MDB2 tries to handle this with
- // MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES, but it doesn't stick.
- if ($this->_db->phptype == 'sqlite') {
- $connection = $this->_db->getConnection();
- @sqlite_query('PRAGMA full_column_names=0', $connection);
- @sqlite_query('PRAGMA short_column_names=1', $connection);
- }
+ . (($params['direction'] == 0) ? ' ASC' : ' DESC');
+ $query = $this->_db->addLimitOffset($query, array('limit' => $params['count'], 'offset' => $params['from']));
Horde::logMessage(sprintf("SQL Query by Horde_Share_sql::listShares: %s", $query), 'DEBUG');
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (empty($result)) {
- return array();
+ try {
+ $rows = $this->_db->selectAll($query);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
-
$users = array();
$groups = array();
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$shares[(int)$share['share_id']] = $this->_fromDriverCharset($share);
if ($this->_hasUsers($share)) {
$users[] = (int)$share['share_id'];
$groups[] = (int)$share['share_id'];
}
}
- $result->free();
// Get users permissions
if (!empty($users)) {
$query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table
. '_users WHERE share_id IN (' . implode(', ', $users)
. ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll($query);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
}
}
$query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table
. '_groups WHERE share_id IN (' . implode(', ', $groups)
. ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
- }
- $result->free();
+ try {
+ $rows = $this->_db->selectAll($query);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
}
}
}
unset($shares);
- try {
- return Horde::callHook('share_list', array($userid, $perm, $attributes, $sharelist));
- } catch (Horde_Exception_HookNotSet $e) {}
+ // Run the results through the callback, if configured.
+ if (!empty($this->_callbacks['list'])) {
+ return call_user_func_array($this->_callbacks['list'], array($userid, $sharelist, $params));
+ }
return $sharelist;
}
*/
public function listSystemShares()
{
- // Fix field names for sqlite. MDB2 tries to handle this with
- // MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES, but it doesn't stick.
- if ($this->_db->phptype == 'sqlite') {
- $connection = $this->_db->getConnection();
- @sqlite_query('PRAGMA full_column_names=0', $connection);
- @sqlite_query('PRAGMA short_column_names=1', $connection);
- }
-
$query = 'SELECT * FROM ' . $this->_table . ' WHERE share_owner IS NULL';
Horde::logMessage('SQL Query by Horde_Share_sql::listSystemShares: ' . $query, 'DEBUG');
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());;
- } elseif (empty($result)) {
- return array();
+ try {
+ $rows = $this->_db->selectAll($query);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());;
}
$sharelist = array();
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$data = $this->_fromDriverCharset($share);
$this->_getSharePerms($data);
$sharelist[$data['share_name']] = new $this->_shareObject($data);
$sharelist[$data['share_name']]->setShareOb($this);
}
- $result->free();
return $sharelist;
}
$query = $this->getShareCriteria($userid, $perm, $attributes);
$query = 'SELECT COUNT(DISTINCT s.share_id) ' . $query;
Horde::logMessage(sprintf("SQL Query by Horde_Share_sql::_countShares: %s", $query), 'DEBUG');
- return $this->_db->queryOne($query);
+
+ return $this->_db->selectValue($query);
}
/**
* Returns a new share object.
*
- * @param string $name The share's name.
+ * @param string $name The share's name.
*
* @return Horde_Share_Object_sql A new share object.
*/
$tables = array($this->_table,
$this->_table . '_users',
$this->_table . '_groups');
- foreach ($tables as $table) {
-
- /* Remove the share entry */
- $stmt = $this->_write_db->prepare('DELETE FROM ' . $table . ' WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute($params);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
+ foreach ($tables as $table) {
+ try {
+ $this->_db->delete('DELETE FROM ' . $table . ' WHERE share_id = ?', $params);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
- $stmt->free();
}
return true;
* @throws Horde_Share_Exception
*/
protected function _exists($share)
- {
- $stmt = $this->_db->prepare('SELECT 1 FROM ' . $this->_table
- . ' WHERE share_name = ?');
-
- if ($stmt instanceof PEAR_Error) {
- Horde::logMessage($stmt, 'ERR');
- throw new Horde_Share_Exception($stmt->getMessage());
- }
- $result = $stmt->execute(array($share));
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
+ {
+ try {
+ return (boolean)$this->_db->selectOne('SELECT 1 FROM ' . $this->_table . ' WHERE share_name = ?', array($share));
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Share_Exception($e);
}
-
- $exists = (bool)$result->fetchOne();
- $stmt->free();
- $result->free();
-
- return $exists;
}
/**
* Returns an array of criteria for querying shares.
* @access protected
*
+ * @TODO: Horde_SQL:: stuff should be refactored/removed when it's ported
+ * to Horde_Db
* @param string $userid The userid of the user to check access for.
* @param integer $perm The level of permissions required.
* @param mixed $attributes Restrict the shares returned to those who
* @return string The criteria string for fetching this user's shares.
*/
public function getShareCriteria($userid, $perm = Horde_Perms::SHOW,
- $attributes = null)
+ $attributes = null)
{
$query = ' FROM ' . $this->_table . ' s ';
$where = '';
if (!empty($userid)) {
// (owner == $userid)
- $where .= 's.share_owner = ' . $this->_write_db->quote($userid);
+ $where .= 's.share_owner = ' . $this->_db->quote($userid);
// (name == perm_creator and val & $perm)
$where .= ' OR (' . Horde_SQL::buildClause($this->_db, 's.perm_creator', '&', $perm) . ')';
// (name == perm_users and key == $userid and val & $perm)
$query .= ' LEFT JOIN ' . $this->_table . '_users u ON u.share_id = s.share_id';
- $where .= ' OR ( u.user_uid = ' . $this->_write_db->quote($userid)
+ $where .= ' OR ( u.user_uid = ' . $this->_db->quote($userid)
. ' AND (' . Horde_SQL::buildClause($this->_db, 'u.perm', '&', $perm) . '))';
// If the user has any group memberships, check for those also.
// @TODO: Inject the group driver
try {
- $group = $GLOBALS['injector']->getInstance('Horde_Group');
- $groups = $group->getGroupMemberships($userid, true);
+ $groups = $this->_groups->getGroupMemberships($userid, true);
if ($groups) {
// (name == perm_groups and key in ($groups) and val & $perm)
$ids = array_keys($groups);
}
/**
- * Resets the current database name so that MDB2 is always selecting the
- * database before sending a query.
- *
- * @TODO: This needs to be public since it's used as a callback in MDB2.
- * Remove when refactored to use Horde_Db
- */
- public function _selectDB($db, $scope, $message, $is_manip = null)
- {
- if ($scope == 'query') {
- $db->connected_database_name = '';
- }
- }
-
- /**
* Set the SQL table name to use for the current scope's share storage.
*
* @var string $table The table name
$this->_table = $table;
}
- /**
- * Attempts to open a connection to the sql server.
- *
- * @return boolean True on success.
- * @throws Horde_Share_Exception
- */
- protected function _connect()
+ public function setStorage(Horde_Db_Adapter $db)
{
- $this->_params = $GLOBALS['conf']['sql'];
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the sql server using the supplied parameters. */
- $params = $this->_params;
- unset($params['charset']);
- $this->_write_db = &MDB2::factory($params);
- if ($this->_write_db instanceof PEAR_Error) {
- throw new Horde_Share_Exception($this->_write_db->getMessage());
- }
-
- /* Attach debug handler. */
- $this->_write_db->setOption('debug', true);
- $this->_write_db->setOption('debug_handler', array($this, '_selectDB'));
- $this->_write_db->setOption('seqcol_name', 'id');
-
- /* Set DB portability options. */
- switch ($this->_write_db->phptype) {
- case 'mssql':
- $this->_write_db->setOption('field_case', CASE_LOWER);
- $this->_write_db->setOption('portability', MDB2_PORTABILITY_FIX_CASE | MDB2_PORTABILITY_ERRORS | MDB2_PORTABILITY_RTRIM | MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES);
- break;
-
- default:
- switch ($this->_write_db->phptype) {
- case 'oci8':
- $this->_write_db->setOption('emulate_database', false);
- break;
-
- case 'pgsql':
- /* The debug handler breaks PostgreSQL. In most cases it
- * shouldn't be necessary, but this may mean we simply can't
- * support use of multiple Postgres databases right now. See
- * http://bugs.horde.org/ticket/7825 */
- $this->_write_db->setOption('debug', false);
- break;
- }
- $this->_write_db->setOption('field_case', CASE_LOWER);
- $this->_write_db->setOption('portability', MDB2_PORTABILITY_FIX_CASE | MDB2_PORTABILITY_ERRORS | MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES);
- }
-
- /* Check if we need to set up the read DB connection seperately. */
- if (!empty($this->_params['splitread'])) {
- $params = array_merge($params, $this->_params['read']);
- unset($params['charset']);
- $this->_db = &MDB2::singleton($params);
- if ($this->_db instanceof PEAR_Error) {
- throw new Horde_Share_Exception($this->_db);
- }
-
- $this->_db->setOption('seqcol_name', 'id');
- /* Set DB portability options. */
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('field_case', CASE_LOWER);
- $this->_db->setOption('portability', MDB2_PORTABILITY_FIX_CASE | MDB2_PORTABILITY_ERRORS | MDB2_PORTABILITY_RTRIM | MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES);
- break;
-
- default:
- switch ($this->_db->phptype) {
- case 'oci8':
- $this->_db->setOption('emulate_database', false);
- break;
-
- case 'pgsql':
- /* The debug handler breaks PostgreSQL. In most cases it
- * shouldn't be necessary, but this may mean we simply
- * can't support use of multiple Postgres databases right
- * now. See http://bugs.horde.org/ticket/7825 */
- $this->_write_db->setOption('debug', false);
- break;
- }
- $this->_db->setOption('field_case', CASE_LOWER);
- $this->_db->setOption('portability', MDB2_PORTABILITY_FIX_CASE | MDB2_PORTABILITY_ERRORS | MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES);
- }
- } else {
- /* Default to the same DB handle as the writer for reading too */
- $this->_db = $this->_write_db;
- }
-
- return true;
+ $this->_db = $db;
}
/**
foreach ($data as $key => $value) {
if (substr($key, 0, 9) == 'attribute') {
$data[$key] = Horde_String::convertCharset(
- $data[$key], $this->_params['charset'], 'UTF-8');
+ $data[$key], $this->_db->getOption('charset'), 'UTF-8');
}
}
foreach ($data as $key => $value) {
if (substr($key, 0, 9) == 'attribute') {
$data[$key] = Horde_String::convertCharset(
- $data[$key], 'UTF-8', $this->_params['charset']);
+ $data[$key], 'UTF-8', $this->_db->getOption('charset'));
}
}
* Override new share creation so we can allow for shares with empty
* share_names.
*
+ * @see Horde_Share::newShare
*/
- public function newShare($name = '')
+ public function newShare($owner, $name = '')
{
$share = $this->_newShare();
- $share->setShareOb($this);
- //@TODO: inject the Auth object
- $share->set('owner', $GLOBALS['registry']->getAuth());
+ $this->initShareObject($share);
+ $share->set('owner', $owner);
return $share;
}
/**
* Returns an array of all shares that $userid has access to.
*
- * @param string $userid The userid of the user to check access for.
- * @param integer $perm The level of permissions required.
- * @param mixed $attributes Restrict the shares counted to those
- * matching $attributes. An array of
- * attribute/values pairs or a share owner
- * username.
- * @param integer $from The share to start listing from.
- * @param integer $count The number of shares to return.
- * @param string $sort_by The field to sort by
- * @param integer $direction The sort direction
- * @param mixed $parent Either a share_id, Horde_Share_Object or null.
- * @param boolean $alllevels List all levels or just the direct children
- * of $parent?
+ * @param string $userid The userid of the user to check access for.
+ * @param array $params Additional parameters for the search.
+ *<pre>
+ * 'perm' Require this level of permissions. Horde_Perms constant.
+ * 'attribtues' Restrict shares to these attributes. A hash or username.
+ * 'from' Offset. Start at this share
+ * 'count' Limit. Only return this many.
+ * 'sort_by' Sort by attribute.
+ * 'direction' Sort by direction.
+ * 'parent' Start at this share in the hierarchy. Either share_id or
+ * Horde_Share_Object
+ * 'all_levels' List all levels or just the direct children of parent?
+ * 'ignore_perms' Don't check perms.
+ *</pre>
*
- * @return mixed The shares the user has access to
- * @throws Horde_Share_Exception
+ * @return array The shares the user has access to.
*/
- public function &listShares($userid, $perm = Horde_Perms::SHOW, $attributes = null,
- $from = 0, $count = 0, $sort_by = null,
- $direction = 0, $parent = null,
- $allLevels = true, $ignorePerms = false)
+ public function listShares($userid, $params = array())
{
+ $params = array_merge(array('perm' => Horde_Perms::SHOW,
+ 'attributes' => null,
+ 'from' => 0,
+ 'count' => 0,
+ 'sort_by' => null,
+ 'direction' => 0,
+ 'parent' => null,
+ 'all_levels' => true,
+ 'ignore_perms' => false),
+ $params);
$shares = array();
- if (is_null($sort_by)) {
+ if (is_null($params['sort_by'])) {
$sortfield = 's.share_id';
- } elseif ($sort_by == 'owner' || $sort_by == 'id') {
- $sortfield = 's.share_' . $sort_by;
+ } elseif ($params['sort_by'] == 'owner' || $params['sort_by'] == 'id') {
+ $sortfield = 's.share_' . $params['sort_by'];
} else {
- $sortfield = 's.attribute_' . $sort_by;
+ $sortfield = 's.attribute_' . $params['sort_by'];
}
$query = 'SELECT DISTINCT s.* '
- . $this->getShareCriteria($userid, $perm, $attributes,
- $parent, $allLevels, $ignorePerms)
+ . $this->getShareCriteria($userid, $params['perm'], $params['attributes'], $params['parent'], $params['all_levels'], $params['ignore_perms'])
. ' ORDER BY ' . $sortfield
- . (($direction == 0) ? ' ASC' : ' DESC');
- if ($from > 0 || $count > 0) {
- $this->_db->setLimit($count, $from);
- }
+ . (($params['direction'] == 0) ? ' ASC' : ' DESC');
+ $query = $this->_db->addLimitOffset($query, array('limit' => $params['count'], 'offset' => $params['from']));
Horde::logMessage('Query By Horde_Share_sql_hierarchical: ' . $query, 'DEBUG');
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (empty($result)) {
- return array();
+ try {
+ $rows = $this->_db->selectAll($query);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
$users = array();
$groups = array();
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$shares[(int)$share['share_id']] = $this->_fromDriverCharset($share);
if ($this->_hasUsers($share)) {
$users[] = (int)$share['share_id'];
$groups[] = (int)$share['share_id'];
}
}
- $result->free();
// Get users permissions
if (!empty($users)) {
$query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table
- . '_users WHERE share_id IN (' . implode(', ', $users)
- . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ . '_users WHERE share_id IN (' . str_repeat('?,', count($users) - 1) . '?)';
+
+ try {
+ $rows = $this->_db->selectAll($query, $users);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
$shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
- }
- $result->free();
}
}
// Get groups permissions
if (!empty($groups)) {
$query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table
- . '_groups WHERE share_id IN (' . implode(', ', $groups)
- . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
- }
- $result->free();
+ . '_groups WHERE share_id IN (' . str_repeat('?,', count($groups) - 1) . '?)';
+ try {
+ $rows = $this->_db->selectAll($query, $groups);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
}
}
}
unset($shares);
- try {
- return Horde::callHook('share_list', array($userid, $perm, $attributes, $sharelist));
- } catch (Horde_Exception_HookNotSet $e) {}
+ // Run the results through the callback, if configured.
+ if (!empty($this->_callbacks['list'])) {
+ return call_user_func_array($this->_callbacks['list'], array($userid, $sharelist, $params));
+ }
return $sharelist;
}
/**
* Returns an array of criteria for querying shares.
- * @access protected
*
+ * @TODO: check method visisbility,
+ * remove ignorePerms param, simply set perm to null for this
+ *
* @param string $userid The userid of the user to check access for.
* @param integer $perm The level of permissions required.
* @param mixed $attributes Restrict the shares returned to those who
{
static $criteria = array();
- if ($parent instanceof Horde_Share_Object) {
+ if (is_object($parent)) {
$parent_id = $parent->getId();
} else {
$parent_id = $parent;
}
-
$key = hash('sha1', serialize(array($userid, $perm, $parent_id, $allLevels, $attributes, $ignorePerms)));
if (isset($criteria[$key])) {
- return $criteria[$key];
+ //return $criteria[$key];
}
$query = ' FROM ' . $this->_table . ' s ';
// (name == perm_users and key == $userid and val & $perm)
$query .= ' LEFT JOIN ' . $this->_table . '_users u ON u.share_id = s.share_id';
- $where .= ' OR ( u.user_uid = ' . $this->_write_db->quote($userid)
+ $where .= ' OR ( u.user_uid = ' . $this->_db->quote($userid)
. ' AND (' . Horde_SQL::buildClause($this->_db, 'u.perm', '&', $perm) . '))';
// If the user has any group memberships, check for those also.
// @TODO: Inject the group driver
try {
- $group = $GLOBALS['injector']->getInstance('Horde_Group');
- $groups = $group->getGroupMemberships($userid, true);
+ $groups = $this->_groups->getGroupMemberships($userid, true);
if ($groups) {
// (name == perm_groups and key in ($groups) and val & $perm)
$ids = array_keys($groups);
if ($parent != null) {
if (!($parent instanceof Horde_Share_Object)) {
$parent = $this->getShareById($parent);
- if ($parent instanceof PEAR_Error) {
- throw new Horde_Share_Exception($parent->getMessage());
- }
}
// Need to append the parent's share id to the list of parents in
$from = 0, $count = 0)
{
$sql = 'SELECT DISTINCT(s.share_owner) '
- . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null,
- $parent, $allLevels);
+ . $this->getShareCriteria($this->_user, $perm, null, $parent, $allLevels);
if ($count) {
- $this->_db->setLimit($count, $from);
+ $sql = $this->_db->addLimitOffset($sql, array('limit' => $count, 'offset' => $from));
}
- $allowners = $this->_db->queryCol($sql);
- if ($allowners instanceof PEAR_Error) {
- Horde::logMessage($allowners, 'ERR');
- throw new Horde_Share_Exception($allowners->getMessage());
+ try {
+ $allowners = $this->_db->selectValues($sql);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e);
}
$owners = array();
foreach ($allowners as $owner) {
- if ($this->countShares($GLOBALS['registry']->getAuth(), $perm, $owner, $parent, $allLevels)) {
+ if ($this->countShares($this->_user, $perm, $owner, $parent, $allLevels)) {
$owners[] = $owner;
}
}
public function countOwners($perm = Horde_Perms::SHOW, $parent = null, $allLevels = true)
{
$sql = 'SELECT COUNT(DISTINCT(s.share_owner)) '
- . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null, $parent,
- $allLevels);
+ . $this->getShareCriteria($this->_user, $perm, null, $parent, $allLevels);
- return $this->_db->queryOne($sql);
+ return $this->_db->selectValue($sql);
}
/**
public function getShareById($cid)
{
if (!isset($this->_cache[$cid])) {
- $share = &$this->_getShareById($cid);
- if ($share instanceof PEAR_Error) {
- throw new Horde_Share_Exception($share->getMessage());
- }
+ $share = $this->_getShareById($cid);
$share->setShareOb($this);
$this->_cache[$cid] = &$share;
}
}
if (count($missing_ids)) {
- $shares = &$this->_getShares($missing_ids);
- if ($shares instanceof PEAR_Error) {
- throw new Horde_Share_Exception($shares->getMessage());
- }
-
+ $shares = $this->_getShares($missing_ids);
foreach (array_keys($shares) as $key) {
$this->_cache[$key] = &$shares[$key];
$this->_cache[$key]->setShareOb($this);
*/
public function removeShare(Horde_Share_Object $share)
{
- try {
- Horde::callHook('share_remove', array($share));
- } catch (Horde_Exception_HookNotSet $e) {}
-
/* Get the list of all $share's children */
- $children = $share->getChildren(null, true);
+ $children = $share->getChildren(null, null, true);
/* Remove share from the caches. */
$id = $share->getId();
$this->_cache = array();
$this->_listCache = array();
-
foreach ($children as $child) {
$result = $this->_removeShare($child);
- if ($result instanceof PEAR_Error) {
- throw new Horde_Share_Exception($result->getMessage());
- }
}
return $this->_removeShare($share);
protected function _getShares($ids)
{
$shares = array();
- $query = 'SELECT * FROM ' . $this->_table . ' WHERE share_id IN (' . implode(', ', $ids) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (empty($result)) {
- return array();
+ $query = 'SELECT * FROM ' . $this->_table . ' WHERE share_id IN (' . str_repeat('?,', count($ids) - 1) . '?)';
+ try {
+ $rows = $this->_db->selectAll($query, $ids);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
$groups = array();
$users = array();
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
+ foreach ($rows as $share) {
$shares[(int)$share['share_id']] = $this->_fromDriverCharset($share);
if ($this->_hasUsers($share)) {
$users[] = (int)$share['share_id'];
$groups[] = (int)$share['share_id'];
}
}
- $result->free();
// Get users permissions
if (!empty($users)) {
- $query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users '
- . ' WHERE share_id IN (' . implode(', ', $users) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
- }
- $result->free();
+ $query = 'SELECT share_id, user_uid, perm FROM ' . $this->_table . '_users WHERE share_id IN (' . str_repeat('?,', count($users) - 1) . '?)';
+ try {
+ $rows = $this->_db->selectAll($query, $users);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
+ }
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['users'][$share['user_uid']] = (int)$share['perm'];
}
}
// Get groups permissions
if (!empty($groups)) {
$query = 'SELECT share_id, group_uid, perm FROM ' . $this->_table . '_groups'
- . ' WHERE share_id IN (' . implode(', ', $groups) . ')';
- $result = $this->_db->query($query);
- if ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Horde_Share_Exception($result->getMessage());
- } elseif (!empty($result)) {
- while ($share = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
- $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
- }
- $result->free();
+ . ' WHERE share_id IN (' . str_repeat('?,', count($groups) - 1) . '?)';
+ try {
+ $rows = $this->_db->selectAll($query, $groups);
+ } catch (Horde_Db_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ throw new Horde_Share_Exception($e->getMessage());
}
+ foreach ($rows as $share) {
+ $shares[$share['share_id']]['perm']['groups'][$share['group_uid']] = (int)$share['perm'];
+ }
}
$sharelist = array();
$query = 'SELECT COUNT(DISTINCT s.share_id) '
. $this->getShareCriteria($userid, $perm, $attributes,
$parent, $allLevels);
- return $this->_db->queryOne($query);
+ return $this->_db->selectValue($query);
}
+
}
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
- <date>2010-10-22</date>
- <time>19:03:00</time>
+ <date>2010-10-29</date>
+ <time>13:19:48</time>
<version>
<release>0.0.4</release>
<api>0.0.4</api>
<release>beta</release>
<api>beta</api>
</stability>
- <date>2010-10-22</date>
+ <date>2010-10-29</date>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
* Converted to Horde 4 coding standards
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->newShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
- $share->set('owner', $userName);
- $share->set('name', $shareTitle);
-
- if (is_a($result = $shares->addShare($share), 'PEAR_Error')) {
- throw new Horde_Exception($result);
+ try {
+ $share = $shares->newShare($GLOBALS['registry']->getAuth(), $shareName);
+ $share->set('owner', $userName);
+ $share->set('name', $shareTitle);
+ $shares->addShare($share);
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception($e);
}
}
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
- if (is_a($result = $shares->removeShare($share), 'PEAR_Error')) {
- throw new Horde_Exception($result);
+ $share = $shares->getShare($shareName);
+ try {
+ $shares->removeShare($share);
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception_Prior($e);
}
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
- $share_list = &$shares->listShares($userName, Horde_Perms::SHOW, $userName);
+ $share_list = $shares->listShares($userName,
+ array('perm' => Horde_Perms::SHOW,
+ 'attributes' => $userName));
$myshares = array();
foreach ($share_list as $share) {
$myshares[] = $share->getName();
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
+ $share = $shares->getShare($shareName);
+ try {
+ $perm = $share->getPermission();
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception_Prior($e);
}
- $perm = &$share->getPermission();
foreach ($permissions as $permission) {
$permission = Horde_String::upper($permission);
if (defined('Horde_Perms::' . $permission)) {
}
}
- if (is_a($result = $share->setPermission($perm), 'PEAR_Error')) {
- throw new Horde_Exception($result);
+ try {
+ $share->setPermission($perm);
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception_Prior($e);
}
}
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
+ $shares->getShare($shareName);
try {
$groups = $GLOBALS['injector']->getInstance('Horde_Group');
$groupId = $groups->getGroupId($groupName);
throw new Horde_Exception($e);
}
- $perm = &$share->getPermission();
+ $perm = $share->getPermission();
foreach ($permissions as $permission) {
$permission = Horde_String::upper($permission);
if (defined('Horde_Perms::' . $permission)) {
}
}
- if (is_a($result = $share->setPermission($perm), 'PEAR_Error')) {
- throw new Horde_Exception($result);
+ try {
+ $share->setPermission($perm);
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception($e);
}
}
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
- if (is_a($result = $share->removeUser($userName), 'PEAR_Error')) {
+ $share = $shares->getShare($shareName);
+ try {
+ $share->removeUser($userName);
+ } catch (Horde_Share_Exception $e) {
throw new Horde_Exception($result);
}
}
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
+ $share = $shares->getShare($shareName);
try {
$groups = $GLOBALS['injector']->getInstance('Horde_Group');
$groupId = $groups->getGroupId($groupName);
} catch (Horde_Group_Exception $e) {
throw new Horde_Exception($e);
}
-
- if (is_a($result = $share->removeGroup($groupId), 'PEAR_Error')) {
- throw new Horde_Exception($result);
+ try {
+ $share->removeGroup($groupId);
+ } catch (Horde_Share_Exception $e) {
+ throw new Horde_Exception($e);
}
}
Horde_Perms::DELETE => 'delete');
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
- $perm = &$share->getPermission();
+ $share = $shares->getShare($shareName);
+ $perm = $share->getPermission();
$permissions = $perm->getUserPermissions();
if (empty($permissions[$userName])) {
return array();
Horde_Perms::DELETE => 'delete');
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
- $perm = &$share->getPermission();
+ $share = $shares->getShare($shareName);
+ $perm = $share->getPermission();
$permissions = $perm->getGroupPermissions();
if (empty($permissions[$groupName])) {
return array();
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
+ $share = $shares->getShare($shareName);
$perm = 0;
foreach ($permissions as $permission) {
$permission = Horde_String::upper($permission);
}
$shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
-
- if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
- throw new Horde_Exception($share);
- }
-
+ $share = $shares->getShare($shareName);
$perm = 0;
foreach ($permissions as $permission) {
$permission = Horde_String::upper($permission);
$share = $shares->getShareById(Horde_Util::getFormData('cid'));
$form = 'edit.inc';
$perm = $share->getPermission();
- } catch (Horde_Share_Exception $e) {
+ } catch (Horde_Exception_NotFound $e) {
if (($category = Horde_Util::getFormData('share')) !== null) {
try {
$share = $shares->getShare($category);
if (trim($name) == '') {
$name = $GLOBALS['registry']->getAuth('original');
}
- $share = $GLOBALS['ingo_shares']->newShare($signature);
+ $share = $GLOBALS['ingo_shares']->newShare($GLOBALS['registry']->getAuth(), $signature);
$share->set('name', $name);
$GLOBALS['ingo_shares']->addShare($share);
$GLOBALS['all_rulesets'][$signature] = $share;
/* Get a list of all shares this user owns and has perms to delete
* and remove them. */
try {
- $shares = $GLOBALS['ingo_shares']->listShares($user, Horde_Perms::DELETE, $user);
+ $shares = $GLOBALS['ingo_shares']->listShares($user, array('perm' => Horde_Perms::DELETE,
+ 'attributes' => $user));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e, 'ERR');
throw new Ingo_Exception($e);
$permission = Horde_Perms::SHOW)
{
try {
- $rulesets = $GLOBALS['ingo_shares']->listShares($GLOBALS['registry']->getAuth(), $permission, $owneronly ? $GLOBALS['registry']->getAuth() : null);
+ $rulesets = $GLOBALS['ingo_shares']->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $permission,
+ 'attributes' => $owneronly ? $GLOBALS['registry']->getAuth() : null));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e, 'ERR');
return array();
} elseif (count($parts) == 1) {
// This request is for all calendars owned by the requested user
- $calendars = $GLOBALS['kronolith_shares']->listShares($GLOBALS['registry']->getAuth(),
- Horde_Perms::SHOW,
- $parts[0]);
+ $calendars = $GLOBALS['kronolith_shares']->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => Horde_Perms::SHOW,
+ 'attributes' => $parts[0]));
$results = array();
foreach ($calendars as $calendarId => $calendar) {
$retpath = 'kronolith/' . $parts[0] . '/' . $calendarId;
}
}
}
-
+
if (count($ids) == 0) {
throw new Kronolith_Exception(_("No iCalendar data was found."));
} else if (count($ids) == 1) {
if (!empty($event)) {
$uid = $calendar . ':' . $event;
}
+
return $GLOBALS['kronolith_shares']->getShare($calendar)->lock($GLOBALS['injector']->getInstance('Horde_Lock'), $uid);
}
}
try {
- $shares = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::EDIT);
+ $shares = $GLOBALS['kronolith_shares']->listShares($user, array('perm' => Horde_Perms::EDIT));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($shares, 'ERR');
throw new Kronolith_Exception($shares);
if (trim($name) == '') {
$name = $GLOBALS['registry']->getAuth('original');
}
- $share = &$GLOBALS['kronolith_shares']->newShare($GLOBALS['registry']->getAuth());
+ $share = $GLOBALS['kronolith_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth());
$share->set('name', sprintf(_("%s's Calendar"), $name));
$GLOBALS['kronolith_shares']->addShare($share);
$GLOBALS['all_calendars'][$GLOBALS['registry']->getAuth()] = new Kronolith_Calendar_Internal(array('share' => $share));
}
try {
- $calendars = $GLOBALS['kronolith_shares']->listShares($GLOBALS['registry']->getAuth(), $permission, $owneronly ? $GLOBALS['registry']->getAuth() : null, 0, 0, 'name');
+ $calendars = $GLOBALS['kronolith_shares']->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $permission,
+ 'attributes' => $owneronly ? $GLOBALS['registry']->getAuth() : null,
+ 'sort_by' => 'name'));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e, 'ERR');
return array();
public static function addShare($info)
{
try {
- $calendar = $GLOBALS['kronolith_shares']->newShare(strval(new Horde_Support_Randomid()));
+ $calendar = $GLOBALS['kronolith_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid()));
} catch (Horde_Share_Exception $e) {
throw new Kronolith_Exception($e);
}
$tagger->tag($calendar->getName(), $info['tags'], $calendar->get('owner'), 'calendar');
try {
- $result = $GLOBALS['kronolith_shares']->addShare($calendar);
+ $GLOBALS['kronolith_shares']->addShare($calendar);
} catch (Horde_Share_Exception $e) {
throw new Kronolith_Exception($e);
}
try {
$share = $shares->getShareById(Horde_Util::getFormData('cid'));
$perm = $share->getPermission();
- } catch (Horde_Share_Exception $e) {
+ } catch (Horde_Exception_NotFound $e) {
if (($category = Horde_Util::getFormData('share')) !== null) {
try {
$share = $shares->getShare($category);
// If we found an email address, generate the agenda.
switch ($agenda_calendars) {
case 'owner':
- $calendars = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::SHOW, $user);
+ $calendars = $GLOBALS['kronolith_shares']->listShares(
+ $user,
+ array('perm' => Horde_Perms::SHOW,
+ 'attributes' => $user));
break;
case 'read':
- $calendars = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::SHOW, null);
+ $calendars = $GLOBALS['kronolith_shares']->listShares(
+ $user,
+ array('perm' => Horde_Perms::SHOW));
break;
case 'show':
default:
$calendars = array();
$shown_calendars = unserialize($prefs->getValue('display_cals'));
- $cals = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::SHOW, null);
+ $cals = $GLOBALS['kronolith_shares']->listShares(
+ $user,
+ array('perm' => Horde_Perms::SHOW));
foreach ($cals as $calId => $cal) {
if (in_array($calId, $shown_calendars)) {
$calendars[$calId] = $cal;
$user = $row['owner_name'];
Horde_Auth::setAuth($user, array());
$cli->message('Creating calendar ' . $row['name']);
- $share = $kronolith_shares->newShare($row['id']);
+ $share = $kronolith_shares->newShare($GLOBALS['registry']->getAuth(), $row['id']);
$share->set('name', $row['name']);
$kronolith_shares->addShare($share);
{
// Create new share.
try {
- $notepad = $GLOBALS['mnemo_shares']->newShare(strval(new Horde_Support_Uuid()));
+ $notepad = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Uuid()));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e->getMessage(), 'ERR');
throw new Mnemo_Exception($e);
$name = $GLOBALS['registry']->getAuth();
}
try {
- $notepad = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth());
+ $notepad = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth());
} catch (Horde_Share_Exception $e) {
return;
}
return array();
}
try {
- $notepads = $GLOBALS['mnemo_shares']->listShares($GLOBALS['registry']->getAuth(), $permission, $owneronly ? $GLOBALS['registry']->getAuth() : null, 0, 0, 'name');
+ $notepads = $GLOBALS['mnemo_shares']->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $permission,
+ 'attributes' => $owneronly ? $GLOBALS['registry']->getAuth() : null,
+ 'sort_by' => 'name'));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e->getMessage(), 'ERR');
return array();
if (trim($name) == '') {
$name = $GLOBALS['registry']->getAuth();
}
- $share = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth());
+ $share = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth());
$share->set('name', sprintf(_("%s's Notepad"), $name));
$GLOBALS['mnemo_shares']->addShare($share);
//
// This request is for all tasklists owned by the requested user
//
- $tasklists = $GLOBALS['nag_shares']->listShares($parts[0],
- Horde_Perms::SHOW,
- $parts[0]);
+ $tasklists = $GLOBALS['nag_shares']->listShares(
+ $parts[0],
+ array('perm' => Horde_Perms::SHOW,
+ 'attributes' => $parts[0]));
// The last check returns all addressbooks for the requested user,
// but that does not mean the requesting user has access to them.
return array();
}
try {
- $tasklists = $GLOBALS['nag_shares']->listShares($GLOBALS['registry']->getAuth(), $permission, $owneronly ? $GLOBALS['registry']->getAuth() : null, 0, 0, 'name');
+ $tasklists = $GLOBALS['nag_shares']->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $permission, $owneronly ? $GLOBALS['registry']->getAuth() : null,
+ 'sort_by' => 'name'));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e->getMessage(), 'ERR');
return array();
public static function addTasklist($info)
{
try {
- $tasklist = $GLOBALS['nag_shares']->newShare(strval(new Horde_Support_Uuid()));
+ $tasklist = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Uuid()));
$tasklist->set('name', $info['name']);
$tasklist->set('color', $info['color']);
$tasklist->set('desc', $info['description']);
if (trim($name) == '') {
$name = $GLOBALS['registry']->getAuth('original');
}
- $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth());
+ $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth());
$share->set('name', sprintf(_("%s's Task List"), $name));
$GLOBALS['nag_shares']->addShare($share);
if ($task->tasklist == '**EXTERNAL**') {
// Just use a new share that this user owns for tasks from
// external calls - if the API gives them back, we'll trust it.
- $share = $GLOBALS['nag_shares']->newShare('**EXTERNAL**');
+ $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), '**EXTERNAL**');
$owner = $task->tasklist_name;
} else {
try {
if ($task->tasklist == '**EXTERNAL**') {
// Just use a new share that this user owns for tasks from
// external calls - if the API gives them back, we'll trust it.
- $share = $GLOBALS['nag_shares']->newShare('**EXTERNAL**');
+ $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), '**EXTERNAL**');
$owner = $task->tasklist_name;
} else {
try {
// No backends are configured to provide shares
return array();
}
- $addressbooks = $GLOBALS['turba_shares']->listShares($parts[0],
- Horde_Perms::READ,
- $parts[0]);
+ $addressbooks = $GLOBALS['turba_shares']->listShares(
+ $parts[0],
+ array('perm' => Horde_Perms::READ,
+ 'attributes' => $parts[0]));
// The last check returns all addressbooks for the requested user,
// but that does not mean the requesting user has access to them.
// Filter out those address books for which the requesting user has
return;
}
- $shares = $GLOBALS['turba_shares']->listShares($user, Horde_Perms::EDIT, $user);
+ $shares = $GLOBALS['turba_shares']->listShares(
+ $user,
+ array('perm' => Horde_Perms::EDIT,
+ 'attributes' => $user));
/* Look for the deleted user's default share and remove it */
foreach ($shares as $share) {
try {
$sources = $GLOBALS['turba_shares']->listShares(
- $GLOBALS['registry']->getAuth(), $permission,
- $owneronly ? $GLOBALS['registry']->getAuth() : null);
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $permission,
+ 'attributes' => $owneronly ? $GLOBALS['registry']->getAuth() : null));
} catch (Horde_Share_Exception $e) {
Horde::logMessage($e, 'ERR');
return array();
/* Generate the new share. */
try {
- $share = $GLOBALS['turba_shares']->newShare($share_id);
+ $share = $GLOBALS['turba_shares']->newShare($GLOBALS['registry']->getAuth(), $share_id);
/* Set the display name for this share. */
$share->set('name', $name);
// Create the new share.
$owner_uid = strval(new Horde_Support_Randomid());
-$share = &$turba_shares->newShare($sourceKey . ':' . $owner_uid);
+$share = &$turba_shares->newShare($GLOBALS['registry']->getAuth(), $sourceKey . ':' . $owner_uid);
if ($share instanceof Horde_Share_Exception) {
var_dump($share);
exit;
{
try {
$share = $this->_shareManager->getShareById($queryId);
- } catch (Horde_Share_Exception $e) {
+ } catch (Horde_Exception_NotFound $e) {
throw new Whups_Exception($e);
}
return $this->_getQuery($share);
function getQueryBySlug($slug)
{
try {
- $shares = $this->_shareManager->listShares($GLOBALS['registry']->getAuth(), Horde_Perms::READ,
- array('slug' => $slug));
+ $shares = $this->_shareManager->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => Horde_Perms::READ,
+ 'attribtues' => array('slug' => $slug)));
} catch (Horde_Share_Exception $e) {
throw new Whups_Exception($e);
}
{
try {
$share = $this->_shareManager->getShareById($queryId);
- } catch (Horde_Share_Exception $e) {
+ } catch (Horde_Exception_NotFound $e) {
// If the share doesn't exist yet, then it has open perms.
return true;
}
// if necessary.
try {
$share = $this->_shareManager->getShareById($query->id);
- } catch (Horde_Share_Exception $e) {
+ } catch (Horde_Exception_NotFound $e) {
// Share has an id but doesn't exist; just throw an
// error.
throw new Whups_Exception($e);
}
} else {
// Create a new share for the query.
- $share = $this->_shareManager->newShare((string)new Horde_Support_Uuid());
+ $share = $this->_shareManager->newShare($GLOBALS['registry']->getAuth(), (string)new Horde_Support_Uuid());
$share->set('name', $query->name);
$share->set('slug', $query->slug);
try {
try {
$share = $this->_shareManager->getShareById($query->id);
$this->_shareManager->removeShare($share);
- } catch (Horde_Share_Exception $e) {
+ } catch (Exception $e) {
throw new Whups_Exception($e);
}
$result = $GLOBALS['whups_driver']->deleteQuery($query->id);