| Conditions | 20 |
| Paths | 2885 |
| Total Lines | 150 |
| Code Lines | 99 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 19 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db){ |
||
| 20 | global $spip_version_base; |
||
| 21 | |||
| 22 | // Prefix des tables : |
||
| 23 | // contrairement a ce qui est dit dans le message (trop strict mais c'est |
||
| 24 | // pour notre bien), on va tolerer les chiffres en plus des minuscules |
||
| 25 | // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
||
| 26 | // a partir de ce qui est envoye a l'installation |
||
| 27 | if (!defined('_INSTALL_TABLE_PREFIX')) { |
||
| 28 | $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
||
| 29 | ? $GLOBALS['table_prefix'] |
||
| 30 | : trim(preg_replace(',[^a-z0-9],','',strtolower(_request('tprefix')))); |
||
| 31 | // S'il est vide on remet spip |
||
| 32 | if (!$table_prefix) |
||
| 33 | $table_prefix = 'spip'; |
||
| 34 | } else { |
||
| 35 | $table_prefix = _INSTALL_TABLE_PREFIX; |
||
| 36 | } |
||
| 37 | |||
| 38 | $GLOBALS['connexions'][$server_db] |
||
| 39 | = spip_connect_db($adresse_db, 0, $login_db, $pass_db, '', $server_db); |
||
| 40 | |||
| 41 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
||
| 42 | = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
||
| 43 | |||
| 44 | $fquery = sql_serveur('query', $server_db); |
||
| 45 | if ($choix_db == "new_spip") { |
||
| 46 | $re = ',^[a-z_][a-z_0-9-]*$,i'; |
||
| 47 | if (preg_match($re, $sel_db)) |
||
| 48 | sql_create_base($sel_db, $server_db); |
||
| 49 | else { |
||
| 50 | $re = "Le nom de la base doit correspondre a $re"; |
||
| 51 | spip_log($re); |
||
| 52 | return "<p>"._T("avis_connexion_erreur_nom_base")."</p><!--\n$re\n-->"; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | // on rejoue la connexion apres avoir teste si il faut lui indiquer |
||
| 57 | // un sql_mode |
||
| 58 | install_mode_appel($server_db, false); |
||
| 59 | $GLOBALS['connexions'][$server_db] |
||
| 60 | = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
||
| 61 | |||
| 62 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
||
| 63 | = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
||
| 64 | |||
| 65 | // Completer le tableau decrivant la connexion |
||
| 66 | |||
| 67 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
||
| 68 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
||
| 69 | |||
| 70 | $old = sql_showbase($table_prefix . "_meta", $server_db); |
||
| 71 | if ($old) $old = sql_fetch($old, $server_db); |
||
| 72 | if (!$old) { |
||
|
|
|||
| 73 | |||
| 74 | // Si possible, demander au serveur d'envoyer les textes |
||
| 75 | // dans le codage std de SPIP, |
||
| 76 | $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
||
| 77 | |||
| 78 | if ($charset) { |
||
| 79 | sql_set_charset($charset['charset'], $server_db); |
||
| 80 | $GLOBALS['meta']['charset_sql_base'] = |
||
| 81 | $charset['charset']; |
||
| 82 | $GLOBALS['meta']['charset_collation_sql_base'] = |
||
| 83 | $charset['collation']; |
||
| 84 | $GLOBALS['meta']['charset_sql_connexion'] = |
||
| 85 | $charset['charset']; |
||
| 86 | $charsetbase = $charset['charset']; |
||
| 87 | } else { |
||
| 88 | spip_log(_DEFAULT_CHARSET . " inconnu du serveur SQL"); |
||
| 89 | $charsetbase = 'standard'; |
||
| 90 | } |
||
| 91 | spip_log("Creation des tables. Codage $charsetbase"); |
||
| 92 | creer_base($server_db); // AT LAST |
||
| 93 | // memoriser avec quel charset on l'a creee |
||
| 94 | |||
| 95 | if ($charset) { |
||
| 96 | $t = array('nom' => 'charset_sql_base', |
||
| 97 | 'valeur' => $charset['charset'], |
||
| 98 | 'impt' => 'non'); |
||
| 99 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 100 | $t['nom'] = 'charset_collation_sql_base'; |
||
| 101 | $t['valeur'] = $charset['collation']; |
||
| 102 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 103 | $t['nom'] = 'charset_sql_connexion'; |
||
| 104 | $t['valeur'] = $charset['charset']; |
||
| 105 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 106 | } |
||
| 107 | $t = array('nom' => 'version_installee', |
||
| 108 | 'valeur' => $spip_version_base, |
||
| 109 | 'impt' => 'non'); |
||
| 110 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 111 | $t['nom'] = 'nouvelle_install'; |
||
| 112 | $t['valeur'] = 1; |
||
| 113 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 114 | // positionner la langue par defaut du site si un cookie de lang a ete mis |
||
| 115 | if (isset($_COOKIE['spip_lang_ecrire'])){ |
||
| 116 | @sql_insertq('spip_meta', array('nom'=>'langue_site','valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
||
| 117 | } |
||
| 118 | } else { |
||
| 119 | |||
| 120 | // pour recreer les tables disparues au besoin |
||
| 121 | spip_log("Table des Meta deja la. Verification des autres."); |
||
| 122 | creer_base($server_db); |
||
| 123 | $fupdateq = sql_serveur('updateq', $server_db); |
||
| 124 | |||
| 125 | $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
||
| 126 | |||
| 127 | if ($r) $r = sql_fetch($r, $server_db); |
||
| 128 | $version_installee = !$r ? 0 : (double) $r['valeur']; |
||
| 129 | if (!$version_installee OR ($spip_version_base < $version_installee)) { |
||
| 130 | $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
||
| 131 | spip_log("nouvelle version installee: $spip_version_base"); |
||
| 132 | } |
||
| 133 | // eliminer la derniere operation d'admin mal terminee |
||
| 134 | // notamment la mise a jour |
||
| 135 | @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
||
| 136 | } |
||
| 137 | |||
| 138 | $ligne_rappel = install_mode_appel($server_db); |
||
| 139 | |||
| 140 | $result_ok = @$fquery("SELECT COUNT(*) FROM spip_meta", $server_db); |
||
| 141 | if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
||
| 142 | |||
| 143 | if ($chmod_db) { |
||
| 144 | install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
||
| 145 | } |
||
| 146 | |||
| 147 | if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
||
| 148 | list(,$adresse_db, $port) = $r; |
||
| 149 | else $port = ''; |
||
| 150 | |||
| 151 | // si ce fichier existe a cette etape c'est qu'il provient |
||
| 152 | // d'une installation qui ne l'a pas cree correctement. |
||
| 153 | // Le supprimer pour que _FILE_CONNECT_TMP prime. |
||
| 154 | |||
| 155 | if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) |
||
| 156 | spip_unlink(_FILE_CONNECT); |
||
| 157 | |||
| 158 | install_fichier_connexion(_FILE_CONNECT_TMP, |
||
| 159 | $ligne_rappel |
||
| 160 | . install_connexion($adresse_db, |
||
| 161 | $port, |
||
| 162 | $login_db, |
||
| 163 | $pass_db, |
||
| 164 | $sel_db, |
||
| 165 | $server_db, |
||
| 166 | $table_prefix)); |
||
| 167 | return ''; |
||
| 168 | } |
||
| 169 | |||
| 323 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.