/**
* Execute the process.
*
+ * @param object $tracker the output tracker to use.
* @return void
*/
- public function execute() {
+ public function execute($tracker = null) {
if ($this->processstarted) {
throw new coding_exception('Process has already been started');
}
$this->processstarted = true;
- $tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_PLAIN);
+ if (empty($tracker)) {
+ $tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::NO_OUTPUT);
+ }
$tracker->start();
+ $total = 0;
+ $created = 0;
+ $updated = 0;
+ $deleted = 0;
+ $errors = 0;
+
// Loop over the CSV lines.
while ($line = $this->cir->next()) {
$this->linenb++;
+ $total++;
$data = $this->parse_line($line);
$course = $this->get_course($data);
if ($course->prepare()) {
$course->proceed();
- $tracker->output($this->linenb, true, $course->get_statuses(), $data);
+
+ $status = $course->get_statuses();
+ if (array_key_exists('coursecreated', $status)) {
+ $created++;
+ } else if (array_key_exists('courseupdated', $status)) {
+ $updated++;
+ } else if (array_key_exists('coursedeleted', $status)) {
+ $deleted++;
+ }
+
+ $tracker->output($this->linenb, true, $status, $data);
} else {
+ $errors++;
$tracker->output($this->linenb, false, $course->get_errors(), $data);
}
}
$tracker->finish();
+ $tracker->results($total, $created, $updated, $deleted, $errors);
$this->remove_restore_content();
}
* This only returns passed data, along with the errors.
*
* @param integer $rows number of rows to preview.
+ * @param object $tracker the output tracker to use.
* @return array of preview data.
*/
- public function preview($rows = 10) {
+ public function preview($rows = 10, $tracker = null) {
if ($this->processstarted) {
throw new coding_exception('Process has already been started');
}
$this->processstarted = true;
- $tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_PLAIN);
+
+ if (empty($tracker)) {
+ $tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::NO_OUTPUT);
+ }
$tracker->start();
// Loop over the CSV lines.
$string['coursereset'] = 'Course reset';
$string['courseresetnotallowed'] = 'Course reset now allowed';
$string['courserestored'] = 'Course restored';
+$string['coursestotal'] = 'Courses total: {$a}';
+$string['coursescreated'] = 'Courses created: {$a}';
+$string['coursesupdated'] = 'Courses updated: {$a}';
+$string['coursesdeleted'] = 'Courses deleted: {$a}';
+$string['courseserrors'] = 'Courses errors: {$a}';
$string['courseshortnameincremented'] = 'Course shortname incremented {$a->from} -> {$a->to}';
$string['courseshortnamegenerated'] = 'Course shortname generated: {$a}';
$string['coursetorestorefromdoesnotexist'] = 'The course to restore from does not exist';
$string['generatedshortnameinvalid'] = 'The generated shortname is invalid';
$string['generatedshortnamealreadyinuse'] = 'The generated shortname is already in use';
$string['id'] = 'ID';
+$string['idnumberalreadyinuse'] = 'ID number already used by a course';
$string['invalidbackupfile'] = 'Invalid backup file';
$string['invalidcourseformat'] = 'Invalid course format';
$string['invalidroles'] = 'Invalid role names: {$a}';
* The first record contains a list of fieldnames defining the format of the rest of the file
* Required fieldnames are coursename, password, firstname, lastname, email';
$string['uploadcoursespreview'] = 'Upload courses preview';
-$string['courseupdated'] = 'Course updated';
$string['courseuptodate'] = 'Course up-to-date';
+$string['courseupdated'] = 'Course updated';
$string['coursedeleted'] = 'Course deleted';
$string['courserenamed'] = 'Course renamed';
-$string['coursescreated'] = 'Courses created';
-$string['coursesdeleted'] = 'Courses deleted';
$string['coursesrenamed'] = 'Courses renamed';
$string['coursesskipped'] = 'Courses skipped';
-$string['coursesupdated'] = 'Courses updated';
$string['coursenotadded'] = 'Course not added - already exists';
$string['coursenotaddederror'] = 'Course not added - error';
$string['coursenotdeletederror'] = 'Course not deleted - error';