Commit 56fdcb8f authored by Alan Garcia's avatar Alan Garcia

Quelques modifs sur la classe variables

parent e578e4a2
...@@ -11,8 +11,8 @@ Class m_export { ...@@ -11,8 +11,8 @@ Class m_export {
function export_conf(){ function export_conf(){
global $hooks; global $hooks;
$conf=$hooks->invoke('alternc_export_conf'); $config=$hooks->invoke('alternc_export_conf');
return $conf; return $config;
} }
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme /** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme
......
...@@ -37,6 +37,7 @@ class m_variables { ...@@ -37,6 +37,7 @@ class m_variables {
var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN'); var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN');
var $cache_variable_list = false; var $cache_variable_list = false;
var $replace_array = array(); var $replace_array = array();
var $cache_conf = array();
/** /**
* *
...@@ -169,7 +170,7 @@ class m_variables { ...@@ -169,7 +170,7 @@ class m_variables {
// Replace needed vars // Replace needed vars
foreach ($variables as $vv => $hh) { foreach ($variables as $vv => $hh) {
if (!isset($hh['value']) || !empty($hh['value'])) { if (!isset($hh['value']) || empty($hh['value'])) {
continue; continue;
} }
$variables[$vv]['value'] = strtr($hh['value'], $this->replace_array ); $variables[$vv]['value'] = strtr($hh['value'], $this->replace_array );
...@@ -178,22 +179,20 @@ class m_variables { ...@@ -178,22 +179,20 @@ class m_variables {
if ($var && isset($variables[$var])) { if ($var && isset($variables[$var])) {
return $variables[$var]; return $variables[$var];
} else { } 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() * @uses variable_init()
* @param boolean $force * @param boolean $force
*/ */
function variable_init_maybe($force=false) { function variable_init_maybe($force=false) {
global $conf; if ($force || empty($this->cache_conf) ) {
if ($force || !isset($conf)) {
$this->cache_variable_list = false; $this->cache_variable_list = false;
$conf = $this->variable_init(); $this->cache_conf = $this->variable_init();
} }
} }
...@@ -209,19 +208,17 @@ class m_variables { ...@@ -209,19 +208,17 @@ class m_variables {
* and createit_comment value as comment * and createit_comment value as comment
* @return mixed * @return mixed
* The value of the variable. * The value of the variable.
* @global array $conf
* A cache of the configuration.
*/ */
function variable_get($name, $default = null, $createit_comment = null, $type=null) { function variable_get($name, $default = null, $createit_comment = null, $type=null) {
global $conf;
$this->variable_init_maybe(); $this->variable_init_maybe();
if (isset($conf[$name])) { if (isset($this->cache_conf[$name])) {
return $conf[$name]['value']; return $this->cache_conf[$name]['value'];
} elseif (!is_null($createit_comment)) { } elseif (!is_null($createit_comment)) {
$this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type); $this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type);
} }
return $default; return $default;
} }
...@@ -256,6 +253,7 @@ class m_variables { ...@@ -256,6 +253,7 @@ class m_variables {
$sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id); $sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id);
} else { } else {
if ( empty($strata) ) { if ( empty($strata) ) {
$this->variable_init_maybe(true);
$err->raise('variables', _("Err: Missing strata when creating var")); $err->raise('variables', _("Err: Missing strata when creating var"));
return false; return false;
} }
...@@ -412,7 +410,6 @@ class m_variables { ...@@ -412,7 +410,6 @@ class m_variables {
function variables_list() { function variables_list() {
global $db; global $db;
if ( ! $this->cache_variable_list ) { if ( ! $this->cache_variable_list ) {
$result = $db->query('SELECT * FROM `variable`'); $result = $db->query('SELECT * FROM `variable`');
$arr_var=array(); $arr_var=array();
......
...@@ -137,6 +137,7 @@ class DB_system extends DB_Sql { ...@@ -137,6 +137,7 @@ class DB_system extends DB_Sql {
// Creates database from schema // Creates database from schema
// ********************************************* // *********************************************
echo "*** In progress: importing mysql.sql\n";
$queryList = array( $queryList = array(
"mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '", "mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '",
"mysql -u $user --password='$password' -e 'CREATE DATABASE $database'", "mysql -u $user --password='$password' -e 'CREATE DATABASE $database'",
...@@ -148,6 +149,8 @@ foreach ($queryList as $exec_command) { ...@@ -148,6 +149,8 @@ foreach ($queryList as $exec_command) {
throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,true)); 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 = new \DB_system($user,$database,$password);
$db->connect(); $db->connect();
$cuid = 0; $cuid = 0;
......
...@@ -73,6 +73,22 @@ class m_variablesTest extends AlterncTest ...@@ -73,6 +73,22 @@ class m_variablesTest extends AlterncTest
{ {
$result = $this->object->variable_get("phpunit"); $result = $this->object->variable_get("phpunit");
$this->assertStringMatchesFormat("phpunit",$result); $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);
*/
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment