[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/dbtransfer/ -> index.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Transfer tool
  19   *
  20   * @package    tool_dbtransfer
  21   * @copyright  2008 Petr Skoda {@link http://skodak.org/}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  define('NO_OUTPUT_BUFFERING', true);
  26  
  27  require('../../../config.php');
  28  require_once ('locallib.php');
  29  require_once ('database_transfer_form.php');
  30  
  31  require_login();
  32  admin_externalpage_setup('tooldbtransfer');
  33  
  34  // Create the form.
  35  $form = new database_transfer_form();
  36  $problem = '';
  37  
  38  // If we have valid input.
  39  if ($data = $form->get_data()) {
  40      // Connect to the other database.
  41      list($dbtype, $dblibrary) = explode('/', $data->driver);
  42      $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary);
  43      $dboptions = array();
  44      if ($data->dbport) {
  45          $dboptions['dbport'] = $data->dbport;
  46      }
  47      if ($data->dbsocket) {
  48          $dboptions['dbsocket'] = $data->dbsocket;
  49      }
  50      try {
  51          $targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, $dboptions);
  52          if ($targetdb->get_tables()) {
  53              $problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
  54          }
  55      } catch (moodle_exception $e) {
  56          $problem .= get_string('notargetconectexception', 'tool_dbtransfer').'<br />'.$e->debuginfo;
  57      }
  58  
  59      if ($problem === '') {
  60          // Scroll down to the bottom when finished.
  61          $PAGE->requires->js_init_code("window.scrollTo(0, 5000000);");
  62  
  63          // Enable CLI maintenance mode if requested.
  64          if ($data->enablemaintenance) {
  65              $PAGE->set_pagelayout('maintenance');
  66              tool_dbtransfer_create_maintenance_file();
  67          }
  68  
  69          // Start output.
  70          echo $OUTPUT->header();
  71          $data->dbtype = $dbtype;
  72          $data->dbtypefrom = $CFG->dbtype;
  73          echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data));
  74  
  75          // Do the transfer.
  76          $CFG->tool_dbransfer_migration_running = true;
  77          try {
  78              $feedback = new html_list_progress_trace();
  79              tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
  80              $feedback->finished();
  81          } catch (Exception $e) {
  82              if ($data->enablemaintenance) {
  83                  tool_dbtransfer_maintenance_callback();
  84              }
  85              unset($CFG->tool_dbransfer_migration_running);
  86              throw $e;
  87          }
  88          unset($CFG->tool_dbransfer_migration_running);
  89  
  90          // Finish up.
  91          echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
  92          echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/");
  93          echo $OUTPUT->footer();
  94          die;
  95      }
  96  }
  97  
  98  // Otherwise display the settings form.
  99  echo $OUTPUT->header();
 100  echo $OUTPUT->heading(get_string('transferdbtoserver', 'tool_dbtransfer'));
 101  
 102  $info = format_text(get_string('transferdbintro', 'tool_dbtransfer'), FORMAT_MARKDOWN);
 103  echo $OUTPUT->box($info);
 104  
 105  $form->display();
 106  if ($problem !== '') {
 107      echo $OUTPUT->box($problem, 'generalbox error');
 108  }
 109  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1