Turba::getSourceFromShare PHP Method

getSourceFromShare() public static method

Retrieve a new source config entry based on a Turba share.
public static getSourceFromShare ( Horde_Share_Object $share ) : array
$share Horde_Share_Object
return array The $cfgSource entry for this share source.
    public static function getSourceFromShare(Horde_Share_Object $share)
    {
        // Require a fresh config file.
        $cfgSources = self::availableSources();
        $params = @unserialize($share->get('params'));
        $newConfig = $cfgSources[$params['source']];
        $newConfig['params']['config'] = $cfgSources[$params['source']];
        $newConfig['params']['config']['params']['share'] = $share;
        $newConfig['params']['config']['params']['name'] = $params['name'];
        $newConfig['title'] = $share->get('name');
        $newConfig['type'] = 'share';
        $newConfig['use_shares'] = false;
        return $newConfig;
    }

Usage Example

Example #1
0
 /**
  */
 public function removeUserData($user)
 {
     /* We need a clean copy of the $cfgSources array here.*/
     $cfgSources = Turba::availableSources();
     foreach ($cfgSources as $sourceId => $source) {
         if (empty($source['use_shares'])) {
             // Shares not enabled for this source
             try {
                 $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source, $sourceId);
             } catch (Turba_Exception $e) {
                 Horde::log($e, 'ERR');
             }
             try {
                 $driver->removeUserData($user);
             } catch (Turba_Exception_NotSupported $e) {
                 continue;
             } catch (Turba_Exception $e) {
                 Horde::log($e, 'ERR');
                 throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
             }
         }
     }
     /* Only attempt share removal if we have shares configured */
     if (!$GLOBALS['session']->get('turba', 'has_share')) {
         return;
     }
     $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
     $shares = $turba_shares->listShares($user, array('attributes' => $user));
     // Look for the deleted user's shares and remove them
     foreach ($shares as $share) {
         $config = Turba::getSourceFromShare($share);
         try {
             $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($config, $share->getName());
         } catch (Turba_Exception $e) {
             continue;
         }
         try {
             $driver->removeUserData($user);
         } catch (Turba_Exception_NotSupported $e) {
             continue;
         } catch (Turba_Exception $e) {
             Horde::log($e, 'ERR');
             throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
         }
     }
     /* Get a list of all shares this user has perms to and remove the
      * perms. */
     try {
         $shares = $turba_shares->listShares($user);
         foreach ($shares as $share) {
             $share->removeUser($user);
         }
     } catch (Horde_Share_Exception $e) {
         Horde::log($e, 'ERR');
         throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
     }
 }