Quelques modifs sur la classe variables

This commit is contained in:
Alan Garcia 2014-03-28 14:28:25 +00:00
parent e578e4a230
commit 56fdcb8f9f
4 changed files with 31 additions and 15 deletions

View File

@ -11,8 +11,8 @@ Class m_export {
function export_conf(){
global $hooks;
$conf=$hooks->invoke('alternc_export_conf');
return $conf;
$config=$hooks->invoke('alternc_export_conf');
return $config;
}
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme

View File

@ -37,6 +37,7 @@ class m_variables {
var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN');
var $cache_variable_list = false;
var $replace_array = array();
var $cache_conf = array();
/**
*
@ -169,7 +170,7 @@ class m_variables {
// Replace needed vars
foreach ($variables as $vv => $hh) {
if (!isset($hh['value']) || !empty($hh['value'])) {
if (!isset($hh['value']) || empty($hh['value'])) {
continue;
}
$variables[$vv]['value'] = strtr($hh['value'], $this->replace_array );
@ -178,22 +179,20 @@ class m_variables {
if ($var && isset($variables[$var])) {
return $variables[$var];
} else {
return $variables;
return $variables;
}
}
/**
* Initialize the global $conf array if necessary
* Initialize the global conf
*
* @global $conf the global conf array
* @uses variable_init()
* @param boolean $force
*/
function variable_init_maybe($force=false) {
global $conf;
if ($force || !isset($conf)) {
if ($force || empty($this->cache_conf) ) {
$this->cache_variable_list = false;
$conf = $this->variable_init();
$this->cache_conf = $this->variable_init();
}
}
@ -209,19 +208,17 @@ class m_variables {
* and createit_comment value as comment
* @return mixed
* The value of the variable.
* @global array $conf
* A cache of the configuration.
*/
function variable_get($name, $default = null, $createit_comment = null, $type=null) {
global $conf;
$this->variable_init_maybe();
if (isset($conf[$name])) {
return $conf[$name]['value'];
if (isset($this->cache_conf[$name])) {
return $this->cache_conf[$name]['value'];
} elseif (!is_null($createit_comment)) {
$this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type);
}
return $default;
}
@ -256,6 +253,7 @@ class m_variables {
$sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id);
} else {
if ( empty($strata) ) {
$this->variable_init_maybe(true);
$err->raise('variables', _("Err: Missing strata when creating var"));
return false;
}
@ -412,7 +410,6 @@ class m_variables {
function variables_list() {
global $db;
if ( ! $this->cache_variable_list ) {
$result = $db->query('SELECT * FROM `variable`');
$arr_var=array();

View File

@ -137,6 +137,7 @@ class DB_system extends DB_Sql {
// Creates database from schema
// *********************************************
echo "*** In progress: importing mysql.sql\n";
$queryList = array(
"mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '",
"mysql -u $user --password='$password' -e 'CREATE DATABASE $database'",
@ -148,6 +149,8 @@ foreach ($queryList as $exec_command) {
throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,true));
}
}
echo "*** In progress: mysql.sql imported\n";
$db = new \DB_system($user,$database,$password);
$db->connect();
$cuid = 0;

View File

@ -73,6 +73,22 @@ class m_variablesTest extends AlterncTest
{
$result = $this->object->variable_get("phpunit");
$this->assertStringMatchesFormat("phpunit",$result);
/*
// Check old way
$this->object->variable_get('phpunit1', 'toto','plop');
$result = $this->object->variable_get('phpunit1');
$this->assertSame("toto",$result);
// New way
$this->object->variable_get('phpunit2', 'here','comment', array('desc'=>'Want a string','type'=>'string'));
$result = $this->object->variable_get('phpunit2');
$this->assertSame("here",$result);
$this->object->variable_get('phpunit3', array("ns1"=>'ns1.tld',"ip"=>"1.2.3.4"),'comment', array("ns1"=>array('desc'=>'ns name','type'=>'string'),"ip"=>array("desc"=>"here an ip", "type"=>"ip")));
$result = $this->object->variable_get('phpunit2');
$this->assertSame(array('ns1'=>"ns1.tld", "ip"=>"1.2.3.4"),$result);
*/
}
/**