index.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004-2005 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. $my_name = 'mysql';
  23. $url = 'tools.php?p='.$my_name;
  24. $img_check = 'images/check_%s.png';
  25. $optimize = (!empty($_GET['optimize'])) ? $_GET['optimize'] : '';
  26. $backup = (!empty($_POST['backup'])) ? $_POST['backup'] : '';
  27. $restore = (!empty($_POST['restore'])) ? $_POST['restore'] : '';
  28. // Optimisation des tables
  29. if ($optimize == 1)
  30. {
  31. buffer::str('<h2>'.__('Optimization').'</h2>');
  32. if ($blog->optimize() !== false) {
  33. buffer::str(
  34. '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  35. __('Optimize tables').'</p>'
  36. );
  37. } else {
  38. buffer::str(
  39. '<p><img src="'.sprintf($img_check,'off').'" alt="ok" /> '.
  40. __('Error during tables optimization').'</p>'
  41. );
  42. }
  43. $blog->countAll();
  44. buffer::str(
  45. '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  46. __('Count comments').'</p>'
  47. );
  48. buffer::str(
  49. '<p>'.__('Optimization done').'</p>'.
  50. '<p><a href="tools.php">'.__('Back to tools').'</a></p>'
  51. );
  52. }
  53. // Sauvegarde des tables
  54. elseif ($backup == 1)
  55. {
  56. include_once(dirname(__FILE__).'/lib.mysqldump.php');
  57. $send_it = isset($_POST['sendit'])?true:false;
  58. $res = dbdump::saveDump($send_it);
  59. buffer::str('<h2>'.__('Backup').'</h2>');
  60. if ($res !== false) {
  61. buffer::str(
  62. '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  63. __('Your tables have been saved').'</p>'.
  64. '<p>'. __('You can now download a gzipped version of the corresponding SQL file from this location') .
  65. ' : <a href="'.dc_app_url.'/share/mysql/'.$res.'">'.$res.'</a></p>'.
  66. '<p>'.__('Backup done').'</p>'
  67. );
  68. } else {
  69. buffer::str(
  70. '<p><img src="'.sprintf($img_check,'off').'" alt="ok" /> '.
  71. __('Error during tables backup').'</p>'.
  72. '<p>'.__('Backup done').'</p>'
  73. );
  74. }
  75. buffer::str(
  76. '<p><a href="tools.php">'.__('Back to tools').'</a></p>'
  77. );
  78. }
  79. // Restauration des tables
  80. elseif ($restore == 1)
  81. {
  82. include_once(dirname(__FILE__).'/lib.mysqldump.php');
  83. buffer::str('<h2>'.__('Restore').'</h2>');
  84. if (isset($_FILES['dumpfile']) && $_FILES['dumpfile']['error'] == 0) {
  85. if (is_uploaded_file($_FILES['dumpfile']['tmp_name'])) {
  86. $tmp_file = DC_SHARE_DIR.'/mysql/dump.tmp';
  87. if (!move_uploaded_file($_FILES['dumpfile']['tmp_name'],$tmp_file)) {
  88. return(false);
  89. }
  90. $src_file = $tmp_file;
  91. }
  92. switch($_FILES['dumpfile']['type']) {
  93. case '' :
  94. case 'application/octet-stream' :
  95. if ($fh = fopen($src_file, "rb")) {
  96. $buffer = fread($fh, 3);
  97. fclose($fh);
  98. $compressed = ($buffer[0] == chr(31) && $buffer[1] == chr(139))?true:false;
  99. } else {
  100. $error = __('Cannot read uploaded file');
  101. @unlink($src_file);
  102. }
  103. break;
  104. case 'application/x-gzip':
  105. case 'application/x-gzip-compressed':
  106. $compressed = true;
  107. break;
  108. case 'text/plain':
  109. $compressed = false;
  110. break;
  111. default :
  112. $error = __('Wrong file format.');
  113. @unlink($src_file);
  114. break;
  115. }
  116. } else {
  117. $error = __('An error occurred while uploading the dumpfile.');
  118. }
  119. if (isset($compressed)) {
  120. if (($res = dbdump::restoreDump($src_file, $compressed)) !== false) {
  121. buffer::str(
  122. '<p>'.__('Restore done.').'</p>'
  123. );
  124. $blog->triggerMassUpd();
  125. } else {
  126. $error = __('An error occurred while restoring. Your blog may be broken.');
  127. }
  128. }
  129. if (!empty($error)) {
  130. buffer::str(
  131. '<div class="erreur"><p>'.$error.'</p></div>'.
  132. '<p>'.__('Restore failed.').'</p>'
  133. );
  134. }
  135. buffer::str(
  136. '<p><a href="'.$url.'">'.__('Back to menu').'</a></p>'
  137. );
  138. }
  139. else
  140. {
  141. include_once(dirname(__FILE__).'/lib.installer.php');
  142. buffer::str(
  143. '<h2>'.__('MySQL database operations').'</h2>');
  144. // Vérification de la présence d'un répertoire dédié dans share (pour dump)
  145. if (($err = installer::checkPluginShareDir($my_name))) {
  146. buffer::str(
  147. '<div class="erreur"><p><strong>'.
  148. __('Unavailable mysql/ directory in share/. You may create it manually.').
  149. '</strong></p>'.
  150. '</div>'
  151. );
  152. }
  153. // Optimisation
  154. buffer::str(
  155. '<h3>'.__('Optimization').' '.helpLink('index&amp;plugin=mysql','optimisation').'</h3>'.
  156. '<p>'.__('This operation allows you to optimize DotClear-related tables '.
  157. 'in MySQL and keep some data safe. No data should be lost during this '.
  158. 'operation.').'</p>'.
  159. '<p><strong>'.__('Important').'</strong>&nbsp;: '.
  160. __('Such an operation could take some time. Please be patient.').'</p>'.
  161. '<p><a href="'.$url.'&amp;optimize=1">'.__('Optimize database').'</a></p>'
  162. );
  163. // Sauvegarde
  164. buffer::str(
  165. '<h3>'.__('Backup').' '.helpLink('index&amp;plugin=mysql','sauvegarde').'</h3>'.
  166. '<p>'.__('This operation allows you to save DotClear-related tables '.
  167. 'in MySQL. It will generate a gzipped SQL file, stored in your share/ directory, which could be use to restore your tables and their content.').
  168. '</p>'.
  169. '<p><strong>'.__('Important').'</strong>&nbsp;: '.
  170. __('Such an operation could take some time. Please be patient.').'</p>'.
  171. '<form method="post" action="'.$url.'">'.
  172. '<fieldset>'.
  173. '<p class="field"><label class="float" for="sendit">'.__('Immediate download').' '.helpLink('index&amp;plugin=mysql','send_it').'</label>'.
  174. '<input type="checkbox" name="sendit" id="sendit" value="1" checked="checked" /></p>'.
  175. '<p class="field"><input type="hidden" name="backup" value="1"/>'.
  176. '<input type="submit" class="submit" value="'.__('Backup').'"/></p>'.
  177. '</fieldset>'.
  178. '</form>'
  179. );
  180. // Restauration
  181. buffer::str(
  182. '<h3>'.__('Restore a backup').' '.helpLink('index&amp;plugin=mysql','restauration').'</h3>'.
  183. '<p>'.__('This operation allows you to restore your DotClear-related tables in MySQL. '.
  184. 'It will use a gzipped dump file produced by the backup operation.').'</p>'.
  185. '<p>'.__('Use the form below to select and upload your dump file.').'</p>'.
  186. '<p><strong>'.__('Important').'</strong>&nbsp;: '.
  187. __('Such an operation could take some time. Please be patient.').'</p>'.
  188. '<p class="erreur"><strong>'.
  189. __('Please note that this operation will not merge existing datas with dumped ones, but simply replace them.').
  190. '<br />'.
  191. __('Besides, this process can fail due to execution time restrictions in your PHP configuration.').
  192. __('In such a case, it may leave your blog in a damaged state.').
  193. '<br />'.
  194. __('You are now warned !').
  195. '</strong></p>'.
  196. '<form method="post" action="'.$url.'" enctype="multipart/form-data">'.
  197. '<fieldset>'.
  198. '<p class="field"><label class="float" for="dumpfile">'.__('Dumpfile to restore').' '.helpLink('index&amp;plugin=mysql','dumpfile').'</label>'.
  199. '<input type="file" name="dumpfile" id="dumpfile"/></p>'.
  200. '<p class="field"><input type="hidden" name="restore" value="1"/>'.
  201. '<input type="submit" class="submit" value="'.__('Restore').'"/></p>'.
  202. '</fieldset>'.
  203. '</form>'
  204. );
  205. }
  206. ?>