]> git.mjollnir.org Git - moodle.git/commitdiff
"REPOSITORY/MDL-13766, improve create function"
authordongsheng <dongsheng>
Thu, 5 Mar 2009 05:40:56 +0000 (05:40 +0000)
committerdongsheng <dongsheng>
Thu, 5 Mar 2009 05:40:56 +0000 (05:40 +0000)
admin/repository.php
lang/en_utf8/repository.php
repository/flickr_public/repository.class.php
repository/lib.php

index 7ad659a5f48e0f8c1db29a0fd58620b2399159ea..bed5871340ea14253998241001f38cfc88790067 100644 (file)
@@ -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)) {
index 003b490099b9b3a01efa84b1441c72350898ea86..99a69511938252067956b1a4b0887c98b3ff7570 100644 (file)
@@ -14,6 +14,7 @@ $string['attachment'] = 'Attachment';
 $string['back'] = '&lt; 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';
index e6f6cfe9a453a69ab5f49fdb931cf6862d2dcd4f..fb12f16f6b8257346d660860080708ecacaa673a 100644 (file)
@@ -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');
index ca974fbfd60d865ff3e3b84450a750b298450274..479f95cf205a93f3821b7ae20670d8bce80e3727 100644 (file)
@@ -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;