]> git.mjollnir.org Git - moodle.git/commitdiff
"REPOSITORY/MDL-18354, enabled local and upload repository plugins when upgrading"
authordongsheng <dongsheng>
Thu, 5 Mar 2009 04:40:51 +0000 (04:40 +0000)
committerdongsheng <dongsheng>
Thu, 5 Mar 2009 04:40:51 +0000 (04:40 +0000)
lang/en_utf8/repository.php
lib/db/upgrade.php
repository/lib.php
version.php

index afb002fc40faa610b3160e537d45f715a29db406..003b490099b9b3a01efa84b1441c72350898ea86 100644 (file)
@@ -79,6 +79,7 @@ $string['saveas'] = 'Save as';
 $string['saved'] = 'Saved';
 $string['saving'] = 'Saving';
 $string['settings'] = 'Settings';
+$string['setupdefaultplugins'] = 'Setting up default repository plugins';
 $string['search'] = 'Search ';
 $string['searching'] = 'Search in ';
 $string['siteinstances'] = 'Repositories instances of the site';
index c661d18f2b7a4a2c77bc0bab6832ce7c69871168..18cbdfa5617715cd04494769c3f66dda7190a28a 100644 (file)
@@ -1472,7 +1472,6 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
     /// 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');
@@ -1490,6 +1489,13 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
 
         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;
 }
index ea8720ee7c8dc63d50bcc7481812a0b9257aa6c9..b3538b72d1a4bb42c84f9ac36f92a82257ac3376 100644 (file)
@@ -205,9 +205,12 @@ class repository_type {
 
     /**
      * 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
@@ -227,7 +230,9 @@ class repository_type {
         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
@@ -235,7 +240,7 @@ class repository_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();
@@ -249,9 +254,19 @@ class repository_type {
                 $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;
         }
     }
 
@@ -1806,4 +1821,14 @@ final class repository_type_form extends moodleform {
     }
 }
 
-
+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'));
+    }
+}
index 9283d5046887c3cdbfa59d1198bec59eb7d9a34f..63c4e11d9e305ac8d535957f4448595106970eff 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009030300;  // YYYYMMDD   = date of the last version bump
+    $version = 2009030501;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090305)';  // Human-friendly version name