changed config-class to only write config-values if they are changed or new. This should give a better performance and prefents cases where the complete config got lost, because of a concurrent access.

This commit is contained in:
Ralf Becker 2003-11-03 14:25:50 +00:00
parent 5d922e91f1
commit 737461af74

View File

@ -39,6 +39,10 @@
$this->appname = $appname;
}
/*!
@function read_repository
@abstract reads the whole repository for $this->appname, appname has to be set via the constructor
*/
function read_repository()
{
$this->db->query("select * from phpgw_config where config_app='" . $this->appname . "'",__LINE__,__FILE__);
@ -56,40 +60,86 @@
}
}
/*!
@function save_repository
@abstract updates the whole repository for $this->appname, you have to call read_repository() before (!)
*/
function save_repository()
{
$config_data = $this->config_data;
if ($config_data)
if ($this->config_data)
{
$this->db->lock(array('phpgw_config','phpgw_app_sessions'));
$this->db->query("delete from phpgw_config where config_app='" . $this->appname . "'",__LINE__,__FILE__);
if($this->appname == 'phpgwapi')
{
$this->db->query("delete from phpgw_app_sessions where sessionid = '0' and loginid = '0' and app = '".$this->appname."' and location = 'config'",__LINE__,__FILE__);
}
while (list($name,$value) = each($config_data))
foreach($this->config_data as $name => $value)
{
if(is_array($value))
{
$value = serialize($value);
}
$name = addslashes($name);
$value = addslashes($value);
$this->db->query("delete from phpgw_config where config_name='" . $name . "'",__LINE__,__FILE__);
$query = "insert into phpgw_config (config_app,config_name,config_value) "
. "values ('" . $this->appname . "','" . $name . "','" . $value . "')";
$this->db->query($query,__LINE__,__FILE__);
$this->save_value($name,$value);
}
$this->db->unlock();
}
}
/*!
@function save_value
@abstract updates or insert a single config-value
@param $name string name of the config-value
@param $value mixed content
@param $app string app-name, defaults to $this->appname set via the constructor
*/
function save_value($name,$value,$app=False)
{
//echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n";
if (!$app || $app == $this->appname)
{
$app = $this->appname;
$this->config_data[$name] = $value;
}
$name = $this->db->db_addslashes($name);
$this->db->query($sql="select * from phpgw_config where config_app='$app' AND config_name='$name'",__LINE__,__FILE__);
if ($this->db->next_record())
{
$value_read = @unserialize($this->db->f('config_value'));
if (!$value_read)
{
$value_read = $this->db->f('config_value');
}
if ($value_read == $value)
{
return True; // no change ==> exit
}
$update = True;
}
//echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n";
if(is_array($value))
{
$value = serialize($value);
}
$value = $this->db->db_addslashes($value);
$query = $update ? "UPDATE phpgw_config SET config_value='$value' WHERE config_app='$app' AND config_name='$name'" :
"INSERT INTO phpgw_config (config_app,config_name,config_value) VALUES ('$app','$name','$value')";
return $this->db->query($query,__LINE__,__FILE__);
}
/*!
@function delete_repository
@abstract deletes the whole repository for $this->appname, appname has to be set via the constructor
*/
function delete_repository()
{
$this->db->query("delete from phpgw_config where config_app='" . $this->appname . "'",__LINE__,__FILE__);
}
/*!
@function value
@abstract sets a single value in the repositry, you need to call save_repository after
@param $variable_name string name of the config
@param $variable_data mixed the content
*/
function value($variable_name,$variable_data)
{
$this->config_data[$variable_name] = $variable_data;