| Conditions | 23 |
| Paths | 12820 |
| Total Lines | 164 |
| Code Lines | 110 |
| Lines | 10 |
| Ratio | 6.1 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | View Code Duplication | 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 | if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
||
| 39 | list(,$adresse_db, $port) = $r; |
||
| 40 | else $port = ''; |
||
| 41 | |||
| 42 | $GLOBALS['connexions'][$server_db] |
||
| 43 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
||
| 44 | |||
| 45 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
||
| 46 | = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
||
| 47 | |||
| 48 | $fquery = sql_serveur('query', $server_db); |
||
| 49 | if ($choix_db == "new_spip") { |
||
| 50 | $re = ',^[a-z_][a-z_0-9-]*$,i'; |
||
| 51 | if (preg_match($re, $sel_db)) { |
||
| 52 | $ok = sql_create_base($sel_db, $server_db); |
||
| 53 | if (!$ok) { |
||
| 54 | $re = "Impossible de creer la base $re"; |
||
| 55 | spip_log($re); |
||
| 56 | return "<p>"._T("avis_connexion_erreur_creer_base")."</p><!--\n$re\n-->"; |
||
| 57 | } |
||
| 58 | } else { |
||
| 59 | $re = "Le nom de la base doit correspondre a $re"; |
||
| 60 | spip_log($re); |
||
| 61 | return "<p>"._T("avis_connexion_erreur_nom_base")."</p><!--\n$re\n-->"; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | // on rejoue la connexion apres avoir teste si il faut lui indiquer |
||
| 66 | // un sql_mode |
||
| 67 | install_mode_appel($server_db, false); |
||
| 68 | $GLOBALS['connexions'][$server_db] |
||
| 69 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
||
| 70 | |||
| 71 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
||
| 72 | = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
||
| 73 | |||
| 74 | // Completer le tableau decrivant la connexion |
||
| 75 | |||
| 76 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
||
| 77 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
||
| 78 | |||
| 79 | $old = sql_showbase($table_prefix . "_meta", $server_db); |
||
| 80 | if ($old) $old = sql_fetch($old, $server_db); |
||
| 81 | if (!$old) { |
||
| 82 | |||
| 83 | // Si possible, demander au serveur d'envoyer les textes |
||
| 84 | // dans le codage std de SPIP, |
||
| 85 | $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
||
| 86 | |||
| 87 | if ($charset) { |
||
| 88 | sql_set_charset($charset['charset'], $server_db); |
||
| 89 | $GLOBALS['meta']['charset_sql_base'] = |
||
| 90 | $charset['charset']; |
||
| 91 | $GLOBALS['meta']['charset_collation_sql_base'] = |
||
| 92 | $charset['collation']; |
||
| 93 | $GLOBALS['meta']['charset_sql_connexion'] = |
||
| 94 | $charset['charset']; |
||
| 95 | $charsetbase = $charset['charset']; |
||
| 96 | } else { |
||
| 97 | spip_log(_DEFAULT_CHARSET . " inconnu du serveur SQL"); |
||
| 98 | $charsetbase = 'standard'; |
||
| 99 | } |
||
| 100 | spip_log("Creation des tables. Codage $charsetbase"); |
||
| 101 | creer_base($server_db); // AT LAST |
||
| 102 | // memoriser avec quel charset on l'a creee |
||
| 103 | |||
| 104 | if ($charset) { |
||
| 105 | $t = array('nom' => 'charset_sql_base', |
||
| 106 | 'valeur' => $charset['charset'], |
||
| 107 | 'impt' => 'non'); |
||
| 108 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 109 | $t['nom'] = 'charset_collation_sql_base'; |
||
| 110 | $t['valeur'] = $charset['collation']; |
||
| 111 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 112 | $t['nom'] = 'charset_sql_connexion'; |
||
| 113 | $t['valeur'] = $charset['charset']; |
||
| 114 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 115 | } |
||
| 116 | $t = array('nom' => 'version_installee', |
||
| 117 | 'valeur' => $spip_version_base, |
||
| 118 | 'impt' => 'non'); |
||
| 119 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 120 | $t['nom'] = 'nouvelle_install'; |
||
| 121 | $t['valeur'] = 1; |
||
| 122 | @sql_insertq('spip_meta', $t, '', $server_db); |
||
| 123 | // positionner la langue par defaut du site si un cookie de lang a ete mis |
||
| 124 | if (isset($_COOKIE['spip_lang_ecrire'])){ |
||
| 125 | @sql_insertq('spip_meta', array('nom'=>'langue_site','valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
||
| 126 | } |
||
| 127 | } else { |
||
| 128 | |||
| 129 | // pour recreer les tables disparues au besoin |
||
| 130 | spip_log("Table des Meta deja la. Verification des autres."); |
||
| 131 | creer_base($server_db); |
||
| 132 | creer_base_types_doc($server_db); |
||
| 133 | $fupdateq = sql_serveur('updateq', $server_db); |
||
| 134 | |||
| 135 | $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
||
| 136 | |||
| 137 | if ($r) $r = sql_fetch($r, $server_db); |
||
| 138 | $version_installee = !$r ? 0 : (double) $r['valeur']; |
||
| 139 | if (!$version_installee OR ($spip_version_base < $version_installee)) { |
||
| 140 | $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
||
| 141 | spip_log("nouvelle version installee: $spip_version_base"); |
||
| 142 | } |
||
| 143 | // eliminer la derniere operation d'admin mal terminee |
||
| 144 | // notamment la mise a jour |
||
| 145 | @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
||
| 146 | } |
||
| 147 | |||
| 148 | // recuperer le charset de la connexion dans les meta |
||
| 149 | $charset = ''; |
||
| 150 | $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
||
| 151 | if ($r) $r = sql_fetch($r, $server_db); |
||
| 152 | if ($r) $charset = $r['valeur']; |
||
| 153 | |||
| 154 | $ligne_rappel = install_mode_appel($server_db); |
||
| 155 | |||
| 156 | $result_ok = @$fquery("SELECT COUNT(*) FROM spip_meta", $server_db); |
||
| 157 | if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
||
| 158 | |||
| 159 | if ($chmod_db) { |
||
| 160 | install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
||
| 161 | } |
||
| 162 | |||
| 163 | // si ce fichier existe a cette etape c'est qu'il provient |
||
| 164 | // d'une installation qui ne l'a pas cree correctement. |
||
| 165 | // Le supprimer pour que _FILE_CONNECT_TMP prime. |
||
| 166 | |||
| 167 | if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) |
||
| 168 | spip_unlink(_FILE_CONNECT); |
||
| 169 | |||
| 170 | install_fichier_connexion(_FILE_CONNECT_TMP, |
||
| 171 | $ligne_rappel |
||
| 172 | . install_connexion($adresse_db, |
||
| 173 | $port, |
||
| 174 | $login_db, |
||
| 175 | $pass_db, |
||
| 176 | $sel_db, |
||
| 177 | $server_db, |
||
| 178 | $table_prefix, |
||
| 179 | '', |
||
| 180 | $charset)); |
||
| 181 | return ''; |
||
| 182 | } |
||
| 183 | |||
| 337 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.