mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
- config is now cached on instance level
- arrays in $GLOBALS[egw_info][server] are now automatically serialized and unserialized - new static method to check if user is export-limit excepted --> saves to query it on each request (for non-phpgwapi, which was already cached in the session)
This commit is contained in:
parent
7d33eb610a
commit
389486793d
@ -291,7 +291,8 @@ class addressbook_bo extends addressbook_so
|
||||
}
|
||||
if ($GLOBALS['egw_info']['server']['org_fileds_to_update'])
|
||||
{
|
||||
$this->org_fields = unserialize($GLOBALS['egw_info']['server']['org_fileds_to_update']);
|
||||
$this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update'];
|
||||
if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields);
|
||||
|
||||
// Set country code if country name is selected
|
||||
$supported_fields = $this->get_fields('supported',null,0);
|
||||
@ -308,8 +309,7 @@ class addressbook_bo extends addressbook_so
|
||||
|
||||
$this->tracking = new addressbook_tracking($this);
|
||||
|
||||
$config = config::read('phpgwapi');
|
||||
$this->delete_history = $config['history'];
|
||||
$this->delete_history = $GLOBALS['egw_info']['server']['history'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,8 @@ class addressbook_ui extends addressbook_bo
|
||||
{
|
||||
$this->config['contact_export_limit'] = $this->config['export_limit'];
|
||||
}
|
||||
if ($this->config['copy_fields'] && ($fields = unserialize($this->config['copy_fields'])))
|
||||
if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ?
|
||||
$this->config['copy_fields'] : unserialize($this->config['copy_fields'])))
|
||||
{
|
||||
// Set country code if country name is selected
|
||||
$supported_fields = $this->get_fields('supported',null,0);
|
||||
|
@ -83,7 +83,6 @@ abstract class bo_merge
|
||||
*/
|
||||
public static function hook_export_limit_excepted($config)
|
||||
{
|
||||
error_log(__METHOD__.'('.array2string($config).')');
|
||||
$accountsel = new uiaccountsel();
|
||||
|
||||
return $accountsel->selection('newsettings[export_limit_excepted]','export_limit_excepted',$config['export_limit_excepted'],'both',4);
|
||||
@ -295,6 +294,33 @@ abstract class bo_merge
|
||||
return egw_time::to($time,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current user is excepted from the export-limit:
|
||||
* a) access to admin application
|
||||
* b) he or one of his memberships is named in export_limit_excepted config var
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function is_export_limit_excepted()
|
||||
{
|
||||
static $is_excepted;
|
||||
|
||||
if (is_null($is_excepted))
|
||||
{
|
||||
$is_excepted = isset($GLOBALS['egw_info']['user']['apps']['admin']);
|
||||
|
||||
// check export-limit and fail if user tries to export more entries then allowed
|
||||
if (!$is_excepted && (is_array($export_limit_excepted = $GLOBALS['egw_info']['server']['export_limit_excepted']) ||
|
||||
is_array($export_limit_excepted = unserialize($export_limit_excepted))))
|
||||
{
|
||||
$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
|
||||
$id_and_memberships[] = $GLOBALS['egw_info']['user']['account_id'];
|
||||
$is_excepted = (bool) array_intersect($id_and_memberships, $export_limit_excepted);
|
||||
}
|
||||
}
|
||||
return $is_excepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges a given document with contact data
|
||||
*
|
||||
@ -313,10 +339,7 @@ abstract class bo_merge
|
||||
return false;
|
||||
}
|
||||
|
||||
// check export-limit and fail if user tries to export more entries then allowed
|
||||
$limit_exception = count(@array_intersect(array($GLOBALS['egw_info']['user']['account_id']) + $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true), unserialize($GLOBALS['egw_info']['server']['export_limit_excepted']))) > 0;
|
||||
if ($this->export_limit && !($GLOBALS['egw_info']['user']['apps']['admin'] || $limit_exception) &&
|
||||
count($ids) > (int)$this->export_limit)
|
||||
if ($this->export_limit && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit)
|
||||
{
|
||||
$err = lang('No rights to export more then %1 entries!',(int)$this->export_limit);
|
||||
return false;
|
||||
@ -1182,14 +1205,12 @@ abstract class bo_merge
|
||||
}
|
||||
}
|
||||
}
|
||||
$limit_exception = count(@array_intersect(array($GLOBALS['egw_info']['user']['account_id']) + $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true), unserialize($GLOBALS['egw_info']['server']['export_limit_excepted']))) > 0;
|
||||
return array(
|
||||
'icon' => 'etemplate/merge',
|
||||
'caption' => $caption,
|
||||
'children' => $documents,
|
||||
// disable action if no document or export completly forbidden for non-admins
|
||||
'enabled' => (boolean)$documents && (empty($export_limit) ||
|
||||
(int)$export_limit > 0 || $GLOBALS['egw_info']['user']['apps']['admin'] || $limit_exception),
|
||||
'enabled' => (boolean)$documents && (empty($export_limit) || (int)$export_limit > 0 || self::is_export_limit_excepted()),
|
||||
'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
|
||||
'group' => $group,
|
||||
);
|
||||
|
@ -276,10 +276,9 @@ class nextmatch_widget
|
||||
unset($value['rows']);
|
||||
$extension_data += $value;
|
||||
|
||||
$limit_exception = count(@array_intersect(array($GLOBALS['egw_info']['user']['account_id']) + $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true), unserialize($GLOBALS['egw_info']['server']['export_limit_excepted']))) > 0;
|
||||
$value['no_csv_export'] = $value['csv_fields'] === false ||
|
||||
$GLOBALS['egw_info']['server']['export_limit'] && !is_numeric($GLOBALS['egw_info']['server']['export_limit']) &&
|
||||
!(isset($GLOBALS['egw_info']['user']['apps']['admin']) || $limit_exception);
|
||||
!bo_merge::is_export_limit_excepted();
|
||||
|
||||
if (!$value['filter_onchange']) $value['filter_onchange'] = 'this.form.submit();';
|
||||
if (!$value['filter2_onchange']) $value['filter2_onchange'] = 'this.form.submit();';
|
||||
@ -1448,8 +1447,7 @@ class nextmatch_widget
|
||||
*/
|
||||
static public function csv_export(&$value,$separator=';')
|
||||
{
|
||||
$limit_exception = count(array_intersect(array($GLOBALS['egw_info']['user']['account_id']) + $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true), unserialize($GLOBALS['egw_info']['server']['export_limit_excepted']))) > 0;
|
||||
if (!(isset($GLOBALS['egw_info']['user']['apps']['admin']) || $limit_exception))
|
||||
if (!bo_merge::is_export_limit_excepted())
|
||||
{
|
||||
$export_limit = $GLOBALS['egw_info']['server']['export_limit'];
|
||||
//if (isset($value['export_limit'])) $export_limit = $value['export_limit'];
|
||||
|
@ -31,7 +31,7 @@ class config
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static private $configs = array();
|
||||
static private $configs;
|
||||
|
||||
/**
|
||||
* app the particular config class is instanciated for
|
||||
@ -82,16 +82,12 @@ class config
|
||||
*/
|
||||
function save_repository()
|
||||
{
|
||||
if (!is_object(self::$db))
|
||||
{
|
||||
self::init_db();
|
||||
}
|
||||
if (is_array($this->config_data))
|
||||
{
|
||||
self::$db->lock(array(config::TABLE));
|
||||
foreach($this->config_data as $name => $value)
|
||||
{
|
||||
$this->save_value($name,$value);
|
||||
$this->save_value($name,$value,null,false);
|
||||
}
|
||||
foreach(self::$configs[$this->appname] as $name => $value)
|
||||
{
|
||||
@ -107,6 +103,8 @@ class config
|
||||
$GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server])
|
||||
}
|
||||
self::$configs[$this->appname] = $this->config_data;
|
||||
|
||||
egw_cache::setInstance(__CLASS__, 'configs', self::$configs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +117,7 @@ class config
|
||||
* @param mixed $value content, empty or null values are not saved, but deleted
|
||||
* @param string $app=null app-name, defaults to $this->appname set via the constructor
|
||||
*/
|
||||
/* static */ function save_value($name,$value,$app=null)
|
||||
/* static */ function save_value($name,$value,$app=null,$update_cache=true)
|
||||
{
|
||||
if (!$app && (!isset($this) || !is_a($this,__CLASS__)))
|
||||
{
|
||||
@ -131,6 +129,10 @@ class config
|
||||
$app = $this->appname;
|
||||
$this->config_data[$name] = $value;
|
||||
}
|
||||
if (!isset(self::$configs))
|
||||
{
|
||||
self::init_static();
|
||||
}
|
||||
//echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n";
|
||||
if (isset(self::$configs[$app][$name]) && self::$configs[$app][$name] === $value)
|
||||
{
|
||||
@ -145,16 +147,18 @@ class config
|
||||
{
|
||||
$value = serialize($value);
|
||||
}
|
||||
if (!is_object(self::$db))
|
||||
{
|
||||
self::init_db();
|
||||
}
|
||||
if (!isset($value) || $value === '')
|
||||
{
|
||||
if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]);
|
||||
return self::$db->delete(config::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__);
|
||||
$ok = self::$db->delete(config::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__);
|
||||
}
|
||||
return self::$db->insert(config::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__);
|
||||
else
|
||||
{
|
||||
$ok = self::$db->insert(config::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__);
|
||||
}
|
||||
if ($update_cache) egw_cache::setInstance(__CLASS__, 'configs', self::$configs);
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,13 +167,14 @@ class config
|
||||
*/
|
||||
function delete_repository()
|
||||
{
|
||||
if (!is_object(self::$db))
|
||||
if (!isset(self::$configs))
|
||||
{
|
||||
self::init_db();
|
||||
self::init_static();
|
||||
}
|
||||
self::$db->delete(config::TABLE,array('config_app' => $this->appname),__LINE__,__FILE__);
|
||||
|
||||
unset(self::$configs[$this->appname]);
|
||||
egw_cache::setInstance(__CLASS__, 'configs', self::$configs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,31 +208,11 @@ class config
|
||||
*/
|
||||
static function read($app)
|
||||
{
|
||||
$config =& self::$configs[$app];
|
||||
|
||||
if (!isset($config))
|
||||
if (!isset(self::$configs))
|
||||
{
|
||||
if (!is_object(self::$db))
|
||||
{
|
||||
self::init_db();
|
||||
}
|
||||
$config = array();
|
||||
foreach(self::$db->select(config::TABLE,'*',array('config_app' => $app),__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$name = $row['config_name'];
|
||||
$value = $row['config_value'];
|
||||
|
||||
$test = @unserialize($value);
|
||||
if($test === false)
|
||||
{
|
||||
// manually retrieve the string lengths of the serialized array if unserialize failed
|
||||
$test = @unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.mb_strlen('$2','8bit').':\"$2\";'", $value));
|
||||
}
|
||||
|
||||
$config[$name] = is_array($test) ? $test : $value;
|
||||
}
|
||||
self::init_static();
|
||||
}
|
||||
return $config;
|
||||
return self::$configs[$app];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -300,7 +285,7 @@ class config
|
||||
* We use a reference here (no clone), as we no longer use egw_db::row() or egw_db::next_record()!
|
||||
*
|
||||
*/
|
||||
private static function init_db()
|
||||
private static function init_static()
|
||||
{
|
||||
if (is_object($GLOBALS['egw']->db))
|
||||
{
|
||||
@ -310,5 +295,24 @@ class config
|
||||
{
|
||||
config::$db = $GLOBALS['egw_setup']->db;
|
||||
}
|
||||
if (!(self::$configs = egw_cache::getInstance(__CLASS__, 'configs')))
|
||||
{
|
||||
self::$configs = array();
|
||||
foreach(self::$db->select(config::TABLE,'*',false,__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$app = $row['config_app'];
|
||||
$name = $row['config_name'];
|
||||
$value = $row['config_value'];
|
||||
|
||||
$test = @unserialize($value);
|
||||
if($test === false)
|
||||
{
|
||||
// manually retrieve the string lengths of the serialized array if unserialize failed
|
||||
$test = @unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.mb_strlen('$2','8bit').':\"$2\";'", $value));
|
||||
}
|
||||
self::$configs[$app][$name] = is_array($test) ? $test : $value;
|
||||
}
|
||||
egw_cache::setInstance(__CLASS__, 'configs', self::$configs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class egw extends egw_minimal
|
||||
exit;
|
||||
}
|
||||
// Set the DB's client charset if a system-charset is set
|
||||
$system_charset = $this->db->select(config::TABLE,'config_value',array(
|
||||
$system_charset = $GLOBALS['egw_info']['server']['system_charset'] = $this->db->select(config::TABLE,'config_value',array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => 'system_charset',
|
||||
),__LINE__,__FILE__)->fetchColumn();
|
||||
@ -127,11 +127,7 @@ class egw extends egw_minimal
|
||||
$this->db->Link_ID->SetCharSet($system_charset);
|
||||
}
|
||||
// load up the $GLOBALS['egw_info']['server'] array
|
||||
foreach($this->db->select(config::TABLE,'*',array('config_app' => 'phpgwapi'),__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value'];
|
||||
}
|
||||
//$GLOBALS['egw_info']['server'] = config::read('phpgwapi'); would unserialize arrays
|
||||
$GLOBALS['egw_info']['server'] += config::read('phpgwapi');
|
||||
|
||||
// if no server timezone set, use date_default_timezone_get() to determine it once
|
||||
// it fills to log with deprecated warnings under 5.3 otherwise
|
||||
|
@ -456,9 +456,11 @@ class egw_cache
|
||||
{
|
||||
if(!isset($GLOBALS['egw_info']['server'][$name]))
|
||||
{
|
||||
if (isset($GLOBALS['egw_setup']) && isset($GLOBALS['egw_setup']->db))
|
||||
if (isset($GLOBALS['egw_setup']) && isset($GLOBALS['egw_setup']->db) || $GLOBALS['egw']->db)
|
||||
{
|
||||
$GLOBALS['egw_info']['server'][$name] = $GLOBALS['egw_setup']->db->select(config::TABLE,'config_value',array(
|
||||
$db = $GLOBALS['egw']->db ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
|
||||
|
||||
$GLOBALS['egw_info']['server'][$name] = $db->select(config::TABLE,'config_value',array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => $name,
|
||||
),__LINE__,__FILE__)->fetchColumn();
|
||||
|
@ -1212,8 +1212,8 @@ class vfs_stream_wrapper implements iface_stream_wrapper
|
||||
{
|
||||
stream_register_wrapper(self::SCHEME,__CLASS__);
|
||||
|
||||
if ($GLOBALS['egw_info']['server']['vfs_fstab'] &&
|
||||
is_array($fstab = unserialize($GLOBALS['egw_info']['server']['vfs_fstab'])) && count($fstab))
|
||||
if (($fstab = $GLOBALS['egw_info']['server']['vfs_fstab']) &&
|
||||
(is_array($fstab) || is_array($fstab = unserialize($fstab))) && count($fstab))
|
||||
{
|
||||
self::$fstab = $fstab;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user