[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/publish/ -> backup.php (source)

   1  <?php
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // This file is part of Moodle - http://moodle.org/                      //
   6  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   7  //                                                                       //
   8  // Moodle is free software: you can redistribute it and/or modify        //
   9  // it under the terms of the GNU General Public License as published by  //
  10  // the Free Software Foundation, either version 3 of the License, or     //
  11  // (at your option) any later version.                                   //
  12  //                                                                       //
  13  // Moodle is distributed in the hope that it will be useful,             //
  14  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  15  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  16  // GNU General Public License for more details.                          //
  17  //                                                                       //
  18  // You should have received a copy of the GNU General Public License     //
  19  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
  20  //                                                                       //
  21  ///////////////////////////////////////////////////////////////////////////
  22  
  23  /*
  24   * @package    course
  25   * @subpackage publish
  26   * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
  28   * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
  29   *
  30   * This page display the publication backup form
  31   */
  32  
  33  require_once('../../config.php');
  34  require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  35  require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
  36  require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
  37  require_once($CFG->dirroot . '/course/publish/lib.php');
  38  require_once($CFG->libdir . '/filelib.php');
  39  
  40  
  41  //retrieve initial page parameters
  42  $id = required_param('id', PARAM_INT);
  43  $hubcourseid = required_param('hubcourseid', PARAM_INT);
  44  $huburl = required_param('huburl', PARAM_URL);
  45  $hubname = optional_param('hubname', '', PARAM_TEXT);
  46  
  47  //some permissions and parameters checking
  48  $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
  49  require_login($course);
  50  if (!has_capability('moodle/course:publish', context_course::instance($id))
  51          or !confirm_sesskey()) {
  52      throw new moodle_exception('nopermission');
  53  }
  54  
  55  //page settings
  56  $PAGE->set_url('/course/publish/backup.php');
  57  $PAGE->set_pagelayout('incourse');
  58  $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
  59  $PAGE->set_heading($course->fullname);
  60  
  61  //BEGIN backup processing
  62  $backupid = optional_param('backup', false, PARAM_ALPHANUM);
  63  if (!($bc = backup_ui::load_controller($backupid))) {
  64      $bc = new backup_controller(backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
  65                      backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
  66  }
  67  $backup = new backup_ui($bc,
  68          array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
  69  $backup->process();
  70  if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
  71      $backup->execute();
  72  } else {
  73      $backup->save_controller();
  74  }
  75  
  76  if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
  77      $renderer = $PAGE->get_renderer('core', 'backup');
  78      echo $OUTPUT->header();
  79      echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main');
  80      if ($backup->enforce_changed_dependencies()) {
  81          debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
  82      }
  83      echo $renderer->progress_bar($backup->get_progress_bar());
  84      echo $backup->display($renderer);
  85      echo $OUTPUT->footer();
  86      die();
  87  }
  88  
  89  //$backupfile = $backup->get_stage_results();
  90  $backupfile = $bc->get_results();
  91  $backupfile = $backupfile['backup_destination'];
  92  //END backup processing
  93  
  94  //retrieve the token to call the hub
  95  $registrationmanager = new registration_manager();
  96  $registeredhub = $registrationmanager->get_registeredhub($huburl);
  97  
  98  //display the sending file page
  99  echo $OUTPUT->header();
 100  echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
 101  $renderer = $PAGE->get_renderer('core', 'publish');
 102  echo $renderer->sendingbackupinfo($backupfile);
 103  if (ob_get_level()) {
 104      ob_flush();
 105  }
 106  flush();
 107  
 108  //send backup file to the hub
 109  $curl = new curl();
 110  $params = array();
 111  $params['filetype'] = HUB_BACKUP_FILE_TYPE;
 112  $params['courseid'] = $hubcourseid;
 113  $params['file'] = $backupfile;
 114  $params['token'] = $registeredhub->token;
 115  $curl->post($huburl . "/local/hub/webservice/upload.php", $params);
 116  
 117  //delete the temp backup file from user_tohub aera
 118  $backupfile->delete();
 119  $bc->destroy();
 120  
 121  //Output sending success
 122  echo $renderer->sentbackupinfo($id, $huburl, $hubname);
 123  
 124  echo $OUTPUT->footer();


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