-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexecute.php
73 lines (64 loc) · 2.84 KB
/
execute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* Executes the passed AMOScript and stages the result
*
* @package local_amos
* @copyright 2011 David Mudrak <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/local/amos/locallib.php');
require_once($CFG->dirroot . '/local/amos/mlanglib.php');
require_once($CFG->dirroot . '/local/amos/execute_form.php');
require_login(SITEID, false);
require_capability('local/amos:execute', context_system::instance());
require_capability('local/amos:stage', context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/execute.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('scriptexecute', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('scriptexecute', 'local_amos'));
$executeform = new local_amos_execute_form(null, local_amos_execute_options());
if ($data = $executeform->get_data()) {
$version = mlang_version::by_code($data->version);
$stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
$instructions = mlang_tools::extract_script_from_text($data->script);
if (!empty($instructions)) {
foreach ($instructions as $instruction) {
$changes = mlang_tools::execute($instruction, $version);
if ($changes instanceof mlang_stage) {
foreach ($changes as $component) {
$stage->add($component, true);
}
$changes->clear();
} else if ($changes < 0) {
throw new moodle_exception('error_during_amoscript_execution', 'local_amos', '', null, $changes);
}
unset($changes);
}
}
$stage->rebase();
$stage->store();
if (!isset($SESSION->local_amos)) {
$SESSION->local_amos = new stdClass();
}
$SESSION->local_amos->presetcommitmessage = $data->script;
}
if (!isset($stage) or !$stage->has_component()) {
notice(get_string('nothingtostage', 'local_amos'), new moodle_url('/local/amos/stage.php'));
}
redirect(new moodle_url('/local/amos/stage.php'));