mnet MDL-21473 detect services we subscribe to, as well as publish at install/upgrade...
authorPenny Leach <penny@liip.ch>
Fri, 29 Jan 2010 02:31:44 +0000 (02:31 +0000)
committerPenny Leach <penny@liip.ch>
Fri, 29 Jan 2010 02:31:44 +0000 (02:31 +0000)
and add upgrades for all mnet enabled plugins

admin/mnet/adminlib.php
auth/mnet/db/mnet.php
auth/mnet/version.php
enrol/mnet/db/mnet.php
enrol/mnet/version.php
portfolio/mahara/db/mnet.php
portfolio/mahara/version.php
repository/mahara/db/mnet.php [new file with mode: 0644]
repository/mahara/version.php
repository/remotemoodle/db/mnet.php
repository/remotemoodle/version.php

index 2a6b7b9..95aa383 100644 (file)
@@ -43,14 +43,20 @@ function upgrade_plugin_mnet_functions($component) {
     if (empty($publishes)) {
         $publishes = array(); // still need this to be able to disable stuff later
     }
+    if (empty($subscribes)) {
+        $subscribes = array(); // still need this to be able to disable stuff later
+    }
+
+    static $servicecache = array();
 
     // rekey an array based on the rpc method for easy lookups later
-    $methodservices = array();
+    $publishmethodservices = array();
+    $subscribemethodservices = array();
     foreach($publishes as $servicename => $service) {
         if (is_array($service['methods'])) {
             foreach($service['methods'] as $methodname) {
                 $service['servicename'] = $servicename;
-                $methodservices[$methodname][] = $service;
+                $publishmethodservices[$methodname][] = $service;
             }
         }
     }
@@ -58,11 +64,12 @@ function upgrade_plugin_mnet_functions($component) {
     // Disable functions that don't exist (any more) in the source
     // Should these be deleted? What about their permissions records?
     foreach ($DB->get_records('mnet_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) {
-        if (!array_key_exists($rpc->functionname, $methodservices)) {
+        if (!array_key_exists($rpc->functionname, $publishmethodservices)) {
             $DB->set_field('mnet_rpc', 'enabled', 0, array('id' => $rpc->id));
         }
     }
 
+    // reflect all the services we're publishing and save them
     require_once($CFG->dirroot . '/lib/zend/Zend/Server/Reflection.php');
     static $cachedclasses = array(); // to store reflection information in
     foreach ($publishes as $service => $data) {
@@ -136,7 +143,7 @@ function upgrade_plugin_mnet_functions($component) {
             }
         }
 
-        foreach ($methodservices[$dataobject->functionname] as $service) {
+        foreach ($publishmethodservices[$dataobject->functionname] as $service) {
             if ($serviceobj = $DB->get_record('mnet_service', array('name'=>$service['servicename']))) {
                 $serviceobj->apiversion = $service['apiversion'];
                 $DB->update_record('mnet_service', $serviceobj);
@@ -147,6 +154,7 @@ function upgrade_plugin_mnet_functions($component) {
                 $serviceobj->offer       = 1;
                 $serviceobj->id          = $DB->insert_record('mnet_service', $serviceobj);
             }
+            $servicecache[$service['servicename']] = $serviceobj;
             if (!$DB->record_exists('mnet_service2rpc', array('rpcid'=>$dataobject->id, 'serviceid'=>$serviceobj->id))) {
                 $obj = new stdClass();
                 $obj->rpcid = $dataobject->id;
@@ -155,7 +163,46 @@ function upgrade_plugin_mnet_functions($component) {
             }
         }
     }
-        return true;
+
+    // finished with methods we publish, now do subscribable methods
+    foreach($subscribes as $service => $methods) {
+        if (!array_key_exists($service, $servicecache)) {
+            if (!$serviceobj = $DB->get_record('mnet_service', array('name' =>  $service))) {
+                debugging("skipping unknown service $service");
+                continue;
+            }
+            $servicecache[$service] = $serviceobj;
+        } else {
+            $serviceobj = $servicecache[$service];
+        }
+        foreach ($methods as $method => $xmlrpcpath) {
+            if (!$rpcid = $DB->record_exists('mnet_remote_rpc', array('xmlrpcpath'=>$xmlrpcpath))) {
+                $remoterpc = (object)array(
+                    'functionname' => $method,
+                    'xmlrpcpath' => $xmlrpcpath,
+                    'plugintype' => $type,
+                    'pluginname' => $plugin,
+                    'enabled'    => 1,
+                );
+                $rpcid = $remoterpc->id = $DB->insert_record('mnet_remote_rpc', $remoterpc, true);
+            }
+            if (!$DB->record_exists('mnet_remote_service2rpc', array('rpcid'=>$rpcid, 'serviceid'=>$serviceobj->id))) {
+                $obj = new stdClass();
+                $obj->rpcid = $rpcid;
+                $obj->serviceid = $serviceobj->id;
+                $DB->insert_record('mnet_remote_service2rpc', $obj, true);
+            }
+            $subscribemethodservices[$method][] = $servicename;
+        }
+    }
+
+    foreach ($DB->get_records('mnet_remote_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) {
+        if (!array_key_exists($rpc->functionname, $subscribemethodservices)) {
+            $DB->set_field('mnet_remote_rpc', 'enabled', 0, array('id' => $rpc->id));
+        }
+    }
+
+    return true;
 }
 
 /**
index 6a64312..743f1ff 100644 (file)
@@ -50,3 +50,18 @@ $publishes = array(
         )
     )
 );
+$subscribes = array(
+    'sso_idp' => array(
+        'user_authorise'    => 'auth/mnet/auth.php/user_authorise',
+        'keepalive_server'  => 'auth/mnet/auth.php/keepalive_server',
+        'kill_children'     => 'auth/mnet/auth.php/kill_children',
+        'refresh_log'       => 'auth/mnet/auth.php/refresh_log',
+        'fetch_user_image'  => 'auth/mnet/auth.php/fetch_user_image',
+        'fetch_theme_info'  => 'auth/mnet/auth.php/fetch_theme_info',
+        'update_enrolments' => 'auth/mnet/auth.php/update_enrolments',
+    ),
+    'sso_sp' => array(
+        'keepalive_client' => 'auth/mnet/auth.php/keepalive_client',
+        'kill_child'       => 'auth/mnet/auth.php/kill_child',
+    ),
+);
index c221ebe..1caaa67 100644 (file)
@@ -1,3 +1,3 @@
 <?php
 
-$plugin->version = 2010012900;
+$plugin->version = 2010012901;
index 7edace2..bc7a4d4 100644 (file)
@@ -39,3 +39,12 @@ $publishes = array(
         ),
     ),
 );
+$subscribes = array(
+    'mnet_enrol' => array(
+        'available_courses' => 'enrol/mnet/enrol.php/available_courses',
+        'user_enrolments'   => 'enrol/mnet/enrol.php/user_enrolments',
+        'enrol_user'        => 'enrol/mnet/enrol.php/enrol_user',
+        'unenrol_user'      => 'enrol/mnet/enrol.php/unenrol_user',
+        'course_enrolments' => 'enrol/mnet/enrol.php/course_enrolments',
+    ),
+);
index c221ebe..1caaa67 100644 (file)
@@ -1,3 +1,3 @@
 <?php
 
-$plugin->version = 2010012900;
+$plugin->version = 2010012901;
index 1e7ba59..c2c42f4 100644 (file)
@@ -35,4 +35,9 @@ $publishes = array(
         ),
     ),
 );
-
+$subscribes = array(
+    'pf' => array(
+        'send_content_intent' => 'portfolio/mahara/lib.php/send_content_intent',
+        'send_content_ready'  => 'portfolio/mahara/lib.php/send_content_ready',
+    ),
+);
index a88e66d..610cb0d 100644 (file)
@@ -25,7 +25,7 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-$plugin->version  = 2010012900;
+$plugin->version  = 2010012901;
 $plugin->requires = 2008072500;
 $plugin->cron     = 0;
 
diff --git a/repository/mahara/db/mnet.php b/repository/mahara/db/mnet.php
new file mode 100644 (file)
index 0000000..277e3f4
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * This file contains the mnet services for the mahara repository plugin
+ *
+ * @since 2.0
+ * @package moodlecore
+ * @subpackage repository
+ * @copyright 2010 Penny Leach
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$publishes = array();
+$subscribes = array(
+    'remoterep' => array(
+        'get_folder_files'         => 'repository/mahara/repository.class.php/get_folder_files',
+        'search_folders_and_files' => 'repository/mahara/repository.class.php/search_folders_and_files',
+        'get_file'                 => 'repository/mahara/repository.class.php/get_file',
+    ),
+);
+
index cb9a91e..c109c52 100644 (file)
@@ -15,4 +15,4 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-$plugin->version = 2010012600;
+$plugin->version = 2010012901;
index 53727c7..dbcb5ef 100644 (file)
@@ -37,3 +37,10 @@ $publishes = array(
         ),
     ),
 );
+$subscribes = array(
+    'remoterep' => array(
+        'getFileList'  => 'repository/remotemoodle/repository.class.php/getFileList',
+        'retrieveFile' => 'repository/remotemoodle/repository.class.php/retrieveFile',
+
+    ),
+);
index 92a27e0..c109c52 100644 (file)
@@ -15,4 +15,4 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-$plugin->version = 2010012900;
+$plugin->version = 2010012901;