MDL-64506 templates: replace spans where and col-x appears
[moodle.git] / admin / tool / analytics / importmodel.php
CommitLineData
349c4412
AA
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 * Import models tool frontend.
19 *
20 * @package tool_analytics
21 * @copyright 2017 onwards Ankit Agarwal
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(__DIR__ . '/../../../config.php');
349c4412 26
e4453adc
DM
27require_login();
28\core_analytics\manager::check_can_manage_models();
29
30$returnurl = new \moodle_url('/admin/tool/analytics/index.php');
31$url = new \moodle_url('/admin/tool/analytics/importmodel.php');
32$title = get_string('importmodel', 'tool_analytics');
33
34\tool_analytics\output\helper::set_navbar($title, $url);
35
36$form = new \tool_analytics\output\form\import_model();
37if ($form->is_cancelled()) {
38 redirect($returnurl);
39} else if ($data = $form->get_data()) {
40
41 $modelconfig = new \core_analytics\model_config();
349c4412 42
c70a7194 43 $zipfilepath = $form->save_temp_file('modelfile');
e4453adc 44
c70a7194 45 list ($modeldata, $unused) = $modelconfig->extract_import_contents($zipfilepath);
e4453adc 46
e4453adc
DM
47 if ($error = $modelconfig->check_dependencies($modeldata, $data->ignoreversionmismatches)) {
48 // The file is not available until the form is validated so we need an alternative method to show errors.
49 redirect($url, $error, 0, \core\output\notification::NOTIFY_ERROR);
349c4412 50 }
c70a7194 51 \core_analytics\model::import_model($zipfilepath);
e4453adc
DM
52
53 redirect($returnurl, get_string('importedsuccessfully', 'tool_analytics'), 0,
54 \core\output\notification::NOTIFY_SUCCESS);
349c4412
AA
55}
56
e4453adc
DM
57echo $OUTPUT->header();
58$form->display();
349c4412 59echo $OUTPUT->footer();