MDL-24751 fixed default memory limit when deciding to use apache_child_terminate...
[moodle.git] / grade / import / xml / import.php
CommitLineData
e060e33d 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
a700b5de 17
18require_once '../../../config.php';
1843999a 19require_once 'lib.php';
20require_once $CFG->libdir.'/filelib.php';
a700b5de 21
34058207 22$url = required_param('url', PARAM_URL); // only real urls here
23$id = required_param('id', PARAM_INT); // course id
24$feedback = optional_param('feedback', 0, PARAM_BOOL);
a700b5de 25
a6855934 26$url = new moodle_url('/grade/import/xml/import.php', array('id'=>$id,'url'=>$url));
beebcf26 27if ($feedback !== 0) {
28 $url->param('feedback', $feedback);
29}
30$PAGE->set_url($url);
31
f400841b 32if (!$course = $DB->get_record('course', array('id'=>$id))) {
a700b5de 33 print_error('nocourseid');
34}
35
36require_login($course);
37$context = get_context_instance(CONTEXT_COURSE, $id);
1843999a 38
a700b5de 39require_capability('moodle/grade:import', $context);
1843999a 40require_capability('gradeimport/xml:view', $context);
41
a700b5de 42
1843999a 43// Large files are likely to take their time and memory. Let PHP know
44// that we'll take longer, and that the process should be recycled soon
45// to free up memory.
46@set_time_limit(0);
47@raise_memory_limit("256M");
a700b5de 48
1843999a 49$text = download_file_content($url);
50if ($text === false) {
f39c16e0 51 print_error('cannotreadfile');
1843999a 52}
a700b5de 53
1843999a 54$error = '';
55$importcode = import_xml_grades($text, $course, $error);
a700b5de 56
1843999a 57if ($importcode !== false) {
6ef4878b 58 /// commit the code if we are up this far
a700b5de 59
1843999a 60 if (defined('USER_KEY_LOGIN')) {
34058207 61 if (grade_import_commit($id, $importcode, $feedback, false)) {
1843999a 62 echo 'ok';
63 die;
64 } else {
f39c16e0 65 print_error('cannotimportgrade'); //TODO: localize
a700b5de 66 }
67
1843999a 68 } else {
27eef3bb 69 print_grade_page_head($course->id, 'import', 'xml', get_string('importxml', 'grades'));
1843999a 70
34058207 71 grade_import_commit($id, $importcode, $feedback, true);
a700b5de 72
5a931394 73 echo $OUTPUT->footer();
a700b5de 74 die;
75 }
a700b5de 76
1843999a 77} else {
bd8ee7c1 78 print_error('error', 'gradeimport_xml');
1843999a 79}
a700b5de 80
6c3ef410 81