From b740b3590fc964f971df3a2deedc710089c4e059 Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Fri, 29 Jan 2010 02:31:44 +0000 Subject: [PATCH] mnet MDL-21473 detect services we subscribe to, as well as publish at install/upgrade as well and add upgrades for all mnet enabled plugins --- admin/mnet/adminlib.php | 57 ++++++++++++++++++++++++++--- auth/mnet/db/mnet.php | 15 ++++++++ auth/mnet/version.php | 2 +- enrol/mnet/db/mnet.php | 9 +++++ enrol/mnet/version.php | 2 +- portfolio/mahara/db/mnet.php | 7 +++- portfolio/mahara/version.php | 2 +- repository/mahara/db/mnet.php | 37 +++++++++++++++++++ repository/mahara/version.php | 2 +- repository/remotemoodle/db/mnet.php | 7 ++++ repository/remotemoodle/version.php | 2 +- 11 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 repository/mahara/db/mnet.php diff --git a/admin/mnet/adminlib.php b/admin/mnet/adminlib.php index 2a6b7b94523..95aa3831607 100644 --- a/admin/mnet/adminlib.php +++ b/admin/mnet/adminlib.php @@ -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; } /** diff --git a/auth/mnet/db/mnet.php b/auth/mnet/db/mnet.php index 6a64312cbcd..743f1ff0d58 100644 --- a/auth/mnet/db/mnet.php +++ b/auth/mnet/db/mnet.php @@ -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', + ), +); diff --git a/auth/mnet/version.php b/auth/mnet/version.php index c221ebeffdf..1caaa67413e 100644 --- a/auth/mnet/version.php +++ b/auth/mnet/version.php @@ -1,3 +1,3 @@ version = 2010012900; +$plugin->version = 2010012901; diff --git a/enrol/mnet/db/mnet.php b/enrol/mnet/db/mnet.php index 7edace29b1f..bc7a4d452ea 100644 --- a/enrol/mnet/db/mnet.php +++ b/enrol/mnet/db/mnet.php @@ -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', + ), +); diff --git a/enrol/mnet/version.php b/enrol/mnet/version.php index c221ebeffdf..1caaa67413e 100644 --- a/enrol/mnet/version.php +++ b/enrol/mnet/version.php @@ -1,3 +1,3 @@ version = 2010012900; +$plugin->version = 2010012901; diff --git a/portfolio/mahara/db/mnet.php b/portfolio/mahara/db/mnet.php index 1e7ba596d17..c2c42f47a71 100644 --- a/portfolio/mahara/db/mnet.php +++ b/portfolio/mahara/db/mnet.php @@ -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', + ), +); diff --git a/portfolio/mahara/version.php b/portfolio/mahara/version.php index a88e66d7629..610cb0d6e4e 100644 --- a/portfolio/mahara/version.php +++ b/portfolio/mahara/version.php @@ -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 index 00000000000..277e3f4373a --- /dev/null +++ b/repository/mahara/db/mnet.php @@ -0,0 +1,37 @@ +. + + +/** + * 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', + ), +); + diff --git a/repository/mahara/version.php b/repository/mahara/version.php index cb9a91ec062..c109c52de01 100644 --- a/repository/mahara/version.php +++ b/repository/mahara/version.php @@ -15,4 +15,4 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -$plugin->version = 2010012600; +$plugin->version = 2010012901; diff --git a/repository/remotemoodle/db/mnet.php b/repository/remotemoodle/db/mnet.php index 53727c7ca2c..dbcb5efbfac 100644 --- a/repository/remotemoodle/db/mnet.php +++ b/repository/remotemoodle/db/mnet.php @@ -37,3 +37,10 @@ $publishes = array( ), ), ); +$subscribes = array( + 'remoterep' => array( + 'getFileList' => 'repository/remotemoodle/repository.class.php/getFileList', + 'retrieveFile' => 'repository/remotemoodle/repository.class.php/retrieveFile', + + ), +); diff --git a/repository/remotemoodle/version.php b/repository/remotemoodle/version.php index 92a27e02622..c109c52de01 100644 --- a/repository/remotemoodle/version.php +++ b/repository/remotemoodle/version.php @@ -15,4 +15,4 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -$plugin->version = 2010012900; +$plugin->version = 2010012901;