From 56fdcb8f9f21c340a6aa90bcf1d0a69591942273 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Fri, 28 Mar 2014 14:28:25 +0000 Subject: [PATCH 1/3] Quelques modifs sur la classe variables --- bureau/class/m_export.php | 4 ++-- bureau/class/m_variables.php | 23 ++++++++----------- phpunit/bootstrap.php | 3 +++ .../tests/bureau/class/m_variablesTest.php | 16 +++++++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/bureau/class/m_export.php b/bureau/class/m_export.php index 187fef91..9289ea38 100644 --- a/bureau/class/m_export.php +++ b/bureau/class/m_export.php @@ -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 diff --git a/bureau/class/m_variables.php b/bureau/class/m_variables.php index 2662be1b..8aecf835 100644 --- a/bureau/class/m_variables.php +++ b/bureau/class/m_variables.php @@ -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(); diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index f9d459c9..cce42a6e 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -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; diff --git a/phpunit/tests/bureau/class/m_variablesTest.php b/phpunit/tests/bureau/class/m_variablesTest.php index 4f26d294..006f1983 100644 --- a/phpunit/tests/bureau/class/m_variablesTest.php +++ b/phpunit/tests/bureau/class/m_variablesTest.php @@ -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); +*/ } /** From 4daafc958006bc2316927b142e70f168ff01f13d Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Fri, 28 Mar 2014 14:36:10 +0000 Subject: [PATCH 2/3] Fix un test unitaire de variable --- phpunit/tests/bureau/class/m_variablesTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpunit/tests/bureau/class/m_variablesTest.php b/phpunit/tests/bureau/class/m_variablesTest.php index 006f1983..8e5774e0 100644 --- a/phpunit/tests/bureau/class/m_variablesTest.php +++ b/phpunit/tests/bureau/class/m_variablesTest.php @@ -62,8 +62,7 @@ class m_variablesTest extends AlterncTest public function testVariable_init_maybe() { $this->object->variable_init_maybe(); - global $conf; - $this->assertTrue(is_array($conf)); + $this->assertTrue( (is_array($this->object->cache_conf) && !empty($this->object->cache_conf)) ); } /** From 5409257c77baf5b2b00b273d501a25436dcdb50f Mon Sep 17 00:00:00 2001 From: fufroma Date: Fri, 28 Mar 2014 16:01:18 +0100 Subject: [PATCH 3/3] Commentaires sur m_dom --- bureau/class/m_dom.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 46c45c26..7838da80 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -100,6 +100,9 @@ class m_dom { return $t; } + /** + * @param string $fqdn + */ function get_sub_domain_id_and_member_by_name($fqdn) { global $db, $err, $cuid; $err->log("dom", "get_sub_domain_by_name"); @@ -219,6 +222,9 @@ class m_dom { return $val; } + /** + * @param string $zone + */ function import_manual_dns_entry($zone, $domain, $detect_redirect = true, $save = false) { global $cuid, $err; $err->log("dom", "import_manual_dns_entry"); @@ -464,6 +470,10 @@ class m_dom { // Take an URL, and return FALSE is there is no redirection, // and the target URL if there is one (HTTP CODE 301 & 302) // CURL is needed + + /** + * @param string $url + */ function is_it_a_redirect($url) { try { $params = array('http' => array( @@ -667,7 +677,6 @@ class m_dom { *

Chaque classe peut définir une fonction add_dom($dom) qui sera * appellée lors de l'installation d'un nouveau domaine.

* - * @param string $dom nom fqdn du domaine é installer * @param boolean $dns 1 ou 0 pour héberger le DNS du domaine ou pas. * @param boolean $noerase 1 ou 0 pour rendre le domaine inamovible ou non * @param boolean $force 1 ou 0, si 1, n'effectue pas les tests de DNS. @@ -792,6 +801,9 @@ class m_dom { return true; } + /** + * @param string $domain + */ function create_default_subdomains($domain, $target_domain = "") { global $db, $err; $err->log("dom", "create_default_subdomains", $domain); @@ -1057,6 +1069,7 @@ class m_dom { * $ref_domaine est le domaine avec lequel on veux comparer les MX * si $ref_domaine == '', on prend les MX par default * + * @param string $domaine */ function checkmx($domaine, $ref_domain = '') { global $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX; @@ -1180,7 +1193,7 @@ class m_dom { * Retourne TOUTES les infos d'un sous domaine du compte courant. * * @param integer sub_domain_id id du subdomain - * @return arrray Retourne un tableau associatif contenant les + * @return array Retourne un tableau associatif contenant les * informations du sous-domaine demandé.
      *  $r["name"]= nom du sous-domaine (NON-complet)
      *  $r["dest"]= Destination (url, ip, local ...)
@@ -1218,6 +1231,10 @@ class m_dom {
 
 // get_sub_domain_all
 
+    /**
+     * @param integer $type
+     * @param string $value
+     */
     function check_type_value($type, $value) {
         global $db, $err, $cuid;
 
@@ -1333,10 +1350,8 @@ class m_dom {
      * Note : TODO : vérification de concordance de $dest
* * @param string $dom Domaine dont on souhaite modifier/ajouter un sous domaine - * @param string $subk Sous domaine é modifier / créer + * @param string $sub Sous domaine é modifier / créer * @param integer $type Type de sous-domaine (local, ip, url ...) - * @param string $action Action : vaut "add" ou "edit" selon que l'on - * Crée (add) ou Modifie (edit) le sous-domaine * @param string $dest Destination du sous-domaine, dépend de la valeur * de $type (url, ip, dossier...) * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. @@ -1428,8 +1443,6 @@ class m_dom { /** * Supprime le sous-domaine demandé * - * @param string $dom Domaine dont on souhaite supprimer un sous-domaine - * @param string $sub Sous-domaine que l'on souhaite supprimer * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * */ @@ -1453,6 +1466,9 @@ class m_dom { // del_sub_domain + /** + * @param integer $dom_id + */ function set_ttl($dom_id, $ttl) { global $err; $err->log("dom", "set_ttl", "$dom_id / $ttl"); @@ -1479,7 +1495,7 @@ class m_dom { * TRUE sinon. * */ - function edit_domain($dom, $dns, $gesmx, $force = 0, $ttl = 86400) { + function edit_domain($dom, $dns, $gesmx, $force = false, $ttl = 86400) { global $db, $err, $L_MX, $classes, $cuid, $hooks; $err->log("dom", "edit_domain", $dom . "/" . $dns . "/" . $gesmx); // Locked ? @@ -2107,6 +2123,9 @@ order by return true; } + /** + * @param string $dns_action + */ function set_dns_action($domain, $dns_action) { global $db; $db->query("UPDATE domaines SET dns_action='" . mysql_escape_string($dns_action) . "' WHERE domaine='" . mysql_escape_string($domain) . "'; ");