[ Index ] |
|
Code source de SPIP 1.8.3 |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2005 * 7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * 8 * * 9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * 10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * 11 \***************************************************************************/ 12 13 14 // 15 // Ce fichier ne sera execute qu'une fois 16 if (defined("_ECRIRE_OPTIMISER")) return; 17 define("_ECRIRE_OPTIMISER", "1"); 18 19 20 function optimiser_base() { 21 spip_log ("optimisation de la base"); 22 23 $mydate = date("YmdHis", time() - 24 * 3600); 24 25 // 26 // Rubriques 27 // 28 29 $query = "SELECT id_rubrique FROM spip_rubriques"; 30 $result = spip_query($query); 31 $rubriques = '0'; 32 while ($row = spip_fetch_array($result)) $rubriques .= ','.$row['id_rubrique']; 33 34 if ($rubriques) { 35 $query = "DELETE FROM spip_articles WHERE id_rubrique NOT IN ($rubriques) AND maj < $mydate"; 36 spip_query($query); 37 $query = "DELETE FROM spip_breves WHERE id_rubrique NOT IN ($rubriques) AND maj < $mydate"; 38 spip_query($query); 39 $query = "DELETE FROM spip_forum WHERE id_rubrique NOT IN (0,$rubriques)"; 40 spip_query($query); 41 $query = "DELETE FROM spip_auteurs_rubriques WHERE id_rubrique NOT IN ($rubriques)"; 42 spip_query($query); 43 $query = "DELETE FROM spip_documents_rubriques WHERE id_rubrique NOT IN ($rubriques)"; 44 spip_query($query); 45 $query = "DELETE FROM spip_mots_rubriques WHERE id_rubrique NOT IN ($rubriques)"; 46 spip_query($query); 47 } 48 49 50 // 51 // Articles 52 // 53 54 $query = "DELETE FROM spip_articles WHERE statut='poubelle' AND maj < $mydate"; 55 spip_query($query); 56 $query = "SELECT id_article FROM spip_articles"; 57 $result = spip_query($query); 58 $articles = '0'; 59 while ($row = spip_fetch_array($result)) $articles .= ','.$row['id_article']; 60 61 if ($articles) { 62 $query = "DELETE FROM spip_auteurs_articles WHERE id_article NOT IN ($articles)"; 63 spip_query($query); 64 $query = "DELETE FROM spip_documents_articles WHERE id_article NOT IN ($articles)"; 65 spip_query($query); 66 $query = "DELETE FROM spip_mots_articles WHERE id_article NOT IN ($articles)"; 67 spip_query($query); 68 $query = "DELETE FROM spip_forum WHERE id_article NOT IN (0,$articles)"; 69 spip_query($query); 70 } 71 72 73 // 74 // Breves 75 // 76 77 $query = "DELETE FROM spip_breves WHERE statut='refuse' AND maj < $mydate"; 78 spip_query($query); 79 $breves = '0'; 80 $query = "SELECT id_breve FROM spip_breves"; 81 $result = spip_query($query); 82 while ($row = spip_fetch_array($result)) $breves .= ','.$row['id_breve']; 83 84 if ($breves) { 85 $query = "DELETE FROM spip_documents_breves WHERE id_breve NOT IN ($breves)"; 86 spip_query($query); 87 $query = "DELETE FROM spip_mots_breves WHERE id_breve NOT IN ($breves)"; 88 spip_query($query); 89 $query = "DELETE FROM spip_forum WHERE id_breve NOT IN (0,$breves)"; 90 spip_query($query); 91 } 92 93 94 // 95 // Sites 96 // 97 98 $query = "DELETE FROM spip_syndic WHERE maj < $mydate AND statut = 'refuse'"; 99 spip_query($query); 100 101 $syndic = '0'; 102 $query = "SELECT id_syndic FROM spip_syndic"; 103 $result = spip_query($query); 104 while ($row = spip_fetch_array($result)) $syndic .= ','.$row['id_syndic']; 105 106 if ($syndic) { 107 $query = "DELETE FROM spip_syndic_articles WHERE id_syndic NOT IN (0,$syndic)"; 108 spip_query($query); 109 $query = "DELETE FROM spip_mots_syndic WHERE id_syndic NOT IN ($syndic)"; 110 spip_query($query); 111 $query = "DELETE FROM spip_forum WHERE id_syndic NOT IN (0,$syndic)"; 112 spip_query($query); 113 } 114 115 116 // 117 // Auteurs 118 // 119 120 $auteurs = '0'; 121 $query = "SELECT id_auteur FROM spip_auteurs"; 122 $result = spip_query($query); 123 while ($row = spip_fetch_array($result)) $auteurs .= ','.$row['id_auteur']; 124 125 if ($auteurs) { 126 $query = "DELETE FROM spip_auteurs_articles WHERE id_auteur NOT IN ($auteurs)"; 127 spip_query($query); 128 $query = "DELETE FROM spip_auteurs_messages WHERE id_auteur NOT IN ($auteurs)"; 129 spip_query($query); 130 $query = "DELETE FROM spip_auteurs_rubriques WHERE id_auteur NOT IN ($auteurs)"; 131 spip_query($query); 132 } 133 134 $query = "SELECT id_auteur,nom,email FROM spip_auteurs WHERE statut='5poubelle' AND maj < $mydate"; 135 $result = spip_query($query); 136 while ($row = spip_fetch_array($result)) { 137 $id_auteur = $row['id_auteur']; 138 $nom = $row['nom']; 139 $email = $row['email']; 140 141 $query2 = "SELECT * FROM spip_auteurs_articles WHERE id_auteur=$id_auteur"; 142 $result2 = spip_query($query2); 143 if (!spip_num_rows($result2)) { 144 $query3 = "DELETE FROM spip_auteurs WHERE id_auteur=$id_auteur"; 145 $result3 = spip_query($query3); 146 spip_log ("suppression auteur $id_auteur ($nom, $email)"); 147 } 148 } 149 150 151 // 152 // Messages prives 153 // 154 155 $query = "SELECT m.id_message FROM spip_messages AS m, spip_auteurs_messages AS lien ". 156 "WHERE m.id_message = lien.id_message GROUP BY m.id_message"; 157 $result = spip_query($query); 158 while ($row = spip_fetch_array($result)) $messages[] = $row['id_message']; 159 160 $query = "SELECT id_message FROM spip_messages ". 161 "WHERE type ='affich'"; 162 $result = spip_query($query); 163 while ($row = spip_fetch_array($result)) $messages[] = $row['id_message']; 164 165 if ($messages) { 166 $messages = join(",", $messages); 167 168 $query = "DELETE FROM spip_messages WHERE id_message NOT IN ($messages)"; 169 spip_query($query); 170 $query = "DELETE FROM spip_forum WHERE id_message NOT IN (0,$messages)"; 171 spip_query($query); 172 } 173 174 175 // 176 // Mots-cles 177 // 178 179 $query = "DELETE FROM spip_mots WHERE titre='' AND maj < $mydate"; 180 $result = spip_query($query); 181 182 $mots = '0'; 183 $query = "SELECT id_mot FROM spip_mots"; 184 $result = spip_query($query); 185 while ($row = spip_fetch_array($result)) $mots .= ','.$row['id_mot']; 186 187 if ($mots) { 188 $query = "DELETE FROM spip_mots_articles WHERE id_mot NOT IN ($mots)"; 189 spip_query($query); 190 $query = "DELETE FROM spip_mots_breves WHERE id_mot NOT IN ($mots)"; 191 spip_query($query); 192 $query = "DELETE FROM spip_mots_forum WHERE id_mot NOT IN ($mots)"; 193 spip_query($query); 194 $query = "DELETE FROM spip_mots_rubriques WHERE id_mot NOT IN ($mots)"; 195 spip_query($query); 196 $query = "DELETE FROM spip_mots_syndic WHERE id_mot NOT IN ($mots)"; 197 spip_query($query); 198 } 199 200 201 // 202 // Forums 203 // 204 205 $query = "DELETE FROM spip_forum WHERE statut='redac' AND maj < $mydate"; 206 spip_query($query); 207 208 $forums = '0'; 209 $query = "SELECT id_forum FROM spip_forum"; 210 $result = spip_query($query); 211 while ($row = spip_fetch_array($result)) $forums .= ','.$row[0]; 212 213 if ($forums) { 214 $query = "DELETE FROM spip_forum WHERE id_parent NOT IN (0,$forums)"; 215 spip_query($query); 216 $query = "DELETE FROM spip_mots_forum WHERE id_forum NOT IN ($forums)"; 217 spip_query($query); 218 } 219 220 221 // 222 // Indexation 223 // 224 225 // les objets inutiles 226 $types = array('article','auteur','breve','mot','rubrique','forum','signature','syndic'); 227 while (list(,$type) = each($types)) { 228 $table_objet = 'spip_'.table_objet($type); 229 $table_index = 'spip_index_'.table_objet($type); 230 231 // limiter aux objets publies 232 switch ($type) { 233 case 'article': 234 case 'breve': 235 case 'rubrique': 236 case 'syndic': 237 case 'forum': 238 case 'signature': 239 $critere = "AND statut<>'publie'"; 240 break; 241 case 'auteur': 242 $critere = "AND statut NOT IN ('0minirezo', '1comite')"; 243 break; 244 case 'mot': 245 default: 246 $critere = 'AND 1=0'; // ne jamais desindexer un mot 247 break; 248 } 249 250 spip_query("UPDATE $table_objet SET idx='' WHERE idx<>'non' $critere"); 251 252 $suppr = ''; 253 $s = spip_query("SELECT id_$type FROM $table_objet WHERE idx='' $critere"); 254 while ($t = spip_fetch_array($s)) 255 $suppr .= ','.$t[0]; 256 $s = spip_query("SELECT id_$type FROM $table_objet WHERE idx='non'"); 257 while ($t = spip_fetch_array($s)) 258 $suppr .= ','.$t[0]; 259 if ($suppr) 260 spip_query("DELETE FROM $table_index WHERE id_$type IN (0$suppr)"); 261 } 262 263 // 264 // MySQL 265 // 266 if ($GLOBALS['table_prefix']) $table_pref = $GLOBALS['table_prefix']."_"; 267 else $table_pref = ""; 268 269 $query = "SHOW TABLES LIKE '$table_pref%'"; 270 $result = spip_query($query); 271 while ($row = spip_fetch_array($result)) $tables[] = $row[0]; 272 273 if ($tables) { 274 $tables = join(",", $tables); 275 $query = "OPTIMIZE TABLE ".$tables; 276 spip_query($query); 277 } 278 279 spip_log("optimisation ok"); 280 } 281 282 ## debug 283 if ($GLOBALS['auteur_session']['statut'] == '0minirezo' 284 AND $_GET['optimiser'] == 'oui') 285 optimiser_base(); 286 287 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Feb 22 22:27:47 2007 | par Balluche grâce à PHPXref 0.7 |