"REPOSITORY/MDL-13766, improve create function"
This commit is contained in:
@@ -6,10 +6,10 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$CFG->pagepath = 'admin/managerepositories';
|
||||
|
||||
$edit = optional_param('edit', 0, PARAM_ALPHANUM);
|
||||
$edit = optional_param('edit', 0, PARAM_FORMAT);
|
||||
$new = optional_param('new', '', PARAM_FORMAT);
|
||||
$hide = optional_param('hide', '', PARAM_ALPHANUM);
|
||||
$delete = optional_param('delete', 0, PARAM_ALPHANUM);
|
||||
$hide = optional_param('hide', '', PARAM_FORMAT);
|
||||
$delete = optional_param('delete', 0, PARAM_FORMAT);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
$move = optional_param('move', '', PARAM_ALPHANUM);
|
||||
$type = optional_param('type', '', PARAM_ALPHANUM);
|
||||
@@ -134,8 +134,11 @@ if (!empty($edit) || !empty($new)) {
|
||||
if (!confirm_sesskey()) {
|
||||
print_error('confirmsesskeybad', '', $baseurl);
|
||||
}
|
||||
var_dump($hide);
|
||||
$repositorytype = repository::get_type_by_typename($hide);
|
||||
if (empty($repositorytype)) {
|
||||
print_error('invalidplugin', 'repository');
|
||||
|
||||
}
|
||||
$repositorytype->switch_and_update_visibility();
|
||||
$return = true;
|
||||
} else if (!empty($delete)) {
|
||||
|
||||
@@ -14,6 +14,7 @@ $string['attachment'] = 'Attachment';
|
||||
$string['back'] = '< Back';
|
||||
$string['cacheexpire'] = 'Cache expire';
|
||||
$string['cachecleared'] = 'Cached files are removed';
|
||||
$string['cannotinitplugin'] = 'Call plugin_init failed';
|
||||
$string['clicktohide'] = 'Click here to hide';
|
||||
$string['clicktoshow'] = 'Click here to show';
|
||||
$string['close'] = 'Close';
|
||||
|
||||
@@ -344,7 +344,12 @@ class repository_flickr_public extends repository {
|
||||
public static function plugin_init() {
|
||||
//here we create a default instance for this type
|
||||
|
||||
repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => get_string('repositoryname', 'repository_flickr_public'),'email_address' => null),1);
|
||||
$id = repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => get_string('repositoryname', 'repository_flickr_public'),'email_address' => null), 1);
|
||||
if (empty($id)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public function supported_filetypes() {
|
||||
return array('web_image');
|
||||
|
||||
+7
-8
@@ -228,20 +228,12 @@ class repository_type {
|
||||
//only create a new type if it doesn't already exist
|
||||
$existingtype = $DB->get_record('repository', array('type'=>$this->_typename));
|
||||
if (!$existingtype) {
|
||||
//run init function
|
||||
if (!repository::static_function($this->_typename, 'plugin_init')) {
|
||||
if (!$silent) {
|
||||
throw new repository_exception('cannotcreatetype', 'repository');
|
||||
}
|
||||
}
|
||||
|
||||
//create the type
|
||||
$newtype = new stdclass;
|
||||
$newtype->type = $this->_typename;
|
||||
$newtype->visible = $this->_visible;
|
||||
$newtype->sortorder = $this->_sortorder;
|
||||
$plugin_id = $DB->insert_record('repository', $newtype);
|
||||
|
||||
//save the options in DB
|
||||
$this->update_options();
|
||||
|
||||
@@ -254,6 +246,13 @@ class repository_type {
|
||||
$instanceoptions['name'] = $this->_typename;
|
||||
repository::static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
|
||||
}
|
||||
//run plugin_init function
|
||||
if (!repository::static_function($this->_typename, 'plugin_init')) {
|
||||
if (!$silent) {
|
||||
throw new repository_exception('cannotinitplugin', 'repository');
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($plugin_id)) {
|
||||
// return plugin_id if create successfully
|
||||
return $plugin_id;
|
||||
|
||||
Reference in New Issue
Block a user