MDL-13114 tool_uploadcourse: Clean up

This commit is contained in:
Frederic Massart 2013-07-02 13:58:44 +08:00
parent 7a4ec85e2a
commit 3f57c87e1d
16 changed files with 99 additions and 1668 deletions

View File

@ -1,196 +0,0 @@
moodle-tool_uploadcourse
========================
Is a Moodle admin/tools plugin for uploading course outlines
in much the same way that admin/tools/uploaduser works for users.
These plugins became available from Moodle 2.2x and onwards, as
this is when the admin/tools framework first appeared.
https://gitorious.org/moodle-tool_uploadcourse
There is also a bulk course category upload function available at https://gitorious.org/moodle-tool_uploadcoursecategory
If you need to manage course enrolments via bulk upload then you should look at
the core user upload facility - http://docs.moodle.org/22/en/Upload_users
This takes CSV files as input and enables override or augmentation
with default parameter values.
All the usual add,updated,rename, and delete functions.
Thanks to Moshe Golden for help with getting the command line interface going.
!!!! NOTE !!!!
===============
This plugin used to come with the full directory structure
admin/tool/uploadcourse - this is nolonger the case so the
installation proceedure has changed!
General installation proceedures are here:
http://docs.moodle.org/20/en/Installing_contributed_modules_or_plugins
The basic process is:
Download https://gitorious.org/moodle-tool_uploadcourse/moodle-tool_uploadcourse/archive-tarball/master
unpack the file (probably called master) with tar -xzvf master
This will give you a directory called moodle-tool_uploadcourse-moodle-tool_uploadcourse
Move this directory and rename it into it's final position:
mv moodle-tool_uploadcourse-moodle-tool_uploadcourse <Moodle dirroot>/admin/tool/uploadcourse
Alternatively you can use git:
cd <Moodle dirroot>/admin/tool
git clone git@gitorious.org:moodle-tool_uploadcourse/moodle-tool_uploadcourse.git uploadcourse
Be careful about leaving the .git directory in your live environment.
CSV File format
===============
Possible column names are:
fullname, shortname, category, idnumber, summary,
format, showgrades, newsitems, teacher, editingteacher, student, modinfo,
manager, coursecreator, guest, user, startdate, numsections, maxbytes, visible, groupmode, restrictmodules,
enablecompletion, completionstartonenrol, completionnotify, hiddensections, groupmodeforce, lang, theme,
cost, showreports, notifystudents, expirynotify, expirythreshold, requested,
deleted, // 1 means delete course
oldshortname, // for renaming
backupfile, // for restoring a course template after creation
templatename, // course to use as a template - the shortname
reset, // reset the course contents after upload - this resets everything
- so you loose groups, roles, logs, grades etc. Be Careful!!!
An example file is:
fullname,shortname,category,idnumber,summary,backupfile
Computer Science 101,CS101,Cat1,CS101,The first thing you will ever know,/path/to/backup-moodle2-course-cs101-20120213-0748-nu.mbz
As a general rule, the input values for fields are what you find on the data entry form if you inspect the HTML element.
Format
======
The options for the format value are 'scorm', 'social', weeks', and 'topics'.
Role Names
===========
'teacher', 'editingteacher', 'student', 'manager',
'coursecreator', 'guest', 'user' are - where config permitting - you can
substitute your own name for these roles (string value).
Category
========
For category you must supply the category name as it is in Moodle and this
field is case sensitive. If Sub Categories are involved then the full
category hierarchy needs to be specified as a '/' delimited string eg:
'Miscellaneous / Sub Cat / Sub Sub Cat'. The delimiter can be escaped with
a back slash eg: 'some\/category'.
Course Templating
=================
add column backupfile which has the fully qualified path name to a file on
the server that has a a Moodle course backup in it.
Add a column templatename which is the shortname of an existing course that
will be copied over the top of the new course.
Course Enrolment Methods
=========================
Enrolment methods need special CSV columns as there can be many per course, and the fields for each
method are flexible. The following is an example with two enrolment methods - manual, and self - firstly you need
the column identifying the enrolment method enrolmethod_<n>, and then add the corresponding field values subscripted with _<n>.
eg:
fullname,shortname,category,idnumber,summary,enrolmethod_1,status_1,enrolmethod_2,name_2,password_2,customtext1_2
Parent,Parent,,Parent,Parent,manual,1,self,self1,letmein,this is a custom message 1
Students,Students,,Students,Students,manual,0,self,self2,letmein,this is a custom message 2
Teachers,Teachers,,Teachers,Teachers,manual,0,self,self3,letmein,this is a custom message 3
add the special columns for:
* delete - delete_<n> with value 1
* disable - disable_<n> with value 1
startdate enrol_startdate enrol_enddate
=======================================
For startdate enrolstartdate, and enrolenddate the values should be supplied in the form like 31.01.2012 or
31/01/2012 that can be consumed by strtotime() (http://php.net/manual/en/function.strtotime.php) - check
your PHP locale settings for the fine tuning eg: m/d/y vs d/m/y.
Enrolment method field 'enrolperiod' must be in seconds. If this is supplied then enrolenddate will be calculated
as enrolstartdate + enrolperiod.
enrolperiod should be supplied in multiples of enrolment period measurements - 1 hour = 3600, 1 day = 86400
and so on. OR - you can pass a text string that php strtotime() can recognise eg: '2 weeks' or '10 days'
Enrolment Method Role
=====================
Default Role for an enrolment method is supplied by adding the 'role_<n>' column. The expected value is the
descriptive label for the given role eg: 'Student', or "Teacher'.
Enrolment example:
fullname,shortname,category,idnumber,summary,enrolmethod_1,enrolperiod_1,role_1
a name,short1,Miscellaneous,id1,a summary,manual,864000,Manager
Update Course:
=================
Make sure you have shortname in the csv. After uploading the file, select:
Upload type: one of the update existing related options
Existing course details: Overide with file
Allow Renames: Yes
Update example:
fullname,shortname
new full name,short1
Run it in batch mode
=====================
Execute Course Upload in batch mode - this must be run as the www-data user (or the equivalent user that the web server runs under).
Options:
-v, --verbose Print verbose progress information
-h, --help Print out this help
-a, --action Action to perform - addnew, addupdate, update, forceadd
-m, --mode Mode of execution - delete, rename, nochange, file, filedefaults, missing
-f, --file CSV File
-d, --delimiter delimiter - colon,semicolon,tab,cfg,comma
-e, --encoding File encoding - utf8 etc
-c, --category Course category
-s, --templateshortname Template course by shortname
-t, --template Template course by backup file
-g, --format Course format - weeks,scorm,social,topics
-n, --numsections Number of sections
Example:
sudo -u www-data /usr/bin/php admin/tool/uploadcourse/cli/uploadcourse.php --action=addupdate \
--mode=delete --file=./courses.csv --delimiter=comma
Installation
=================
git clone this repository into <moodle root>/admin/tools/uploadcourse directory.
Point your browser at Moodle, and login as admin. This should kick off
the upgrade so that Moodle can now recognise the new plugin.
This was inspired in part by a need for a complimentary function for uploading
courses (as for users) for the the NZ MLE tools for Identity and
Access Managment (synchronising users with the School SMS):
https://gitorious.org/pla-udi
and
https://gitorious.org/pla-udi/mle_ide_tools
Copyright (C) Piers Harding 2011 and beyond, All rights reserved
moodle-tool_uploadcourse free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.

View File

@ -55,18 +55,19 @@ class tool_uploadcourse_base_form extends moodleform {
$mform->setExpanded('importoptionshdr', true);
$choices = array(
tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('ccoptype_addnew', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('ccoptype_addinc', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('ccoptype_addupdate', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('ccoptype_update', 'tool_uploadcourse')
tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('createnew', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('createall', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('createorupdate', 'tool_uploadcourse'),
tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('updateonly', 'tool_uploadcourse')
);
$mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices);
$choices = array(
tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'),
tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('ccupdatefromfile', 'tool_uploadcourse'),
tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS => get_string('ccupdateall', 'tool_uploadcourse'),
tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('ccupdatemissing', 'tool_uploadcourse')
tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('updatewithdataonly', 'tool_uploadcourse'),
tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS =>
get_string('updatewithdataordefaults', 'tool_uploadcourse'),
tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('updatemissing', 'tool_uploadcourse')
);
$mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices);
$mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING);

View File

@ -206,8 +206,11 @@ class tool_uploadcourse_course {
* @return bool
*/
public function can_update() {
return in_array($this->mode, array(tool_uploadcourse_processor::MODE_UPDATE_ONLY,
tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE)) && $this->updatemode != tool_uploadcourse_processor::UPDATE_NOTHING;
return in_array($this->mode,
array(
tool_uploadcourse_processor::MODE_UPDATE_ONLY,
tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE)
) && $this->updatemode != tool_uploadcourse_processor::UPDATE_NOTHING;
}
/**
@ -227,7 +230,8 @@ class tool_uploadcourse_course {
*/
protected function delete() {
global $DB;
$this->id = $DB->get_field_select('course', 'id', 'shortname = :shortname', array('shortname' => $this->shortname), MUST_EXIST);
$this->id = $DB->get_field_select('course', 'id', 'shortname = :shortname',
array('shortname' => $this->shortname), MUST_EXIST);
return delete_course($this->id, false);
}
@ -248,6 +252,7 @@ class tool_uploadcourse_course {
/**
* Return whether the course exists or not.
*
* @param string $shortname the shortname to use to check if the course exists. Falls back on $this->shortname if empty.
* @return bool
*/
protected function exists($shortname = null) {
@ -424,7 +429,8 @@ class tool_uploadcourse_course {
// Can we create/update the course under those conditions?
if ($exists) {
if ($this->mode === tool_uploadcourse_processor::MODE_CREATE_NEW) {
$this->error('courseexistsanduploadnotallowed', new lang_string('courseexistsanduploadnotallowed', 'tool_uploadcourse'));
$this->error('courseexistsanduploadnotallowed',
new lang_string('courseexistsanduploadnotallowed', 'tool_uploadcourse'));
return false;
}
} else {
@ -520,7 +526,8 @@ class tool_uploadcourse_course {
new lang_string('cannotgenerateshortnameupdatemode', 'tool_uploadcourse'));
return false;
} else {
$newshortname = tool_uploadcourse_helper::generate_shortname($coursedata, $this->importoptions['shortnametemplate']);
$newshortname = tool_uploadcourse_helper::generate_shortname($coursedata,
$this->importoptions['shortnametemplate']);
if (is_null($newshortname)) {
$this->error('generatedshortnameinvalid', new lang_string('generatedshortnameinvalid', 'tool_uploadcourse'));
return false;
@ -639,7 +646,7 @@ class tool_uploadcourse_course {
// TODO log warnings.
$this->restoredata = $this->get_restore_content_dir();
// We cannot
// We can only reset courses when allowed and we are updating the course.
if ($this->importoptions['reset'] || $this->options['reset']) {
if ($this->do !== self::DO_UPDATE) {
$this->error('canonlyresetcourseinupdatemode',
@ -837,6 +844,7 @@ class tool_uploadcourse_course {
*
* This does not reset any of the content of the activities.
*
* @param stdClass $course the course object of the course to reset.
* @return array status array of array component, item, error.
*/
protected function reset($course) {

View File

@ -29,10 +29,13 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
/**
* Class containing a set of helpers.
*
* @package tool_uploadcourse
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_uploadcourse_helper {
/** @var array category idnumber cache. */
static protected $categoryidnumbercache = array();

View File

@ -257,7 +257,6 @@ class tool_uploadcourse_processor {
/**
* Get the directory of the object to restore.
*
* @param string $default directory to use if none found.
* @return string subdirectory in $CFG->tempdir/backup/...
*/
protected function get_restore_content_dir() {

View File

@ -51,7 +51,8 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
$mform->addElement('header', 'courseoptionshdr', get_string('courseprocess', 'tool_uploadcourse'));
$mform->setExpanded('courseoptionshdr', true);
$mform->addElement('text', 'options[shortnametemplate]', get_string('shortnametemplate', 'tool_uploadcourse'), 'maxlength="100" size="20"');
$mform->addElement('text', 'options[shortnametemplate]', get_string('shortnametemplate', 'tool_uploadcourse'),
'maxlength="100" size="20"');
$mform->setType('options[shortnametemplate]', PARAM_RAW);
$mform->addHelpButton('options[shortnametemplate]', 'shortnametemplate', 'tool_uploadcourse');
$mform->disabledIf('options[shortnametemplate]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE);
@ -113,7 +114,7 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
$mform->addElement('select', 'defaults[theme]', get_string('forcetheme'), $themes);
}
$languages[] = array();
$languages = array();
$languages[''] = get_string('forceno');
$languages += get_string_manager()->get_list_of_translations();
$mform->addElement('select', 'defaults[lang]', get_string('forcelanguage'), $languages);
@ -162,8 +163,8 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
$mform->setDefault('defaults[groupmodeforce]', $courseconfig->groupmodeforce);
// Hidden fields.
$mform->addElement('hidden', 'iid');
$mform->setType('iid', PARAM_INT);
$mform->addElement('hidden', 'importid');
$mform->setType('importid', PARAM_INT);
$mform->addElement('hidden', 'previewrows');
$mform->setType('previewrows', PARAM_INT);
@ -180,7 +181,7 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
* @param string $submitlabel label for submit button, defaults to get_string('savechanges')
* @return void
*/
function add_action_buttons($cancel = true, $submitlabel = null){
public function add_action_buttons($cancel = true, $submitlabel = null) {
$mform =& $this->_form;
$buttonarray = array();
$buttonarray[] = &$mform->createElement('submit', 'showpreview', get_string('preview', 'tool_uploadcourse'));

View File

@ -207,7 +207,8 @@ class tool_uploadcourse_tracker {
echo html_writer::start_tag('table', array('class' => 'generaltable boxaligncenter flexible-wrap',
'summary' => get_string('uploadcoursesresult', 'tool_uploadcourse')));
echo html_writer::start_tag('tr', array('class' => 'heading r' . $this->rownb));
echo html_writer::tag('th', get_string('csvline', 'tool_uploadcourse'), array('class' => 'c' . $ci++, 'scope' => 'col'));
echo html_writer::tag('th', get_string('csvline', 'tool_uploadcourse'),
array('class' => 'c' . $ci++, 'scope' => 'col'));
echo html_writer::tag('th', get_string('result', 'tool_uploadcourse'), array('class' => 'c' . $ci++, 'scope' => 'col'));
echo html_writer::tag('th', get_string('id', 'tool_uploadcourse'), array('class' => 'c' . $ci++, 'scope' => 'col'));
echo html_writer::tag('th', get_string('shortname'), array('class' => 'c' . $ci++, 'scope' => 'col'));

View File

@ -25,7 +25,6 @@
define('CLI_SCRIPT', true);
require(__DIR__ . '/../../../../config.php');
require_once(__DIR__ . '/../locallib.php');
require_once($CFG->libdir . '/clilib.php');
require_once($CFG->libdir . '/coursecatlib.php');
require_once($CFG->libdir . '/csvlib.class.php');
@ -188,8 +187,8 @@ cron_setup_user();
// Let's get started!
$content = file_get_contents($options['file']);
$iid = csv_import_reader::get_new_iid('uploadcourse');
$cir = new csv_import_reader($iid, 'uploadcourse');
$importid = csv_import_reader::get_new_iid('uploadcourse');
$cir = new csv_import_reader($importid, 'uploadcourse');
$readcount = $cir->load_csv_content($content, $options['encoding'], $options['delimiter']);
unset($content);
if ($readcount === false) {

View File

@ -23,24 +23,22 @@
*/
require(__DIR__ . '/../../../config.php');
require_once(__DIR__ . '/locallib.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/clilib.php');
require_once($CFG->libdir . '/coursecatlib.php');
require_once($CFG->libdir . '/csvlib.class.php');
admin_externalpage_setup('tooluploadcourse');
$iid = optional_param('iid', '', PARAM_INT);
$importid = optional_param('importid', '', PARAM_INT);
$previewrows = optional_param('previewrows', 10, PARAM_INT);
$returnurl = new moodle_url('/admin/tool/uploadcourse/index.php');
if (empty($iid)) {
if (empty($importid)) {
$mform1 = new tool_uploadcourse_step1_form();
if ($form1data = $mform1->get_data()) {
$iid = csv_import_reader::get_new_iid('uploadcourse');
$cir = new csv_import_reader($iid, 'uploadcourse');
$importid = csv_import_reader::get_new_iid('uploadcourse');
$cir = new csv_import_reader($importid, 'uploadcourse');
$content = $mform1->get_file_content('coursefile');
$readcount = $cir->load_csv_content($content, $form1data->encoding, $form1data->delimiter_name);
unset($content);
@ -57,11 +55,11 @@ if (empty($iid)) {
die();
}
} else {
$cir = new csv_import_reader($iid, 'uploadcourse');
$cir = new csv_import_reader($importid, 'uploadcourse');
}
// Data to set in the form.
$data = array('iid' => $iid, 'previewrows' => $previewrows);
$data = array('importid' => $importid, 'previewrows' => $previewrows);
if (!empty($form1data)) {
// Get options from the first form to pass it onto the second.
foreach ($form1data->options as $key => $value) {

View File

@ -15,11 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'tool_uploadcourse', language 'en', branch 'MOODLE_22_STABLE'
* Strings for component 'tool_uploadcourse'.
*
* @package tool_uploadcourse
* @subpackage uploadcourse
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @copyright 2011 Piers Harding
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -61,6 +59,9 @@ $string['coursetemplatename'] = 'Restore from this course after upload';
$string['coursetemplatename_help'] = 'Enter an existing course shortname to use as a template for the creation of all courses.';
$string['coursetorestorefromdoesnotexist'] = 'The course to restore from does not exist';
$string['courseupdated'] = 'Course updated';
$string['createall'] = 'Create all, increment shortname if needed';
$string['createnew'] = 'Create new courses only, skip existing ones';
$string['createorupdate'] = 'Create new courses, or update existing ones';
$string['csvdelimiter'] = 'CSV delimiter';
$string['csvfileerror'] = 'There is something wrong with the format of the CSV file. Please check the number of headings and columns match, and that the delimiter and file encoding are correct: {$a}';
$string['csvline'] = 'Line';
@ -84,6 +85,8 @@ $string['invalidshortname'] = 'Invalid shortname';
$string['missingmandatoryfields'] = 'Missing value for mandatory fields: {$a}';
$string['missingshortnamenotemplate'] = 'Missing shortname and shortname template not set';
$string['mode'] = 'Upload mode';
$string['nochanges'] = 'No changes';
$string['pluginname'] = 'Course upload';
$string['preview'] = 'Preview';
$string['reset'] = 'Reset course after upload';
$string['result'] = 'Result';
@ -94,8 +97,12 @@ $string['shortnametemplate_help'] = 'The short name of the course is displayed i
$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['unknownimportmode'] = 'Unknown import mode';
$string['updatemissing'] = 'Fill in missing from CSV data and defaults';
$string['updatemode'] = 'Update mode';
$string['updatemodedoessettonothing'] = 'Update mode does not allow anything to be updated';
$string['updateonly'] = 'Only update existing courses';
$string['updatewithdataordefaults'] = 'Update with CSV data and defaults';
$string['updatewithdataonly'] = 'Update with CSV data only';
$string['uploadcourses'] = 'Upload courses';
$string['uploadcourses_help'] = 'Courses may be uploaded via text file. The format of the file should be as follows:
@ -103,89 +110,5 @@ $string['uploadcourses_help'] = 'Courses may be uploaded via text file. The form
* Each record is a series of data separated by commas (or other delimiters)
* The first record contains a list of fieldnames defining the format of the rest of the file
* Required fieldnames are shortname, fullname, summary and category';
$string['uploadcoursesresult'] = 'Upload courses results';
$string['deleteerrors'] = 'Delete errors';
$string['errors'] = 'Errors';
$string['invalidinput'] = 'You must specify a valid combination of --action and --mode';
$string['nochanges'] = 'No changes';
$string['pluginname'] = 'Course upload';
$string['renameerrors'] = 'Rename errors';
$string['requiredtemplate'] = 'Required. You may use template syntax here (%l = lastname, %f = firstname, %u = coursename). See help for details and examples.';
$string['uploadpicture_badcoursefield'] = 'The course attribute specified is not valid. Please, try again.';
$string['uploadpicture_cannotmovezip'] = 'Cannot move zip file to temporary directory.';
$string['uploadpicture_cannotprocessdir'] = 'Cannot process unzipped files.';
$string['uploadpicture_cannotsave'] = 'Cannot save picture for course {$a}. Check original picture file.';
$string['uploadpicture_cannotunzip'] = 'Cannot unzip pictures file.';
$string['uploadpicture_invalidfilename'] = 'Picture file {$a} has invalid characters in its name. Skipping.';
$string['uploadpicture_overwrite'] = 'Overwrite existing course pictures?';
$string['uploadpicture_coursefield'] = 'Course attribute to use to match pictures:';
$string['uploadpicture_coursenotfound'] = 'Course with a \'{$a->coursefield}\' value of \'{$a->coursevalue}\' does not exist. Skipping.';
$string['uploadpicture_courseskipped'] = 'Skipping course {$a} (already has a picture).';
$string['uploadpicture_courseupdated'] = 'Picture updated for course {$a}.';
$string['uploadpictures'] = 'Upload course pictures';
$string['uploadpictures_help'] = 'Course pictures can be uploaded as a zip file of image files. The image files should be named chosen-course-attribute.extension, for example course1234.jpg for a course with coursename course1234.';
$string['uploadcoursespreview'] = 'Upload courses preview';
$string['courseuptodate'] = 'Course up-to-date';
$string['courseupdated'] = 'Course updated';
$string['coursedeleted'] = 'Course deleted';
$string['courserenamed'] = 'Course renamed';
$string['coursesrenamed'] = 'Courses renamed';
$string['coursesskipped'] = 'Courses skipped';
$string['coursenotadded'] = 'Course not added - already exists';
$string['coursenotaddederror'] = 'Course not added - error';
$string['coursenotdeletederror'] = 'Course not deleted - error';
$string['coursenotdeletedmissing'] = 'Course not deleted - missing';
$string['coursenotdeletedoff'] = 'Course not deleted - delete off';
$string['coursenotdeletedadmin'] = 'Course not deleted - no admin access';
$string['coursenotupdatederror'] = 'Course not updated - error';
$string['coursenotupdatednotexists'] = 'Course not updated - does not exist';
$string['coursenotupdatedadmin'] = 'Course not updated - no admin';
$string['coursenotrenamedexists'] = 'Course not renamed - target exists';
$string['coursenotrenamedmissing'] = 'Course not renamed - source missing';
$string['coursenotrenamedoff'] = 'Course not renamed - renaming off';
$string['coursenotrenamedadmin'] = 'Course not renamed - no admin';
$string['invalidvalue'] = 'Invalid value for field {$a}';
$string['shortnamecourse'] = 'Shortname';
$string['idnumbernotunique'] = 'idnumber is not unique';
$string['ccbulk'] = 'Select for bulk operations';
$string['ccbulkall'] = 'All courses';
$string['ccbulknew'] = 'New courses';
$string['ccbulkupdated'] = 'Updated courses';
$string['cclegacy1role'] = '(Original Student) typeN=1';
$string['cclegacy2role'] = '(Original Teacher) typeN=2';
$string['cclegacy3role'] = '(Original Non-editing teacher) typeN=3';
$string['ccnoemailduplicates'] = 'Prevent email address duplicates';
$string['ccoptype_addinc'] = 'Add all, append number to shortnames if needed';
$string['ccoptype_addnew'] = 'Add new only, skip existing courses';
$string['ccoptype_addupdate'] = 'Add new and update existing courses';
$string['ccoptype_update'] = 'Update existing courses only';
$string['ccpasswordcron'] = 'Generated in cron';
$string['ccpasswordnew'] = 'New course password';
$string['ccpasswordold'] = 'Existing course password';
$string['ccstandardshortnames'] = 'Standardise shortnames';
$string['ccupdateall'] = 'Override with file and defaults';
$string['ccupdatefromfile'] = 'Override with file';
$string['ccupdatemissing'] = 'Fill in missing from file and defaults';
$string['ccupdatetype'] = 'Existing course details';
$string['ccfullnametemplate'] = 'Fullname template';
$string['ccidnumbertemplate'] = 'Idnumber template';
$string['missingtemplate'] = 'Template not found';
$string['missing'] = 'missing';
$string['incorrectformat'] = 'Invalid format specified';
$string['incorrecttemplatefile'] = 'Template file not found';
$string['invalidenrolmethod'] = 'Invalid enrolment method';
$string['invalidaction'] = 'Invalid action selected';
$string['invalidcategory'] = 'Invalid category';
$string['invalidbackupfile'] = 'Invalid backup file';
$string['uploadcoursesresult'] = 'Upload courses results';

File diff suppressed because it is too large Load Diff

View File

@ -15,19 +15,16 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Link to CSV course upload
* Link to CSV course upload.
*
* @package tool_uploadcourse
* @subpackage uploadcourse
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @copyright 2011 Piers Harding
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();
if (has_capability('moodle/restore:restorecourse', $systemcontext)) {
if ($hassiteconfig) {
$ADMIN->add('courses', new admin_externalpage('tooluploadcourse',
get_string('uploadcourses', 'tool_uploadcourse'),
"$CFG->wwwroot/$CFG->admin/tool/uploadcourse/index.php", 'moodle/site:uploadusers'));
get_string('uploadcourses', 'tool_uploadcourse'), "/admin/tool/uploadcourse/index.php"));
}

View File

@ -28,6 +28,10 @@ global $CFG;
/**
* Course test case.
*
* @package tool_uploadcourse
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
class tool_uploadcourse_course_testcase extends advanced_testcase {
@ -239,7 +243,6 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'enrolment_3_disable' => '1',
);
$this->assertFalse($DB->record_exists('course', array('shortname' => 'c1')));
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
@ -409,7 +412,6 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'enablecompletion' => '1',
);
$this->assertFalse($DB->record_exists('course', array('shortname' => 'c1')));
$co = new tool_uploadcourse_course($mode, $updatemode, $data, $defaultdata);
$this->assertTrue($co->prepare());
@ -576,7 +578,8 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
$data = array('shortname' => 'A1', 'templatecourse' => $c1->shortname, 'summary' => 'A', 'category' => 1, 'fullname' => 'A1');
$data = array('shortname' => 'A1', 'templatecourse' => $c1->shortname, 'summary' => 'A', 'category' => 1,
'fullname' => 'A1');
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();

View File

@ -28,10 +28,14 @@ global $CFG;
/**
* Helper test case.
*
* @package tool_uploadcourse
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_uploadcourse_helper_testcase extends advanced_testcase {
function test_generate_shortname() {
public function test_generate_shortname() {
$data = (object) array('fullname' => 'Ah Bh Ch 01 02 03', 'idnumber' => 'ID123');
$this->assertSame($data->fullname, tool_uploadcourse_helper::generate_shortname($data, '%f'));
@ -41,14 +45,14 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$this->assertSame('[Ah Bh Ch] = ID123', tool_uploadcourse_helper::generate_shortname($data, '[%8f] = %i'));
}
function test_get_course_formats() {
public function test_get_course_formats() {
$result = tool_uploadcourse_helper::get_course_formats();
$this->assertSame(array_keys(get_plugin_list('format')), $result);
// Should be similar as first result, as cached.
$this->assertSame($result, tool_uploadcourse_helper::get_course_formats());
}
function test_get_enrolment_data() {
public function test_get_enrolment_data() {
$this->resetAfterTest(true);
$data = array(
'enrolment_1' => 'unknown',
@ -94,16 +98,17 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$this->assertSame(tool_uploadcourse_helper::get_enrolment_data($data), $expected);
}
function test_get_enrolment_plugins() {
public function test_get_enrolment_plugins() {
$this->resetAfterTest(true);
$actual = tool_uploadcourse_helper::get_enrolment_plugins();
$this->assertSame(array_keys(enrol_get_plugins(false)), array_keys($actual));
// This should be identical as cached.
$secondactual = tool_uploadcourse_helper::get_enrolment_plugins();
$this->assertSame($actual, $secondactual);
$this->assertEquals($actual, $secondactual);
}
function test_get_restore_content_dir() {
public function test_get_restore_content_dir() {
global $CFG;
$this->resetAfterTest(true);
$this->setAdminUser();
@ -144,7 +149,6 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$this->assertEquals($bcinfo->original_course_id, $c2->id);
$this->assertEquals($bcinfo->original_course_fullname, $c2->fullname);
// Checking with a shortname.
$dir = tool_uploadcourse_helper::get_restore_content_dir(null, $c1->shortname);
$bcinfo = backup_general_helper::get_backup_information($dir);
@ -161,6 +165,21 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$this->assertEquals($bcinfo->original_course_id, $c2->id);
$this->assertEquals($bcinfo->original_course_fullname, $c2->fullname);
// Cleaning content directories.
$oldcfg = isset($CFG->keeptempdirectoriesonbackup) ? $CFG->keeptempdirectoriesonbackup : false;
$dir = "$CFG->tempdir/backup/$dir";
$this->assertTrue(file_exists($dir));
$CFG->keeptempdirectoriesonbackup = false;
tool_uploadcourse_helper::clean_restore_content();
$this->assertTrue(file_exists($dir));
$CFG->keeptempdirectoriesonbackup = true;
tool_uploadcourse_helper::clean_restore_content();
$this->assertFalse(file_exists($dir));
$CFG->keeptempdirectoriesonbackup = $oldcfg;
// Restore the time limit to prevent warning.
set_time_limit(0);
}

View File

@ -25,9 +25,14 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
/**
* Processor test case.
*
* @package tool_uploadcourse
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_uploadcourse_processor_testcase extends advanced_testcase {

View File

@ -15,17 +15,15 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin version info
* Plugin version info.
*
* @package tool_uploadcourse
* @subpackage uploadcourse
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @copyright 2011 Piers Harding
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2012112301; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2011091600; // Requires this Moodle version
$plugin->component = 'tool_uploadcourse'; // Full name of the plugin (used for diagnostics).
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2013070200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2013062100; // Requires this Moodle version.
$plugin->component = 'tool_uploadcourse'; // Full name of the plugin (used for diagnostics).