MDL-29857 google apis: OAuth 2.0 repository plugins upgrade
authorDan Poltawski <dan@moodle.com>
Wed, 30 May 2012 15:56:07 +0000 (23:56 +0800)
committerDan Poltawski <dan@moodle.com>
Wed, 30 May 2012 16:19:30 +0000 (00:19 +0800)
We are disabling the plugins on upgrade and emailing admins
about this if they have a plugin configured.

This is required because OAuth 2 credentials are now required
in the plugin configuration.

NOTE: These strings are temporary and need to be improved.

repository/googledocs/db/upgrade.php
repository/googledocs/lang/en/repository_googledocs.php
repository/googledocs/version.php
repository/picasa/db/upgrade.php
repository/picasa/lang/en/repository_picasa.php
repository/picasa/version.php

index 76876a1..893ed39 100644 (file)
@@ -29,5 +29,42 @@ function xmldb_repository_googledocs_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012051400, 'repository', 'googledocs');
     }
 
+    if ($oldversion < 2012053000) {
+        require_once($CFG->dirroot.'/repository/lib.php');
+        $existing = $DB->get_record('repository', array('type' => 'googledocs'), '*', IGNORE_MULTIPLE);
+
+        if ($existing) {
+            $googledocsplugin = new repository_type('googledocs', array(), true);
+            $googledocsplugin->delete();
+            repository_googledocs_admin_upgrade_notification();
+        }
+
+        upgrade_plugin_savepoint(true, 2012053000, 'repository', 'googledocs');
+    }
+
     return true;
 }
+
+function repository_googledocs_admin_upgrade_notification() {
+    $admins = get_admins();
+
+    if (empty($admins)) {
+        return;
+    }
+    $mainadmin = reset($admins);
+
+    foreach ($admins as $admin) {
+        $message = new stdClass();
+        $message->component         = 'moodle';
+        $message->name              = 'notices';
+        $message->userfrom          = $mainadmin;
+        $message->userto            = $admin;
+        $message->smallmessage      = get_string('oauth2upgrade_message_small', 'repository_googledocs');
+        $message->subject           = get_string('oauth2upgrade_message_subject', 'repository_googledocs');
+        $message->fullmessage       = get_string('oauth2upgrade_message_content', 'repository_googledocs');
+        $message->fullmessagehtml   = get_string('oauth2upgrade_message_content', 'repository_googledocs');
+        $message->fullmessageformat = FORMAT_PLAIN;
+        $message->notification      = 1;
+        message_send($message);
+    }
+}
index 8e8cf80..4f7faa7 100644 (file)
@@ -26,6 +26,9 @@ $string['clientid'] = 'Client ID';
 $string['configplugin'] = 'Configure Google Docs plugin';
 $string['googledocs:view'] = 'View google docs repository';
 $string['oauthinfo'] = '<p>To use the Google Docs repository you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
+$string['oauth2upgrade_message_subject'] = 'Important information regarding Google Docs repository plugin';
+$string['oauth2upgrade_message_content'] = 'As part of the upgrade to Moodle 2.3, the Google Docs repository plugin has been disabled due to changes in Googles API. To re-enable your plugin, you must add and reconfigure configure oauth credentials of this plugin.';
+$string['oauth2upgrade_message_small'] = 'The Google Docs repository plugin has been disabled until configured with OAuth2';
 $string['pluginname'] = 'Google Docs';
 $string['secret'] = 'Secret';
 
index 7269aa5..2e03f6c 100644 (file)
@@ -25,6 +25,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2012051400;        // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version   = 2012053000;        // The current plugin version (Date: YYYYMMDDXX).
 $plugin->requires  = 2012051100;        // Requires this Moodle version.
 $plugin->component = 'repository_googledocs'; // Full name of the plugin (used for diagnostics).
index 545ce3b..082e5e3 100644 (file)
@@ -29,5 +29,42 @@ function xmldb_repository_picasa_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012051400, 'repository', 'picasa');
     }
 
+    if ($oldversion < 2012053000) {
+        require_once($CFG->dirroot.'/repository/lib.php');
+        $existing = $DB->get_record('repository', array('type' => 'picasa'), '*', IGNORE_MULTIPLE);
+
+        if ($existing) {
+            $picasaplugin = new repository_type('picasa', array(), true);
+            $picasaplugin->delete();
+            repository_picasa_admin_upgrade_notification();
+        }
+
+        upgrade_plugin_savepoint(true, 2012053000, 'repository', 'picasa');
+    }
+
     return true;
 }
+
+function repository_picasa_admin_upgrade_notification() {
+    $admins = get_admins();
+
+    if (empty($admins)) {
+        return;
+    }
+    $mainadmin = reset($admins);
+
+    foreach ($admins as $admin) {
+        $message = new stdClass();
+        $message->component         = 'moodle';
+        $message->name              = 'notices';
+        $message->userfrom          = $mainadmin;
+        $message->userto            = $admin;
+        $message->smallmessage      = get_string('oauth2upgrade_message_small', 'repository_picasa');
+        $message->subject           = get_string('oauth2upgrade_message_subject', 'repository_picasa');
+        $message->fullmessage       = get_string('oauth2upgrade_message_content', 'repository_picasa');
+        $message->fullmessagehtml   = get_string('oauth2upgrade_message_content', 'repository_picasa');
+        $message->fullmessageformat = FORMAT_PLAIN;
+        $message->notification      = 1;
+        message_send($message);
+    }
+}
index 3c03022..89d75a6 100644 (file)
@@ -25,6 +25,9 @@
 $string['clientid'] = 'Client ID';
 $string['configplugin'] = 'Picasa repository configuration';
 $string['oauthinfo'] = '<p>To use the Picasa repository you must be registered with Google. Instructions for registing your installation with Google are described in <a href="{$a->docsurl}">Moodle Docs</a>. The redirect url should be set to:</p><p>{$a->callbackurl}</p>';
+$string['oauth2upgrade_message_subject'] = 'Important information regarding Picasa repository plugin';
+$string['oauth2upgrade_message_content'] = 'As part of the upgrade to Moodle 2.3, the Picasa repository plugin has been disabled due to changes in Googles API. To re-enable your plugin, you must add and reconfigure configure oauth credentials of this plugin.';
+$string['oauth2upgrade_message_small'] = 'The Picasa repository plugin has been disabled until configured with OAuth2';
 $string['picasa:view'] = 'View picasa repository';
 $string['pluginname'] = 'Picasa web album';
 $string['secret'] = 'Secret';
index 471007a..c6dc0fc 100644 (file)
@@ -26,6 +26,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2012051400;        // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version   = 2012053000;        // The current plugin version (Date: YYYYMMDDXX).
 $plugin->requires  = 2012051100;        // Requires this Moodle version.
 $plugin->component = 'repository_picasa'; // Full name of the plugin (used for diagnostics).