From 60c366e8a6657aa069df677df70461c70a70d085 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Thu, 5 Mar 2009 05:40:56 +0000 Subject: [PATCH] "REPOSITORY/MDL-13766, improve create function" --- admin/repository.php | 11 +++++++---- lang/en_utf8/repository.php | 1 + repository/flickr_public/repository.class.php | 7 ++++++- repository/lib.php | 15 +++++++-------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/admin/repository.php b/admin/repository.php index 7ad659a5f4..bed5871340 100644 --- a/admin/repository.php +++ b/admin/repository.php @@ -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)) { diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 003b490099..99a6951193 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -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'; diff --git a/repository/flickr_public/repository.class.php b/repository/flickr_public/repository.class.php index e6f6cfe9a4..fb12f16f6b 100644 --- a/repository/flickr_public/repository.class.php +++ b/repository/flickr_public/repository.class.php @@ -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'); diff --git a/repository/lib.php b/repository/lib.php index ca974fbfd6..479f95cf20 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -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; -- 2.39.5