4b8a09662361bb7a03640071b001c6950862dbc6
[velocampus/web/www.git] / www / ecrire / base / admin_repair.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 // http://doc.spip.org/@base_admin_repair_dist
16 function base_admin_repair_dist($titre='', $reprise='') {
17
18 $f = sql_repair('repair', NULL, true);
19 if ($f) {
20 $res = admin_repair_tables();
21 } else {
22 if ($titre)
23 spip_log("Pas d'instruction REPAIR dans ce serveur SQL");
24 $res = ' ';
25 }
26
27 if (!$res) {
28 $res = "<br /><br /><span style='color: red; font-weight: bold;'><tt>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error() ."</tt></span><br /><br /><br />\n";
29 } else {
30 include_spip('inc/rubriques');
31 calculer_rubriques();
32 propager_les_secteurs();
33 }
34 include_spip('inc/minipres');
35 $res .= pipeline('base_admin_repair',$res);
36 $res .= admin_repair_plat();
37 echo minipres(_T('texte_tentative_recuperation'),
38 $res . generer_form_ecrire('accueil', '','',_T('public:accueil_site')));
39 }
40
41 // http://doc.spip.org/@admin_repair_plat
42 function admin_repair_plat(){
43 spip_log("verification des documents joints");
44 $out = "";
45 $repertoire = array();
46 include_spip('inc/getdocument');
47 $res = sql_select('*','spip_documents',"fichier REGEXP CONCAT('^',extension,'[^/\]') AND distant='non'");
48
49 while ($row=sql_fetch($res)){
50 $ext = $row['extension'];
51 if (!$ext) {
52 spip_log("document sans extension: " . $row['id_document']);
53 continue;
54 }
55 if (!isset($repertoire[$ext])){
56 if (@file_exists($plat = _DIR_IMG. $ext .".plat"))
57 spip_unlink($plat);
58 $repertoire[$ext] = creer_repertoire_documents($ext);
59 if (preg_match(',_$,',$repertoire[$ext]))
60 $repertoire[$ext] = false;
61 }
62 if ($d=$repertoire[$ext]){
63 $d = substr($d,strlen(_DIR_IMG));
64 $src = $row['fichier'];
65 $dest = $d . substr($src,strlen($d));
66 if (deplacer_fichier_upload(_DIR_IMG . $src, _DIR_IMG . $dest)) {
67 sql_updateq('spip_documents',array('fichier'=>$dest),'id_document='.intval($row['id_document']));
68 spip_unlink(_DIR_IMG . $src);
69 $out .= "$src => $dest<br />";
70 }
71 }
72 }
73
74 return $out;
75 }
76
77 // http://doc.spip.org/@admin_repair_tables
78 function admin_repair_tables() {
79
80 $connexion = $GLOBALS['connexions'][0];
81 $prefixe = $connexion['prefixe'];
82 $res1 = sql_showbase();
83 $res = "";
84 if ($res1) {
85 while ($r = sql_fetch($res1)) {
86 $tab = array_shift($r);
87
88 $res .= "<br /><b>$tab</b> ";
89 spip_log("Repare $tab");
90 $result_repair = sql_repair($tab);
91 if (!$result_repair) return false;
92
93 $count = sql_countsel($tab);
94
95 if ($count>1)
96 $res .= "("._T('texte_compte_elements', array('count' => $count)).")\n";
97 else if ($count==1)
98 $res .= "("._T('texte_compte_element', array('count' => $count)).")\n";
99 else
100 $res .= "("._T('texte_vide').")\n";
101
102 $msg = join(" ", sql_fetch($result_repair)) . ' ';
103
104 $ok = strpos($msg, ' OK ');
105
106 if (!$ok)
107 $res .= "<pre><span style='color: red; font-weight: bold;'>".htmlentities($msg)."</span></pre>\n";
108 else
109 $res .= " "._T('texte_table_ok')."<br />\n";
110 }
111 }
112 return $res;
113 }
114 ?>