| Conditions | 41 |
| Paths | > 20000 |
| Total Lines | 287 |
| Code Lines | 165 |
| Lines | 63 |
| Ratio | 21.95 % |
| 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 |
||
| 15 | function v019_pre193($version_installee, $version_cible) |
||
| 16 | { |
||
| 17 | // Syndication : ajout de l'option resume=oui/non et de la langue |
||
| 18 | if (upgrade_vers(1.901, $version_installee, $version_cible)) { |
||
| 19 | spip_query("ALTER TABLE spip_syndic ADD `resume` VARCHAR(3) DEFAULT 'oui'"); |
||
| 20 | spip_query("ALTER TABLE spip_syndic_articles ADD `lang` VARCHAR(10) DEFAULT '' NOT NULL"); |
||
| 21 | maj_version(1.901); |
||
| 22 | } |
||
| 23 | |||
| 24 | // Syndication : ajout de source, url_source, tags |
||
| 25 | View Code Duplication | if (upgrade_vers(1.902, $version_installee, $version_cible)) { |
|
|
|
|||
| 26 | spip_query("ALTER TABLE spip_syndic_articles ADD `url_source` TINYTEXT DEFAULT '' NOT NULL"); |
||
| 27 | spip_query("ALTER TABLE spip_syndic_articles ADD `source` TINYTEXT DEFAULT '' NOT NULL"); |
||
| 28 | spip_query("ALTER TABLE spip_syndic_articles ADD `tags` TEXT DEFAULT '' NOT NULL"); |
||
| 29 | maj_version(1.902); |
||
| 30 | } |
||
| 31 | |||
| 32 | // URLs propres des sites (sait-on jamais) |
||
| 33 | // + oubli des KEY url_propre sur les auteurs si installation neuve |
||
| 34 | View Code Duplication | if (upgrade_vers(1.903, $version_installee, $version_cible)) { |
|
| 35 | spip_query("ALTER TABLE spip_syndic ADD `url_propre` VARCHAR(255) NOT NULL"); |
||
| 36 | spip_query("ALTER TABLE spip_syndic ADD INDEX `url_propre` (`url_propre`)"); |
||
| 37 | spip_query("ALTER TABLE spip_auteurs ADD INDEX `url_propre` (`url_propre`)"); |
||
| 38 | maj_version(1.903); |
||
| 39 | } |
||
| 40 | |||
| 41 | // suppression des anciennes tables temporaires des visites |
||
| 42 | // (maintenant stockees sous forme de fichiers) |
||
| 43 | if (upgrade_vers(1.904, $version_installee, $version_cible)) { |
||
| 44 | spip_query("DROP TABLE IF EXISTS spip_visites_temp"); |
||
| 45 | spip_query("DROP TABLE IF EXISTS spip_referers_temp"); |
||
| 46 | maj_version(1.904); |
||
| 47 | } |
||
| 48 | |||
| 49 | // fusion des 10 tables index en une seule |
||
| 50 | // pour fonctions futures evoluees du moteur de recherche |
||
| 51 | if (upgrade_vers(1.905, $version_installee, $version_cible)) { |
||
| 52 | // agrandir le champ "valeur" de spip_meta pour pouvoir y stocker |
||
| 53 | // des choses plus sympa |
||
| 54 | spip_query("ALTER TABLE spip_meta DROP INDEX `valeur`"); |
||
| 55 | spip_query("ALTER TABLE spip_meta CHANGE `valeur` `valeur` TEXT"); |
||
| 56 | // table des correspondances table->id_table |
||
| 57 | $liste_tables = array(); |
||
| 58 | $liste_tables[1]='spip_articles'; |
||
| 59 | $liste_tables[2]='spip_auteurs'; |
||
| 60 | $liste_tables[3]='spip_breves'; |
||
| 61 | $liste_tables[4]='spip_documents'; |
||
| 62 | $liste_tables[5]='spip_forum'; |
||
| 63 | $liste_tables[6]='spip_mots'; |
||
| 64 | $liste_tables[7]='spip_rubriques'; |
||
| 65 | $liste_tables[8]='spip_signatures'; |
||
| 66 | $liste_tables[9]='spip_syndic'; |
||
| 67 | |||
| 68 | ecrire_meta('index_table', serialize($liste_tables)); |
||
| 69 | |||
| 70 | ## devenu inutile car suppression totale de l'indexation |
||
| 71 | /* |
||
| 72 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_article` as id_objet,'1' as id_table FROM spip_index_articles"); |
||
| 73 | spip_query("DROP TABLE IF EXISTS spip_index_articles"); |
||
| 74 | |||
| 75 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_auteur` as id_objet,'2' as id_table FROM spip_index_auteurs"); |
||
| 76 | spip_query("DROP TABLE IF EXISTS spip_index_auteurs"); |
||
| 77 | |||
| 78 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_breve` as id_objet,'3' as id_table FROM spip_index_breves"); |
||
| 79 | spip_query("DROP TABLE IF EXISTS spip_index_breves"); |
||
| 80 | |||
| 81 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_document` as id_objet,'4' as id_table FROM spip_index_documents"); |
||
| 82 | spip_query("DROP TABLE IF EXISTS spip_index_documents"); |
||
| 83 | |||
| 84 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_forum` as id_objet,'5' as id_table FROM spip_index_forum"); |
||
| 85 | spip_query("DROP TABLE IF EXISTS spip_index_forum"); |
||
| 86 | |||
| 87 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_mot` as id_objet,'6' as id_table FROM spip_index_mots"); |
||
| 88 | spip_query("DROP TABLE IF EXISTS spip_index_mots"); |
||
| 89 | |||
| 90 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_rubrique` as id_objet,'7' as id_table FROM spip_index_rubriques"); |
||
| 91 | spip_query("DROP TABLE IF EXISTS spip_index_rubriques"); |
||
| 92 | |||
| 93 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_signature` as id_objet,'8' as id_table FROM spip_index_signatures"); |
||
| 94 | spip_query("DROP TABLE IF EXISTS spip_index_signatures"); |
||
| 95 | |||
| 96 | spip_query("INSERT INTO spip_index (`hash`,`points`,`id_objet`,`id_table`) SELECT `hash`,`points`,`id_syndic` as id_objet,'9' as `id_table FROM spip_index_syndic"); |
||
| 97 | spip_query("DROP TABLE IF EXISTS spip_index_syndic"); |
||
| 98 | */ |
||
| 99 | maj_version(1.905); |
||
| 100 | } |
||
| 101 | |||
| 102 | |||
| 103 | // cette table est desormais geree par le plugin "podcast_client", on la |
||
| 104 | // supprime si le plugin n'est pas active ; risque inherent a l'utilisation |
||
| 105 | // de versions alpha :-) |
||
| 106 | if (upgrade_vers(1.906, $version_installee, $version_cible)) { |
||
| 107 | if (!@in_array('podcast_client', $GLOBALS['plugins'])) { |
||
| 108 | spip_query("DROP TABLE spip_documents_syndic"); |
||
| 109 | } |
||
| 110 | maj_version(1.906); |
||
| 111 | } |
||
| 112 | if (upgrade_vers(1.907, $version_installee, $version_cible)) { |
||
| 113 | spip_query("ALTER TABLE spip_forum ADD INDEX `idx` (`idx`)"); |
||
| 114 | maj_version(1.907); |
||
| 115 | } |
||
| 116 | // Oups ! on stockait les tags de syndication sous la forme rel="category" |
||
| 117 | // au lieu de rel="directory" - http://microformats.org/wiki/rel-directory |
||
| 118 | if (upgrade_vers(1.908, $version_installee, $version_cible)) { |
||
| 119 | spip_query("UPDATE spip_syndic_articles SET `tags` = REPLACE(`tags`, 'rel=\"category\">', 'rel=\"directory\">') WHERE `tags` like '%category%'"); |
||
| 120 | maj_version(1.908); |
||
| 121 | } |
||
| 122 | View Code Duplication | if (upgrade_vers(1.909, $version_installee, $version_cible)) { |
|
| 123 | spip_query("ALTER IGNORE TABLE spip_mots_articles ADD PRIMARY KEY (`id_article`, `id_mot`)"); |
||
| 124 | spip_query("ALTER IGNORE TABLE spip_mots_breves ADD PRIMARY KEY (`id_breve`, `id_mot`)"); |
||
| 125 | spip_query("ALTER IGNORE TABLE spip_mots_rubriques ADD PRIMARY KEY (`id_rubrique`, `id_mot`)"); |
||
| 126 | spip_query("ALTER IGNORE TABLE spip_mots_syndic ADD PRIMARY KEY (`id_syndic`, `id_mot`)"); |
||
| 127 | spip_query("ALTER IGNORE TABLE spip_mots_documents ADD PRIMARY KEY (`id_document`, `id_mot`)"); |
||
| 128 | spip_query("ALTER IGNORE TABLE spip_mots_forum ADD PRIMARY KEY (`id_forum`, `id_mot`)"); |
||
| 129 | maj_version(1.909); |
||
| 130 | } |
||
| 131 | |||
| 132 | View Code Duplication | if (upgrade_vers(1.910, $version_installee, $version_cible)) { |
|
| 133 | spip_query("ALTER IGNORE TABLE spip_auteurs_articles ADD PRIMARY KEY (`id_auteur`, `id_article`)"); |
||
| 134 | spip_query("ALTER IGNORE TABLE spip_auteurs_rubriques ADD PRIMARY KEY (`id_auteur`, `id_rubrique`)"); |
||
| 135 | spip_query("ALTER IGNORE TABLE spip_auteurs_messages ADD PRIMARY KEY (`id_auteur`, `id_message`)"); |
||
| 136 | maj_version(1.910); |
||
| 137 | } |
||
| 138 | |||
| 139 | View Code Duplication | if (upgrade_vers(1.911, $version_installee, $version_cible)) { |
|
| 140 | |||
| 141 | spip_query("ALTER IGNORE TABLE spip_auteurs_articles DROP INDEX `id_auteur`"); |
||
| 142 | spip_query("ALTER IGNORE TABLE spip_auteurs_rubriques DROP INDEX `id_auteur`"); |
||
| 143 | spip_query("ALTER IGNORE TABLE spip_auteurs_messages DROP INDEX `id_auteur`"); |
||
| 144 | spip_query("ALTER IGNORE TABLE spip_mots_articles DROP INDEX `id_article`"); |
||
| 145 | spip_query("ALTER IGNORE TABLE spip_mots_breves DROP INDEX `id_breve`"); |
||
| 146 | spip_query("ALTER IGNORE TABLE spip_mots_rubriques DROP INDEX `id_rubrique`"); |
||
| 147 | spip_query("ALTER IGNORE TABLE spip_mots_syndic DROP INDEX `id_syndic`"); |
||
| 148 | spip_query("ALTER IGNORE TABLE spip_mots_forum DROP INDEX `id_forum`"); |
||
| 149 | spip_query("ALTER IGNORE TABLE spip_mots_documents DROP INDEX `id_document`"); |
||
| 150 | # 18 juillet 2007: table depreciee |
||
| 151 | # spip_query("ALTER IGNORE TABLE spip_caches DROP INDEX fichier"); |
||
| 152 | maj_version(1.911); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Le logo du site n'est plus le logo par defaut des rubriques |
||
| 156 | // mais pour assurer la compatibilite ascendante, on le duplique |
||
| 157 | if (upgrade_vers(1.912, $version_installee, $version_cible)) { |
||
| 158 | @copy(_DIR_LOGOS.'rubon0.gif', _DIR_LOGOS.'siteon0.gif'); |
||
| 159 | @copy(_DIR_LOGOS.'ruboff0.gif', _DIR_LOGOS.'siteoff0.gif'); |
||
| 160 | @copy(_DIR_LOGOS.'rubon0.jpg', _DIR_LOGOS.'siteon0.jpg'); |
||
| 161 | @copy(_DIR_LOGOS.'ruboff0.jpg', _DIR_LOGOS.'siteoff0.jpg'); |
||
| 162 | @copy(_DIR_LOGOS.'rubon0.png', _DIR_LOGOS.'siteon0.png'); |
||
| 163 | @copy(_DIR_LOGOS.'ruboff0.png', _DIR_LOGOS.'siteoff0.png'); |
||
| 164 | maj_version(1.912); |
||
| 165 | } |
||
| 166 | |||
| 167 | // suppression de auteur_modif qui n'est plus utilise nulle part |
||
| 168 | if (upgrade_vers(1.913, $version_installee, $version_cible)) { |
||
| 169 | spip_query("ALTER TABLE spip_articles DROP `auteur_modif`"); |
||
| 170 | maj_version(1.913); |
||
| 171 | } |
||
| 172 | |||
| 173 | // Ajout de SVG |
||
| 174 | if (upgrade_vers(1.914, $version_installee, $version_cible)) { |
||
| 175 | spip_query("INSERT IGNORE INTO spip_types_documents (`extension`, `titre`, `inclus`) VALUES ('svg', 'Scalable Vector Graphics', 'embed')"); |
||
| 176 | spip_query("UPDATE spip_types_documents SET `mime_type`='image/svg+xml' WHERE `extension`='svg'"); |
||
| 177 | maj_version(1.914); |
||
| 178 | } |
||
| 179 | |||
| 180 | // Ajout de plein de type mime |
||
| 181 | if (upgrade_vers(1.915, $version_installee, $version_cible)) { |
||
| 182 | maj_version(1.915); |
||
| 183 | } |
||
| 184 | // refaire l'upgrade 1.905 qui a pu foirer en partie a cause de la requete ALTER sur spip_meta |
||
| 185 | if (upgrade_vers(1.916, $version_installee, $version_cible)) { |
||
| 186 | // agrandir le champ "valeur" de spip_meta pour pouvoir y stocker |
||
| 187 | // des choses plus sympa |
||
| 188 | spip_query("ALTER TABLE spip_meta DROP INDEX `valeur`"); |
||
| 189 | spip_query("ALTER TABLE spip_meta CHANGE `valeur` `valeur` TEXT"); |
||
| 190 | #8/08/07 plus d'indexation dans le core |
||
| 191 | //include_spip('inc/indexation'); |
||
| 192 | //update_index_tables(); |
||
| 193 | maj_version(1.916); |
||
| 194 | } |
||
| 195 | if (upgrade_vers(1.917, $version_installee, $version_cible)) { |
||
| 196 | spip_query("ALTER TABLE spip_documents DROP `inclus`"); |
||
| 197 | maj_version(1.917); |
||
| 198 | } |
||
| 199 | |||
| 200 | // Permettre d'enregistrer un numero IP dans les revisions d'articles |
||
| 201 | // a la place de l'id_auteur |
||
| 202 | if (upgrade_vers(1.918, $version_installee, $version_cible)) { |
||
| 203 | spip_query("ALTER TABLE spip_versions CHANGE `id_auteur` `id_auteur` VARCHAR(23)"); |
||
| 204 | maj_version(1.918); |
||
| 205 | } |
||
| 206 | |||
| 207 | if (upgrade_vers(1.919, $version_installee, $version_cible)) { |
||
| 208 | spip_query("ALTER TABLE spip_ajax_fonc DROP `id_auteur`"); |
||
| 209 | maj_version('1.919'); |
||
| 210 | } |
||
| 211 | |||
| 212 | View Code Duplication | if (upgrade_vers(1.920, $version_installee, $version_cible)) { |
|
| 213 | spip_query("ALTER IGNORE TABLE spip_documents_articles ADD PRIMARY KEY (`id_article`, `id_document`)"); |
||
| 214 | spip_query("ALTER IGNORE TABLE spip_documents_breves ADD PRIMARY KEY (`id_breve`, `id_document`)"); |
||
| 215 | spip_query("ALTER IGNORE TABLE spip_documents_rubriques ADD PRIMARY KEY (`id_rubrique`, `id_document`)"); |
||
| 216 | spip_query("ALTER IGNORE TABLE spip_documents_articles DROP INDEX `id_article`"); |
||
| 217 | spip_query("ALTER IGNORE TABLE spip_documents_breves DROP INDEX `id_breve`"); |
||
| 218 | spip_query("ALTER IGNORE TABLE spip_documents_rubriques DROP INDEX `id_rubrique`"); |
||
| 219 | maj_version('1.920'); |
||
| 220 | } |
||
| 221 | if (upgrade_vers(1.922, $version_installee, $version_cible)) { |
||
| 222 | spip_query("ALTER TABLE spip_meta ADD `impt` ENUM('non', 'oui') DEFAULT 'oui' NOT NULL AFTER `valeur`"); |
||
| 223 | $meta_serveur = array('version_installee','adresse_site','alea_ephemere_ancien','alea_ephemere','alea_ephemere_date','langue_site','langues_proposees','date_calcul_rubriques','derniere_modif','optimiser_table','drapeau_edition','creer_preview','taille_preview','creer_htpasswd','creer_htaccess','gd_formats_read','gd_formats', |
||
| 224 | 'netpbm_formats','formats_graphiques','image_process','plugin_header','plugin'); |
||
| 225 | foreach($meta_serveur as $nom) |
||
| 226 | spip_query("UPDATE spip_meta SET `impt`='non' WHERE `nom`="._q($nom)); |
||
| 227 | maj_version('1.922'); |
||
| 228 | } |
||
| 229 | if (upgrade_vers(1.923, $version_installee, $version_cible)) { |
||
| 230 | if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])){ |
||
| 231 | $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
||
| 232 | foreach ($IMPORT_tables_noimport as $key=>$table) |
||
| 233 | if ($table=='spip_meta') unset($IMPORT_tables_noimport[$key]); |
||
| 234 | ecrire_meta('IMPORT_tables_noimport',serialize($IMPORT_tables_noimport),'non'); |
||
| 235 | } |
||
| 236 | maj_version('1.923'); |
||
| 237 | } |
||
| 238 | |||
| 239 | if (upgrade_vers(1.924, $version_installee, $version_cible)) { |
||
| 240 | spip_query('DROP TABLE spip_ajax_fonc'); |
||
| 241 | maj_version('1.924'); |
||
| 242 | } |
||
| 243 | |||
| 244 | if (upgrade_vers(1.925, $version_installee, $version_cible)) { |
||
| 245 | include_spip('inc/flock'); |
||
| 246 | /* deplacement des sessions */ |
||
| 247 | $f_session = preg_files('data', 'session_'); |
||
| 248 | $repertoire = _DIR_SESSIONS; |
||
| 249 | View Code Duplication | if(!@file_exists($repertoire)) { |
|
| 250 | $repertoire = preg_replace(','._DIR_TMP.',', '', $repertoire); |
||
| 251 | $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
||
| 252 | } |
||
| 253 | foreach($f_session as $f) { |
||
| 254 | $d = basename($f); |
||
| 255 | @copy($f, $repertoire.$d); |
||
| 256 | } |
||
| 257 | /* deplacement des visites */ |
||
| 258 | $f_visites = preg_files('data/visites'); |
||
| 259 | $repertoire = sous_repertoire(_DIR_TMP, 'visites'); |
||
| 260 | foreach($f_visites as $f) { |
||
| 261 | $d = basename($f); |
||
| 262 | @copy($f, $repertoire.$d); |
||
| 263 | } |
||
| 264 | /* deplacement des upload */ |
||
| 265 | $auteurs = array(); |
||
| 266 | $req = spip_query("SELECT `login` FROM spip_auteurs WHERE `statut` = '0minirezo'"); |
||
| 267 | while($row = sql_fetch($req)) |
||
| 268 | $auteurs[] = $row['login']; |
||
| 269 | $f_upload = preg_files('upload', -1, 10000, $auteurs); |
||
| 270 | $repertoire = _DIR_TRANSFERT; |
||
| 271 | View Code Duplication | if(!@file_exists($repertoire)) { |
|
| 272 | $repertoire = preg_replace(','._DIR_TMP.',', '', $repertoire); |
||
| 273 | $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
||
| 274 | } |
||
| 275 | foreach($auteurs as $login) { |
||
| 276 | if(is_dir('upload/'.$login)) |
||
| 277 | $sous_repertoire = sous_repertoire(_DIR_TRANSFERT, $login); |
||
| 278 | } |
||
| 279 | foreach($f_upload as $f) { |
||
| 280 | @copy($f, _DIR_TMP.$f); |
||
| 281 | } |
||
| 282 | /* deplacement des dumps */ |
||
| 283 | $f_session = preg_files('data', 'dump'); |
||
| 284 | $repertoire = _DIR_DUMP; |
||
| 285 | View Code Duplication | if(!@file_exists($repertoire)) { |
|
| 286 | $repertoire = preg_replace(','._DIR_TMP.',', '', $repertoire); |
||
| 287 | $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
||
| 288 | } |
||
| 289 | foreach($f_session as $f) { |
||
| 290 | $d = basename($f); |
||
| 291 | @copy($f, $repertoire.$d); |
||
| 292 | } |
||
| 293 | maj_version('1.925'); |
||
| 294 | } |
||
| 295 | // Ajout de MP4 |
||
| 296 | if (upgrade_vers(1.926, $version_installee, $version_cible)) { |
||
| 297 | spip_query("INSERT IGNORE INTO spip_types_documents (`extension`, `titre`, `inclus`) VALUES ('mp4', 'MPEG4', 'embed')"); |
||
| 298 | spip_query("UPDATE spip_types_documents SET `mime_type`='application/mp4' WHERE `extension`='mp4'"); |
||
| 299 | maj_version('1.926'); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | ?> |
||
| 303 |
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.