Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Profiling tool import utility.
  19   *
  20   * @package    tool_profiling
  21   * @copyright  2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
  28  require_once (__DIR__ . '/import_form.php');
  29  
  30  admin_externalpage_setup('toolprofiling');
  31  
  32  $PAGE->navbar->add(get_string('import', 'tool_profiling'));
  33  
  34  // Calculate export variables.
  35  $tempdir = 'profiling';
  36  make_temp_directory($tempdir);
  37  
  38  // URL where we'll end, both on success and failure.
  39  $url = new moodle_url('/admin/tool/profiling/index.php');
  40  
  41  // Instantiate the upload profiling runs form.
  42  $mform = new profiling_import_form();
  43  
  44  // If there is any file to import.
  45  if ($data = $mform->get_data()) {
  46      $filename = $mform->get_new_filename('mprfile');
  47      $file = $CFG->tempdir . '/' . $tempdir . '/' . $filename;
  48      $status = $mform->save_file('mprfile', $file);
  49      if ($status) {
  50          // File saved properly, let's import it.
  51          $status = profiling_import_runs($file, $data->importprefix);
  52      }
  53      // Delete the temp file, not needed anymore.
  54      if (file_exists($file)) {
  55          unlink($file);
  56      }
  57      if ($status) {
  58          // Import ended ok, let's redirect to main profiling page.
  59          redirect($url, get_string('importok', 'tool_profiling', $filename));
  60      }
  61  } else {
  62      echo $OUTPUT->header();
  63      echo $OUTPUT->heading(get_string('import', 'tool_profiling'));
  64      $mform->display();
  65      echo $OUTPUT->footer();
  66      die;
  67  }
  68  
  69  // Something wrong happened, notice it and done.
  70  notice(get_string('importproblem', 'tool_profiling', $filename), $url);