} catch (Horde_Perms_Exception $e) {}
}
- $perm = new Horde_Perms_Permission_DataTreeObject($name, $type, $params);
+ $perm = new Horde_Perms_Permission_DataTreeObject($name, $this->_cacheVersion, $type, $params);
$perm->setDataTree($this->_datatree);
return $perm;
$perm = $this->_cache->get('perm_' . $this->_cacheVersion . $name, $GLOBALS['conf']['cache']['default_lifetime']);
if ($perm === false) {
$perm = $this->_datatree->getObject($name, 'Horde_Perms_Permission_DataTreeObject');
+ $perm->setCacheVersion($this->_cacheVersion);
$this->_cache->set('perm_' . $this->_cacheVersion . $name, serialize($perm), $GLOBALS['conf']['cache']['default_lifetime']);
$this->_permsCache[$name] = $perm;
} else {
*/
public function getPermissionById($cid)
{
- return ($cid == Horde_Perms::ROOT)
- ? $this->newPermission(Horde_Perms::ROOT)
- : $this->_datatree->getObjectById($cid, 'Horde_Perms_Permission_DataTreeObject');
+ if ($cid == Horde_Perms::ROOT) {
+ return $this->newPermission(Horde_Perms::ROOT);
+ }
+ $perm = $this->_datatree->getObjectById($cid, 'Horde_Perms_Permission_DataTreeObject');
+ $perm->setCacheVersion($this->_cacheVersion);
+ return $perm;
}
/**
public $name;
/**
+ * Incrementing version number if cached classes change.
+ *
+ * @var integer
+ */
+ private $_cacheVersion;
+
+ /**
* Constructor.
*
- * @param string $name The name of the perm.
- * @param string $type The permission type.
- * @param array $params A hash with any parameters that the permission
- * type needs.
+ * @param string $name The name of the perm.
+ * @param integer $cacheVersion The revision number of the class.
+ * @param string $type The permission type.
+ * @param array $params A hash with any parameters that the
+ * permission type needs.
*/
- public function __construct($name, $type = 'matrix', $params = null)
+ public function __construct($name, $cacheVersion = null, $type = 'matrix', $params = null)
{
$this->setName($name);
+ $this->setCacheVersion($cacheVersion);
$this->data['type'] = $type;
if (is_array($params)) {
$this->data['params'] = $params;
}
/**
+ * Sets the revision number of the class.
+ *
+ * @param integer $cacheVersion The revision number of the class.
+ */
+ public function setCacheVersion($cacheVersion)
+ {
+ $this->_cacheVersion = $cacheVersion;
+ }
+
+ /**
* Gets one of the attributes of the object, or null if it isn't defined.
*
* @param string $attribute The attribute to get.
parent::save();
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
- $cache->expire('perm_' . $name);
- $cache->expire('perm_exists_' . $name);
+ $cache->expire('perm_' . $this->_cacheVersion . $name);
+ $cache->expire('perm_exists_' . $this->_cacheVersion . $name);
}
}
}
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
- $cache->expire('perm_sql_' . $name);
- $cache->expire('perm_sql_exists_' . $name);
+ $cache->expire('perm_sql_' . $this->_cacheVersion . $name);
+ $cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name);
}
}
} catch (Horde_Perms_Exception $e) {}
}
- return new Horde_Perms_Permission_SqlObject($name, $type, $params);
+ return new Horde_Perms_Permission_SqlObject($name, $this->_cacheVersion, $type, $params);
}
/**
throw new Horde_Perms_Exception('Does not exist');
}
- $object = new Horde_Perms_Permission_SqlObject($name);
+ $object = new Horde_Perms_Permission_SqlObject($name, $this->_cacheVersion);
$object->setId($result['perm_id']);
$object->setData(unserialize($result['perm_data']));
throw new Horde_Perms_Exception('Does not exist');
}
- $object = new Horde_Perms_Permission_SqlObject($result['perm_name']);
+ $object = new Horde_Perms_Permission_SqlObject($result['perm_name'], $this->_cacheVersion);
$object->setId($id);
$object->setData(unserialize($result['perm_data']));
$object->setSQLOb($this->_write_db);