Skip to content
Extraits de code Groupes Projets
Valider de236ca9 rédigé par Antoine Pitrou's avatar Antoine Pitrou
Parcourir les fichiers

suppression des documents inutilises

parent 9bffe84b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -171,21 +171,51 @@ function optimiser_base() { ...@@ -171,21 +171,51 @@ function optimiser_base() {
$result = spip_query($query); $result = spip_query($query);
while ($row = spip_fetch_array($result)) $mots[] = $row['id_mot']; while ($row = spip_fetch_array($result)) $mots[] = $row['id_mot'];
if ($mots) {
$mots = join(",", $mots); //
// Documents
//
$query = "DELETE FROM spip_mots_articles WHERE id_mot NOT IN ($mots)"; $query = "SELECT id_document FROM spip_documents_articles";
spip_query($query); $result = spip_query($query);
$query = "DELETE FROM spip_mots_breves WHERE id_mot NOT IN ($mots)"; while ($row = spip_fetch_array($result)) $documents[] = $row['id_document'];
spip_query($query); $query = "SELECT id_document FROM spip_documents_rubriques";
$query = "DELETE FROM spip_mots_forum WHERE id_mot NOT IN ($mots)"; $result = spip_query($query);
spip_query($query); while ($row = spip_fetch_array($result)) $documents[] = $row['id_document'];
$query = "DELETE FROM spip_mots_rubriques WHERE id_mot NOT IN ($mots)"; $query = "SELECT id_document FROM spip_documents_breves";
spip_query($query); $result = spip_query($query);
$query = "DELETE FROM spip_mots_syndic WHERE id_mot NOT IN ($mots)"; while ($row = spip_fetch_array($result)) $documents[] = $row['id_document'];
spip_query($query);
if ($documents) {
$documents = join(",", $documents);
$query = "SELECT id_document, fichier FROM spip_documents WHERE id_document NOT IN ($documents)";
$result = spip_query($query);
while ($row = spip_fetch_array($result)) {
$documents_poubelle[] = $row['id_document'];
$fichiers_poubelle[] = $row['fichier'];
}
if ($documents_poubelle) {
$documents_poubelle = join(",", $documents_poubelle);
$fichier = $GLOBALS['dir_ecrire'].'data/.poubelle';
if (!$f = @fopen($fichier, 'a')) {
spip_log("impossible d'ecrire dans $fichier !");
@unlink($fichier); // on essaie de forcer
$f = @fopen($fichier, 'a');
}
spip_log("mise a la poubelle : ".join(", ", $fichiers_poubelle));
$ok = fputs($f, join("\n", $fichiers_poubelle)."\n");
fclose($f);
if ($ok) {
$query = "DELETE FROM spip_documents WHERE id_document IN ($documents_poubelle)";
spip_query($query);
}
}
} }
// //
// Forums // Forums
// //
......
...@@ -348,6 +348,37 @@ if (lire_meta("activer_statistiques") != "non") { ...@@ -348,6 +348,37 @@ if (lire_meta("activer_statistiques") != "non") {
} }
//
// Effacement de la poubelle (documents supprimes)
//
if (file_exists($fichier_poubelle = "ecrire/data/.poubelle")) {
if (timeout('poubelle')) {
if ($s = sizeof($suite = file($fichier_poubelle))) {
$s = $suite[$n = rand(0, $s)];
$s = trim($s);
include_ecrire("inc_connect.php3");
if ($db_ok) {
// Verifier qu'on peut vraiment effacer le fichier...
$query = "SELECT id_document FROM spip_documents WHERE fichier='$s'";
$result = spip_query($query);
if (spip_num_rows($result) OR !ereg('^IMG/', $s) OR strpos($s, '..')) {
spip_log("Tentative d'effacement interdit: $s");
}
else {
@unlink($s);
}
unset($suite[$n]);
$f = fopen($fichier_poubelle, 'wb');
fwrite($f, join("", $suite));
fclose($f);
}
}
else @unlink($fichier_poubelle);
}
}
// //
// Gerer l'indexation automatique // Gerer l'indexation automatique
// //
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter