Skip to content

Commit

Permalink
mnet MDL-21473 detect services we subscribe to, as well as publish at…
Browse files Browse the repository at this point in the history
… install/upgrade as well

and add upgrades for all mnet enabled plugins
  • Loading branch information
Penny Leach committed Jan 29, 2010
1 parent b0a9a0c commit b740b35
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 11 deletions.
57 changes: 52 additions & 5 deletions admin/mnet/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,33 @@ 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;
}
}
}

// 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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions auth/mnet/db/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@
)
)
);
$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',
),
);
2 changes: 1 addition & 1 deletion auth/mnet/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$plugin->version = 2010012900;
$plugin->version = 2010012901;
9 changes: 9 additions & 0 deletions enrol/mnet/db/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@
),
),
);
$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',
),
);
2 changes: 1 addition & 1 deletion enrol/mnet/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$plugin->version = 2010012900;
$plugin->version = 2010012901;
7 changes: 6 additions & 1 deletion portfolio/mahara/db/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
),
),
);

$subscribes = array(
'pf' => array(
'send_content_intent' => 'portfolio/mahara/lib.php/send_content_intent',
'send_content_ready' => 'portfolio/mahara/lib.php/send_content_ready',
),
);
2 changes: 1 addition & 1 deletion portfolio/mahara/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
37 changes: 37 additions & 0 deletions repository/mahara/db/mnet.php
Original file line number Diff line number Diff line change
@@ -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',
),
);

2 changes: 1 addition & 1 deletion repository/mahara/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 7 additions & 0 deletions repository/remotemoodle/db/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@
),
),
);
$subscribes = array(
'remoterep' => array(
'getFileList' => 'repository/remotemoodle/repository.class.php/getFileList',
'retrieveFile' => 'repository/remotemoodle/repository.class.php/retrieveFile',

),
);
2 changes: 1 addition & 1 deletion repository/remotemoodle/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit b740b35

Please sign in to comment.