mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-17 02:41:02 +01:00
egw_cache::(get|set|unset)Cache($level,...) excepts now an install_id to use instance cache of given instance
accounts class uses now instance_id to access instance cache to support using it with multiple instances instanciating accounts class with an array of config values clears now internal static cache and singelton instance
This commit is contained in:
parent
1c44d9a147
commit
9b69638f08
@ -56,7 +56,7 @@ class accounts
|
||||
/**
|
||||
* Enables the session-cache, currently switched on independent of the backend
|
||||
*
|
||||
* @var boolean $use_session_cache
|
||||
* @var boolean
|
||||
*/
|
||||
static $use_session_cache = true;
|
||||
|
||||
@ -91,6 +91,19 @@ class accounts
|
||||
var $depricated_names = array('firstname','lastname','fullname','email','type',
|
||||
'status','expires','lastlogin','lastloginfrom','lastpasswd_change');
|
||||
|
||||
/**
|
||||
* List of all config vars accounts depend on and therefore should be passed in when calling contructor with array syntax
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static public $config_vars = array(
|
||||
'account_repository', 'auth_type', // auth_type if fallback if account_repository is not set
|
||||
'install_id', // instance-specific caching
|
||||
'auto_create_expire', 'default_group_lid', // auto-creation of accounts
|
||||
'ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter', // ldap backend
|
||||
'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context', // ads backend
|
||||
);
|
||||
|
||||
/**
|
||||
* Querytypes for the account-search
|
||||
*
|
||||
@ -135,7 +148,7 @@ class accounts
|
||||
private static $_instance = NULL;
|
||||
|
||||
/**
|
||||
* the singleton passtern
|
||||
* Singleton
|
||||
*
|
||||
* @return accounts
|
||||
*/
|
||||
@ -164,10 +177,15 @@ class accounts
|
||||
{
|
||||
$this->config = $backend;
|
||||
$backend = null;
|
||||
self::$_instance = $this; // also set instance returned by singleton
|
||||
unset(self::$cache); // and empty our internal (session) cache
|
||||
self::$cache = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config =& $GLOBALS['egw_info']['server'];
|
||||
|
||||
if (!isset(self::$_instance)) self::$_instance = $this;
|
||||
}
|
||||
if (is_null($backend))
|
||||
{
|
||||
@ -989,7 +1007,9 @@ class accounts
|
||||
{
|
||||
foreach((array)$account_ids as $account_id)
|
||||
{
|
||||
egw_cache::unsetInstance(__CLASS__, 'account-'.$account_id);
|
||||
$instance = self::getInstance();
|
||||
|
||||
egw_cache::unsetCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
|
||||
|
||||
unset(self::$request_cache[$account_id]);
|
||||
}
|
||||
@ -1033,12 +1053,12 @@ class accounts
|
||||
|
||||
if (!isset($account)) // not in request cache --> try intance cache
|
||||
{
|
||||
$account = egw_cache::getInstance(__CLASS__, 'account-'.$account_id);
|
||||
$instance = self::getInstance();
|
||||
|
||||
$account = egw_cache::getCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
|
||||
|
||||
if (!isset($account)) // not in instance cache --> read from backend
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
|
||||
if (($account = $instance->backend->read($account_id)))
|
||||
{
|
||||
if ($instance->get_type($account_id) == 'u')
|
||||
@ -1049,7 +1069,7 @@ class accounts
|
||||
{
|
||||
if (!isset($account['members'])) $account['members'] = $instance->backend->members($account_id);
|
||||
}
|
||||
egw_cache::setInstance(__CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
||||
egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
||||
}
|
||||
//error_log(__METHOD__."($account_id) read from backend ".array2string($account));
|
||||
}
|
||||
@ -1064,7 +1084,7 @@ class accounts
|
||||
{
|
||||
if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
|
||||
}
|
||||
egw_cache::setInstance(__CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
||||
egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
||||
}
|
||||
//error_log(__METHOD__."($account_id, $need_active) returning ".array2string($account));
|
||||
return $account;
|
||||
|
@ -139,12 +139,12 @@ class accounts_ads
|
||||
if (empty($config['ads_host'])) throw new Exception("Required ADS host name(s) missing!");
|
||||
if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!");
|
||||
|
||||
$base_dn = array();
|
||||
$base_dn_parts = array();
|
||||
foreach(explode('.', $config['ads_domain']) as $dc)
|
||||
{
|
||||
$base_dn[] = 'DC='.$dc;
|
||||
$base_dn_parts[] = 'DC='.$dc;
|
||||
}
|
||||
$base_dn = implode(',', $base_dn);
|
||||
$base_dn = implode(',', $base_dn_parts);
|
||||
$options = array(
|
||||
'domain_controllers' => preg_split('/[ ,]+/', $config['ads_host']),
|
||||
'base_dn' => $base_dn ? $base_dn : null,
|
||||
@ -170,10 +170,10 @@ class accounts_ads
|
||||
*/
|
||||
protected function get_sid($account_id=null)
|
||||
{
|
||||
static $domain_sid;
|
||||
static $domain_sid = null;
|
||||
if (!isset($domain_sid))
|
||||
{
|
||||
$domain_sid = egw_cache::getInstance(__CLASS__, 'ads_domain_sid');
|
||||
$domain_sid = egw_cache::getCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid');
|
||||
if ((!is_array($domain_sid) || !isset($domain_sid[$this->frontend->config['ads_domain']])) &&
|
||||
($adldap = self::get_adldap($this->frontend->config)) &&
|
||||
($sr = ldap_search($adldap->getLdapConnection(), $adldap->getBaseDn(), '(objectclass=domain)', array('objectsid'))) &&
|
||||
@ -181,7 +181,7 @@ class accounts_ads
|
||||
{
|
||||
$domain_sid = array();
|
||||
$domain_sid[$this->frontend->config['ads_domain']] = $adldap->utilities()->getTextSID($entries[0]['objectsid'][0]);
|
||||
egw_cache::setInstance(__CLASS__, 'ads_domain_sid', $domain_sid);
|
||||
egw_cache::setCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid', $domain_sid);
|
||||
}
|
||||
}
|
||||
$sid = $domain_sid[$this->frontend->config['ads_domain']];
|
||||
@ -231,6 +231,7 @@ class accounts_ads
|
||||
{
|
||||
$context = $this->ads_context(true);
|
||||
$base = $this->adldap->getBaseDn();
|
||||
$matches = null;
|
||||
if (!preg_match('/^(.*),'.preg_quote($base, '/').'$/i', $context, $matches))
|
||||
{
|
||||
throw new egw_exception_wrong_userinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
|
||||
@ -556,7 +557,7 @@ class accounts_ads
|
||||
*/
|
||||
protected static function _when2ts($when)
|
||||
{
|
||||
static $utc;
|
||||
static $utc=null;
|
||||
if (!isset($utc)) $utc = new DateTimeZone('UTC');
|
||||
|
||||
list($when) = explode('.', $when); // remove .0Z not understood by createFromFormat
|
||||
@ -1101,6 +1102,7 @@ class accounts_ads
|
||||
{
|
||||
foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
|
||||
{
|
||||
unset($account_lid);
|
||||
$ret = $account_id;
|
||||
break;
|
||||
}
|
||||
@ -1132,6 +1134,8 @@ class accounts_ads
|
||||
*/
|
||||
function update_lastlogin($_account_id, $ip)
|
||||
{
|
||||
unset($_account_id, $ip); // not used, but required by function signature
|
||||
|
||||
return false; // not longer supported
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* @package api
|
||||
* @subpackage cache
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2009-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2009-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
@ -39,6 +39,9 @@
|
||||
*
|
||||
* The tree and instance wide cache uses a certain provider class, to store the data
|
||||
* eg. in memcached or if there's nothing else configured in the filesystem (eGW's temp_dir).
|
||||
*
|
||||
* Apps needing to talk to multiple EGroupware instances (eg. Stylite Managementserver)
|
||||
* can use install_id of instance as $level parameter to (set|get|unset)Cache method.
|
||||
*/
|
||||
class egw_cache
|
||||
{
|
||||
@ -101,6 +104,7 @@ class egw_cache
|
||||
|
||||
case self::INSTANCE:
|
||||
case self::TREE:
|
||||
default:
|
||||
if (!($provider = self::get_provider($level)))
|
||||
{
|
||||
return false;
|
||||
@ -141,6 +145,7 @@ class egw_cache
|
||||
|
||||
case self::INSTANCE:
|
||||
case self::TREE:
|
||||
default:
|
||||
if (!($provider = self::get_provider($level)))
|
||||
{
|
||||
return null;
|
||||
@ -207,6 +212,7 @@ class egw_cache
|
||||
|
||||
case self::INSTANCE:
|
||||
case self::TREE:
|
||||
default:
|
||||
if (!($provider = self::get_provider($level)))
|
||||
{
|
||||
return false;
|
||||
@ -434,13 +440,15 @@ class egw_cache
|
||||
*
|
||||
* The returned provider already has an opened connection
|
||||
*
|
||||
* @param string $level egw_cache::(TREE|INSTANCE)
|
||||
* @param string $level egw_cache::(TREE|INSTANCE) or install_id
|
||||
* @return egw_cache_provider
|
||||
*/
|
||||
static protected function get_provider($level)
|
||||
{
|
||||
static $providers = array();
|
||||
|
||||
if ($level != self::TREE) $level = self::INSTANCE;
|
||||
|
||||
if (!isset($providers[$level]))
|
||||
{
|
||||
$params = $GLOBALS['egw_info']['server']['cache_provider_'.strtolower($level)];
|
||||
@ -597,39 +605,43 @@ class egw_cache
|
||||
/**
|
||||
* Get keys array from $level, $app and $location
|
||||
*
|
||||
* @param string $level egw_cache::(TREE|INSTANCE)
|
||||
* @param string $level egw_cache::(TREE|INSTANCE) or instance_id
|
||||
* @param string $app
|
||||
* @param string $location
|
||||
* @return array
|
||||
*/
|
||||
static public function keys($level,$app,$location)
|
||||
{
|
||||
static $bases = array();
|
||||
static $tree_key = null;
|
||||
|
||||
if (!isset($bases[$level]))
|
||||
switch($level)
|
||||
{
|
||||
switch($level)
|
||||
{
|
||||
case self::TREE:
|
||||
$bases[$level] = $level.'-'.str_replace(array(':','/','\\'),'-',EGW_SERVER_ROOT);
|
||||
case self::TREE:
|
||||
if (!isset($tree_key))
|
||||
{
|
||||
$tree_key = $level.'-'.str_replace(array(':','/','\\'),'-',EGW_SERVER_ROOT);
|
||||
// add charset to key, if not utf-8 (as everything we store depends on charset!)
|
||||
if (($charset = self::get_system_config('system_charset',false)) && $charset != 'utf-8')
|
||||
{
|
||||
$bases[$level] .= '-'.$charset;
|
||||
$tree_key .= '-'.$charset;
|
||||
}
|
||||
break;
|
||||
case self::INSTANCE:
|
||||
if (!isset(self::$instance_key))
|
||||
{
|
||||
self::$instance_key = self::getTree(__CLASS__, self::get_system_config('install_id'));
|
||||
//error_log(__METHOD__."('$level',...) instance_key read from tree-cache=".array2string(self::$instance_key));
|
||||
if (!isset(self::$instance_key)) self::generate_instance_key();
|
||||
}
|
||||
$bases[$level] = self::$instance_key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$level_key = $tree_key;
|
||||
break;
|
||||
case self::INSTANCE:
|
||||
if (!isset(self::$instance_key))
|
||||
{
|
||||
self::$instance_key = self::getTree(__CLASS__, self::get_system_config('install_id'));
|
||||
//error_log(__METHOD__."('$level',...) instance_key read from tree-cache=".array2string(self::$instance_key));
|
||||
if (!isset(self::$instance_key)) self::generate_instance_key();
|
||||
}
|
||||
$level_key = self::$instance_key;
|
||||
break;
|
||||
default:
|
||||
$level_key = $level;
|
||||
break;
|
||||
}
|
||||
return array($bases[$level],$app,$location);
|
||||
return array($level_key, $app, $location);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user