/// Main savepoint reached
upgrade_main_savepoint($result, 2009021801);
}
-
/// Add default sort order for question types.
if ($result && $oldversion < 2009030300) {
set_config('multichoice_sortorder', 1, 'question');
upgrade_main_savepoint($result, 2009030300);
}
+ if ($result && $oldversion < 2009030501) {
+ /// setup default repository plugins
+ require_once($CFG->dirroot . '/repository/lib.php');
+ repository_setup_default_plugins();
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2009030501);
+ }
return $result;
}
/**
* Create a repository type (the type name must not already exist)
+ * @param boolean throw exception?
+ * @return mixed return int if create successfully, return false if
+ * any errors
* @global object $DB
*/
- public function create() {
+ public function create($silent = false) {
global $DB;
//check that $type has been set
if (!$existingtype) {
//run init function
if (!repository::static_function($this->_typename, 'plugin_init')) {
- throw new repository_exception('cannotcreatetype', 'repository');
+ if (!$silent) {
+ throw new repository_exception('cannotcreatetype', 'repository');
+ }
}
//create the type
$newtype->type = $this->_typename;
$newtype->visible = $this->_visible;
$newtype->sortorder = $this->_sortorder;
- $DB->insert_record('repository', $newtype);
+ $plugin_id = $DB->insert_record('repository', $newtype);
//save the options in DB
$this->update_options();
$instanceoptions['name'] = $this->_typename;
repository::static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
}
+ if(!empty($plugin_id)) {
+ // return plugin_id if create successfully
+ return $plugin_id;
+ } else {
+ return false;
+ }
} else {
- throw new repository_exception('existingrepository', 'repository');
+ if (!$silent) {
+ throw new repository_exception('existingrepository', 'repository');
+ }
+ // If plugin existed, return false, tell caller no new plugins were created.
+ return false;
}
}
}
}
-
+function repository_setup_default_plugins() {
+ //if the plugin type has no multiple instance (e.g. has no instance option name)
+ //repository_type::create will create an instance automatically
+ $local_plugin = new repository_type('local', array(), true);
+ $local_plugin_id = $local_plugin->create(true);
+ $upload_plugin = new repository_type('upload', array(), true);
+ $upload_plugin_id = $upload_plugin->create(true);
+ if (is_int($local_plugin_id) or is_int($upload_plugin_id)) {
+ print_box(get_string('setupdefaultplugins', 'repository'));
+ }
+}