[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ecrire/tools/mysql/ -> index.php (source)

   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  
  25  $img_check = 'images/check_%s.png';
  26  
  27  $optimize = (!empty($_GET['optimize'])) ? $_GET['optimize'] : '';
  28  $backup = (!empty($_POST['backup'])) ? $_POST['backup'] : '';
  29  $restore = (!empty($_POST['restore'])) ? $_POST['restore'] : '';
  30  
  31  
  32  // Optimisation des tables
  33  if ($optimize == 1)
  34  {
  35      buffer::str('<h2>'.__('Optimization').'</h2>');
  36  
  37      if ($blog->optimize() !== false) {
  38          buffer::str(
  39          '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  40          __('Optimize tables').'</p>'
  41          );
  42      } else {
  43          buffer::str(
  44          '<p><img src="'.sprintf($img_check,'off').'" alt="ok" /> '.
  45          __('Error during tables optimization').'</p>'
  46          );
  47      }
  48  
  49      $blog->countAll();
  50      buffer::str(
  51      '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  52      __('Count comments').'</p>'
  53      );
  54  
  55      buffer::str(
  56      '<p>'.__('Optimization done').'</p>'.
  57      '<p><a href="tools.php">'.__('Back to tools').'</a></p>'
  58      );
  59  }
  60  // Sauvegarde des tables
  61  elseif ($backup == 1)
  62  {
  63      include_once(dirname(__FILE__).'/lib.mysqldump.php');
  64  
  65      $send_it = isset($_POST['sendit'])?true:false;
  66      $res = dbdump::saveDump($send_it);
  67  
  68      buffer::str('<h2>'.__('Backup').'</h2>');
  69      if ($res !== false) {
  70          buffer::str(
  71              '<p><img src="'.sprintf($img_check,'on').'" alt="ok" /> '.
  72              __('Your tables have been saved').'</p>'.
  73              '<p>'. __('You can now download a gzipped version of the corresponding SQL file from this location') .
  74              ' : <a href="'.dc_app_url.'/share/mysql/'.$res.'">'.$res.'</a></p>'.
  75              '<p>'.__('Backup done').'</p>'
  76          );
  77      } else {
  78          buffer::str(
  79              '<p><img src="'.sprintf($img_check,'off').'" alt="ok" /> '.
  80              __('Error during tables backup').'</p>'.
  81              '<p>'.__('Backup done').'</p>'
  82          );
  83      }
  84      buffer::str(
  85          '<p><a href="tools.php">'.__('Back to tools').'</a></p>'
  86      );
  87  }
  88  // Restauration des tables
  89  elseif ($restore == 1)
  90  {
  91      include_once(dirname(__FILE__).'/lib.mysqldump.php');
  92  
  93      buffer::str('<h2>'.__('Restore').'</h2>');
  94  
  95      if (isset($_FILES['dumpfile']) && $_FILES['dumpfile']['error'] == 0) {
  96          if (is_uploaded_file($_FILES['dumpfile']['tmp_name'])) {
  97              $tmp_file = DC_SHARE_DIR.'/mysql/dump.tmp';
  98              if (!move_uploaded_file($_FILES['dumpfile']['tmp_name'],$tmp_file)) {
  99                  return(false);
 100              }
 101              $src_file = $tmp_file;
 102          }
 103          switch($_FILES['dumpfile']['type']) {
 104              case '' :
 105              case 'application/octet-stream' :
 106                  if ($fh = fopen($src_file, "rb")) {
 107                      $buffer = fread($fh, 3);
 108                      fclose($fh);
 109                      $compressed = ($buffer[0] == chr(31) && $buffer[1] == chr(139))?true:false;
 110                  } else {
 111                      $error = __('Cannot read uploaded file');
 112                      @unlink($src_file);
 113                  }
 114                  break;
 115              case 'application/x-gzip':
 116              case 'application/x-gzip-compressed':
 117                  $compressed = true;
 118                  break;
 119              case 'text/plain':
 120                  $compressed = false;
 121                  break;
 122              default :
 123                  $error = __('Wrong file format.');
 124                  @unlink($src_file);
 125                  break;
 126          }
 127      } else {
 128          $error = __('An error occurred while uploading the dumpfile.');
 129      }
 130      if (isset($compressed)) {
 131          if (($res = dbdump::restoreDump($src_file, $compressed)) !== false) {
 132              buffer::str(
 133                  '<p>'.__('Restore done.').'</p>'
 134              );
 135              $blog->triggerMassUpd();
 136          } else {
 137              $error = __('An error occurred while restoring. Your blog may be broken.');
 138          }
 139      }
 140      if (!empty($error)) {
 141          buffer::str(
 142              '<div class="erreur"><p>'.$error.'</p></div>'.
 143              '<p>'.__('Restore failed.').'</p>'
 144          );
 145      }
 146      buffer::str(
 147          '<p><a href="'.$url.'">'.__('Back to menu').'</a></p>'
 148      );
 149  }
 150  else
 151  {
 152      include_once(dirname(__FILE__).'/lib.installer.php');
 153  
 154      buffer::str(
 155      '<h2>'.__('MySQL database operations').'</h2>');
 156  
 157      // Vérification de la présence d'un répertoire dédié dans share (pour dump)
 158      if (($err = installer::checkPluginShareDir($my_name))) {
 159          buffer::str(
 160          '<div class="erreur"><p><strong>'.
 161          __('Unavailable mysql/ directory in share/. You may create it manually.').
 162          '</strong></p>'.
 163          '</div>'
 164          );
 165      }
 166  
 167      // Optimisation
 168      buffer::str(
 169      '<h3>'.__('Optimization').' '.helpLink('index&amp;plugin=mysql','optimisation').'</h3>'.
 170      '<p>'.__('This operation allows you to optimize DotClear-related tables '.
 171      'in MySQL and keep some data safe. No data should be lost during this '.
 172      'operation.').'</p>'.
 173      '<p><strong>'.__('Important').'</strong>&nbsp;: '.
 174      __('Such an operation could take some time. Please be patient.').'</p>'.
 175      '<p><a href="'.$url.'&amp;optimize=1">'.__('Optimize database').'</a></p>'
 176      );
 177  
 178      // Sauvegarde
 179      buffer::str(
 180      '<h3>'.__('Backup').' '.helpLink('index&amp;plugin=mysql','sauvegarde').'</h3>'.
 181      '<p>'.__('This operation allows you to save DotClear-related tables '.
 182      '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.').
 183      '</p>'.
 184      '<p><strong>'.__('Important').'</strong>&nbsp;: '.
 185      __('Such an operation could take some time. Please be patient.').'</p>'.
 186      '<form method="post" action="'.$url.'">'.
 187      '<fieldset>'.
 188      '<p class="field"><label class="float" for="sendit">'.__('Immediate download').' '.helpLink('index&amp;plugin=mysql','send_it').'</label>'.
 189      '<input type="checkbox" name="sendit" id="sendit" value="1" checked="checked" /></p>'.
 190      '<p class="field"><input type="hidden" name="backup" value="1"/>'.
 191      '<input type="submit" class="submit" value="'.__('Backup').'"/></p>'.
 192      '</fieldset>'.
 193      '</form>'
 194      );
 195  
 196      // Restauration
 197      buffer::str(
 198      '<h3>'.__('Restore a backup').' '.helpLink('index&amp;plugin=mysql','restauration').'</h3>'.
 199      '<p>'.__('This operation allows you to restore your DotClear-related tables in MySQL. '.
 200      'It will use a gzipped dump file produced by the backup operation.').'</p>'.
 201      '<p>'.__('Use the form below to select and upload your dump file.').'</p>'.
 202      '<p><strong>'.__('Important').'</strong>&nbsp;: '.
 203      __('Such an operation could take some time. Please be patient.').'</p>'.
 204      '<p class="erreur"><strong>'.
 205      __('Please note that this operation will not merge existing datas with dumped ones, but simply replace them.').
 206      '<br />'.
 207      __('Besides, this process can fail due to execution time restrictions in your PHP configuration.').
 208      __('In such a case, it may leave your blog in a damaged state.').
 209      '<br />'.
 210      __('You are now warned !').
 211      '</strong></p>'.
 212      '<form method="post" action="'.$url.'" enctype="multipart/form-data">'.
 213      '<fieldset>'.
 214      '<p class="field"><label class="float" for="dumpfile">'.__('Dumpfile to restore').' '.helpLink('index&amp;plugin=mysql','dumpfile').'</label>'.
 215      '<input type="file" name="dumpfile" id="dumpfile"/></p>'.
 216      '<p class="field"><input type="hidden" name="restore" value="1"/>'.
 217      '<input type="submit" class="submit" value="'.__('Restore').'"/></p>'.
 218      '</fieldset>'.
 219      '</form>'
 220      );
 221  }
 222  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7