Permalink
Browse files

Revert "Merge branch 'MDL-43127-master' of git://github.com/FMCorz/mo…

…odle"

This reverts commit 4e75dd7, reversing
changes made to f376c2f.
  • Loading branch information...
danpoltawski committed Nov 27, 2014
1 parent e6f5a4b commit 853b6cff9b75f5393f7df5ea9798aa46e446025f
@@ -108,9 +108,6 @@ class tool_uploadcourse_course {
static protected $importoptionsdefaults = array('canrename' => false, 'candelete' => false, 'canreset' => false,
'reset' => false, 'restoredir' => null, 'shortnametemplate' => null);
/** @var array special fields used when processing the enrolment methods. */
static protected $enrolmentspecialfields = array('delete', 'disable', 'startdate', 'enddate', 'enrolperiod', 'role');
/**
* Constructor
*
@@ -658,18 +655,9 @@ public function prepare() {
return false;
}
// Getting the enrolment data.
$errors = array();
$this->enrolmentdata = tool_uploadcourse_helper::get_enrolment_data($this->rawdata, $errors);
if (!empty($errors)) {
foreach ($errors as $key => $message) {
$this->error($key, $message);
}
return false;
}
// Saving data.
$this->data = $coursedata;
$this->enrolmentdata = tool_uploadcourse_helper::get_enrolment_data($this->rawdata);
// Restore data.
// TODO Speed up things by not really extracting the backup just yet, but checking that
@@ -781,20 +769,10 @@ protected function process_enrolment_data($course) {
return;
}
$cannotaddmethods = array();
$enrolmentplugins = tool_uploadcourse_helper::get_enrolment_plugins();
$instances = enrol_get_instances($course->id, false);
foreach ($enrolmentdata as $enrolmethod => $method) {
$plugin = $enrolmentplugins[$enrolmethod];
// TODO MDL-48362 Abstract the logic to prevent it to be tied to the
// user interface. Ideally a plugin should have a method that returns
// whether or not a new instance can be added to the course rather than
// using enrol_plugin::get_newinstance_link() to figure that out.
$canadd = $plugin->get_newinstance_link($course->id);
// TODO MDL-43820 Handle multiple instances of the same type.
$instance = null;
foreach ($instances as $i) {
if ($i->enrol == $enrolmethod) {
@@ -828,57 +806,30 @@ protected function process_enrolment_data($course) {
}
}
} else {
$plugin = null;
if (empty($instance)) {
// Check if we can create a new instance of this enrolment method.
if (!$canadd) {
$cannotaddmethods[] = $enrolmethod;
continue;
}
// Some plugins do not implement enrol_plugin::add_default_instance(),
// but we will try anyway and call enrol_plugin::add_instance() if needed.
$id = $plugin->add_default_instance($course);
if (empty($id)) {
$id = $plugin->add_instance($course);
}
$plugin = $enrolmentplugins[$enrolmethod];
$instance = new stdClass();
$instance->id = $id;
$instance->id = $plugin->add_default_instance($course);
$instance->roleid = $plugin->get_config('roleid');
$instance->status = ENROL_INSTANCE_ENABLED;
} else {
$plugin = $enrolmentplugins[$instance->enrol];
$plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
}
// Now update values.
foreach ($method as $k => $v) {
if (in_array($k, self::$enrolmentspecialfields)) {
// Skip the special import keys.
continue;
}
$instance->{$k} = $v;
}
// Sort out the start, end and date.
if (isset($method['startdate'])) {
$instance->enrolstartdate = strtotime($method['startdate']);
} else if (!isset($instance->enrolstartdate)) {
$instance->enrolstartdate = 0;
}
if (isset($method['enddate'])) {
$instance->enrolenddate = strtotime($method['enddate']);
} else if (!isset($instance->enrolenddate)) {
$instance->enrolenddate = 0;
}
$instance->enrolstartdate = (isset($method['startdate']) ? strtotime($method['startdate']) : 0);
$instance->enrolenddate = (isset($method['enddate']) ? strtotime($method['enddate']) : 0);
// Is the enrolment period set?
if (isset($method['enrolperiod'])) {
if (empty($method['enrolperiod'])) {
// Let's just make sure that it's 0.
$method['enrolperiod'] = 0;
} else if (preg_match('/^\d+$/', $method['enrolperiod'])) {
// Cast integers to integers.
if (isset($method['enrolperiod']) && ! empty($method['enrolperiod'])) {
if (preg_match('/^\d+$/', $method['enrolperiod'])) {
$method['enrolperiod'] = (int) $method['enrolperiod'];
} else {
// Try and convert period to seconds.
@@ -908,11 +859,6 @@ protected function process_enrolment_data($course) {
$DB->update_record('enrol', $instance);
}
}
if (!empty($cannotaddmethods)) {
$this->error('cannotaddenrolmentmethods', new lang_string('cannotaddenrolmentmethods', 'tool_uploadcourse',
implode(', ', $cannotaddmethods)));
}
}
/**
@@ -134,10 +134,9 @@ public static function get_course_formats() {
* )
*
* @param array $data data to extract the enrolment data from.
* @param array $errors will be populated with errors found.
* @return array
*/
public static function get_enrolment_data($data, &$errors = array()) {
public static function get_enrolment_data($data) {
$enrolmethods = array();
$enroloptions = array();
foreach ($data as $field => $value) {
@@ -159,26 +158,16 @@ public static function get_enrolment_data($data, &$errors = array()) {
// Combining enrolment methods and their options in a single array.
$enrolmentdata = array();
$unknownmethods = array();
$methodsnotsupported = array();
if (!empty($enrolmethods)) {
$enrolmentplugins = self::get_enrolment_plugins();
foreach ($enrolmethods as $key => $method) {
if (!array_key_exists($method, $enrolmentplugins)) {
// Unknown enrolment method.
$unknownmethods[] = $method;
// Error!
continue;
}
$enrolmentdata[$enrolmethods[$key]] = $enroloptions[$key];
}
}
// Logging errors related to enrolment methods.
if (!empty($unknownmethods)) {
$errors['unknownenrolmentmethods'] = new lang_string('unknownenrolmentmethods', 'tool_uploadcourse',
implode(', ', $unknownmethods));
}
return $enrolmentdata;
}
@@ -207,7 +207,6 @@ public function execute($tracker = null) {
$course = $this->get_course($data);
if ($course->prepare()) {
$course->proceed();
$outcome = 1;
$status = $course->get_statuses();
if (array_key_exists('coursecreated', $status)) {
@@ -218,19 +217,11 @@ public function execute($tracker = null) {
$deleted++;
}
// Errors can occur even though the course preparation returned true, often because
// some checks could not be done in course::prepare() because it requires the course to exist.
if ($course->has_errors()) {
$status += $course->get_errors();
$errors++;
$outcome = 2;
}
$data = array_merge($data, $course->get_data(), array('id' => $course->get_id()));
$tracker->output($this->linenb, $outcome, $status, $data);
$tracker->output($this->linenb, true, $status, $data);
} else {
$errors++;
$tracker->output($this->linenb, 0, $course->get_errors(), $data);
$tracker->output($this->linenb, false, $course->get_errors(), $data);
}
}
@@ -136,8 +136,7 @@ public function results($total, $created, $updated, $deleted, $errors) {
* Output one more line.
*
* @param int $line line number.
* @param int $outcome 0 for failure, 1 for success, 2 for success with errors. Use 2 when
* most of the process succeeded but there might have been outstanding errors.
* @param bool $outcome success or not?
* @param array $status array of statuses.
* @param array $data extra data to display.
* @return void
@@ -149,16 +148,9 @@ public function output($line, $outcome, $status, $data) {
}
if ($this->outputmode == self::OUTPUT_PLAIN) {
if ($outcome == 1) {
$ok = 'OK';
} else if (!$outcome) {
$ok = 'NOK'; // Not OK.
} else {
$ok = 'EOK'; // Errors, but OK.
}
$message = array(
$line,
$ok,
$outcome ? 'OK' : 'NOK',
isset($data['id']) ? $data['id'] : '',
isset($data['shortname']) ? $data['shortname'] : '',
isset($data['fullname']) ? $data['fullname'] : '',
@@ -176,12 +168,10 @@ public function output($line, $outcome, $status, $data) {
if (is_array($status)) {
$status = implode(html_writer::empty_tag('br'), $status);
}
if ($outcome == 1) {
if ($outcome) {
$outcome = $OUTPUT->pix_icon('i/valid', '');
} else if (!$outcome) {
$outcome = $OUTPUT->pix_icon('i/invalid', '');
} else {
$outcome = $OUTPUT->pix_icon('i/caution', '');
$outcome = $OUTPUT->pix_icon('i/invalid', '');
}
echo html_writer::start_tag('tr', array('class' => 'r' . $this->rownb % 2));
echo html_writer::tag('td', $line, array('class' => 'c' . $ci++));
@@ -29,7 +29,6 @@
$string['allowresets'] = 'Allow resets';
$string['allowresets_help'] = 'Whether the reset field is accepted or not.';
$string['cachedef_helper'] = 'Helper caching';
$string['cannotaddenrolmentmethods'] = 'Cannot add the enrolment methods: {$a}';
$string['cannotdeletecoursenotexist'] = 'Cannot delete a course that does not exist';
$string['cannotgenerateshortnameupdatemode'] = 'Cannot generate a shortname when updates are allowed';
$string['cannotreadbackupfile'] = 'Cannot read the backup file';
@@ -110,7 +109,6 @@
$string['shortnametemplate_help'] = 'The short name of the course is displayed in the navigation. You may use template syntax here (%f = fullname, %i = idnumber), or enter an initial value that is incremented.';
$string['templatefile'] = 'Restore from this file after upload';
$string['templatefile_help'] = 'Select a file to use as a template for the creation of all courses.';
$string['unknownenrolmentmethods'] = 'Unknown enrolment methods: {$a}';
$string['unknownimportmode'] = 'Unknown import mode';
$string['updatemissing'] = 'Fill in missing items from CSV data and defaults';
$string['updatemode'] = 'Update mode';
Oops, something went wrong.

0 comments on commit 853b6cf

Please sign in to comment.