Skip to content

Commit

Permalink
mnet MDL-21261 large overhaul. This commit changes:
Browse files Browse the repository at this point in the history
- The way that mnet rpc functions are registered.  Plugins must now
  create db/mnet.php which is an array, similar to services.php.  This
  *replaces* the old mnet_publishes() functions.  version.php must be
  bumped to trigger this.

- More information about each rpc-available function is stored in the
  database, including the class it belongs to, the file it is found in,
  and whether or not it is static.  Methods that are not static must be
  in a class with a constructor that takes no arguments (this can easily
  be achieved with a small wrapper if necessary)

- The xmlrpc dispatcher has been rewritten to remove all the
  dependencies on hardcoded information about auth,mnet,portfolio and
  repository, and just use the information in the database.

- The old hardcoded hidden mnet/testclient.php has been moved to the
  Admin menu under "Development" and rewritten.

- The xmlrpc introspection method profiling is now using php and zend
  reflection - which is a lot nicer than the old way, which was using a
  php-based php parser.  This fixes some inconsistent handling of
  methods without arguments that were advertising their return value as
  the only method parameter.  While this is a *fix*, it breaks BC
  slightly - the old 1.9 broken mnet/testclient.php will now not work
  properly with 2.0

- Dangerous mode is still supported, but old mod/*/rpclib.php is
  now unsupported, due to the fact that any plugin can export mnet
  functions with db/mnet.php.  This is a slight BC break.

Still TODO:

- TEST TEST TEST
- Document the two small BC breaks in release notes
- Document the contract for db/mnet.php
  • Loading branch information
Penny Leach committed Jan 28, 2010
1 parent 92a8906 commit de260e0
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 1,197 deletions.
314 changes: 144 additions & 170 deletions admin/mnet/adminlib.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion admin/mnet/mnet_services.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?php
foreach($myservices as $name => $versions) {
$version = current($versions);
$langmodule = ($version['parent_type'] == 'mod' ? '' : ($version['parent_type'] . '_')) . $version['parent'];
$langmodule = ($version['plugintype'] == 'mod' ? '' : ($version['plugintype'] . '_')) . $version['pluginname'];
?>
<tr>
<td align="left" valign="top" colspan="2">
Expand Down
10 changes: 5 additions & 5 deletions admin/mnet/mnet_services.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
$id_list .= ', '.$CFG->mnet_all_hosts_id;
}

$concat = $DB->sql_concat('COALESCE(h2s.id,0) ', ' \'-\' ', ' svc.id', '\'-\'', 'r.parent_type', '\'-\'', 'r.parent');
$concat = $DB->sql_concat('COALESCE(h2s.id,0) ', ' \'-\' ', ' svc.id', '\'-\'', 'r.plugintype', '\'-\'', 'r.pluginname');

$query = "
SELECT DISTINCT
Expand All @@ -92,8 +92,8 @@
svc.name,
svc.offer,
svc.apiversion,
r.parent_type,
r.parent,
r.plugintype,
r.pluginname,
h2s.hostid,
h2s.publish,
h2s.subscribe
Expand Down Expand Up @@ -156,8 +156,8 @@
'name' => $result->name,
'offer' => $result->offer,
'apiversion' => $result->apiversion,
'parent_type' => $result->parent_type,
'parent' => $result->parent,
'plugintype' => $result->plugintype,
'pluginname' => $result->pluginname,
'hostsubscribes' => $result->hostsubscribes,
'hostpublishes' => $result->hostpublishes
);
Expand Down
4 changes: 3 additions & 1 deletion admin/settings/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
// XMLDB editor
$ADMIN->add('development', new admin_externalpage('xmldbeditor', get_string('xmldbeditor'), "$CFG->wwwroot/$CFG->admin/xmldb/"));


if ($CFG->mnet_dispatcher_mode !== 'off') {
$ADMIN->add('development', new admin_externalpage('mnettestclient', get_string('testclient', 'mnet'), "$CFG->wwwroot/$CFG->admin/mnet/testclient.php"));
}
} // end of speedup
35 changes: 8 additions & 27 deletions auth/mnet/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ function auth_plugin_mnet() {
$this->config = get_config('auth/mnet');
}

/**
* Provides the allowed RPC services from this class as an array.
* @return array Allowed RPC services.
*/
function mnet_publishes() {

$sso_idp = array();
$sso_idp['name'] = 'sso_idp'; // Name & Description go in lang file
$sso_idp['apiversion'] = 1;
$sso_idp['methods'] = array('user_authorise','keepalive_server', 'kill_children',
'refresh_log', 'fetch_user_image', 'fetch_theme_info',
'update_enrolments');

$sso_sp = array();
$sso_sp['name'] = 'sso_sp'; // Name & Description go in lang file
$sso_sp['apiversion'] = 1;
$sso_sp['methods'] = array('keepalive_client','kill_child');

return array($sso_idp, $sso_sp);
}

/**
* This function is normally used to determine if the username and password
* are correct for local logins. Always returns false, as local users do not
Expand All @@ -74,7 +53,7 @@ function user_login($username, $password) {
*/
function user_authorise($token, $useragent) {
global $CFG, $MNET, $SITE, $MNET_REMOTE_CLIENT, $DB;
require_once $CFG->dirroot . '/mnet/xmlrpc/server.php';
require_once $CFG->dirroot . '/mnet/xmlrpc/serverlib.php';

$mnet_session = $DB->get_record('mnet_session', array('token'=>$token, 'useragent'=>$useragent));
if (empty($mnet_session)) {
Expand Down Expand Up @@ -465,11 +444,11 @@ function confirm_mnet_session($token, $remotewwwroot) {
* Invoke this function _on_ the IDP to update it with enrolment info local to
* the SP right after calling user_authorise()
*
* Normally called by the SP after calling
* Normally called by the SP after calling user_authorise()
*
* @param string $username The username
* @param string $courses Assoc array of courses following the structure of mnet_enrol_course
* @return bool
* @param string $username The username
* @param string $courses Assoc array of courses following the structure of mnet_enrol_course
* @return bool
*/
function update_enrolments($username, $courses) {
global $MNET_REMOTE_CLIENT, $CFG, $DB;
Expand Down Expand Up @@ -623,7 +602,9 @@ function change_password_url() {
* This function is called from admin/auth.php, and outputs a full page with
* a form for configuring this plugin.
*
* @param array $page An object containing all the data for this page.
* @param object $config
* @param object $err
* @param array $user_fields
*/
function config_form($config, $err, $user_fields) {
global $CFG, $DB;
Expand Down
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 = 2009112400;
$plugin->version = 2010012600;
15 changes: 2 additions & 13 deletions enrol/mnet/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,11 @@ function get_access_icons($course) {
*** MNET functions
***
***/
function mnet_publishes() {

$enrol = array();
$enrol['name'] = 'mnet_enrol'; // Name & Description go in lang file
$enrol['apiversion'] = 1;
$enrol['methods'] = array('available_courses','user_enrolments', 'enrol_user', 'unenrol_user', 'course_enrolments' );

return array($enrol);
}

/**
* Does Foo
* Returns a list of all courses available for remote login
*
* @param string $username The username
* @param int $mnethostid The id of the remote mnethost
* @return bool Whether the user can login from the remote host
* @return array Array of courses
*/
function available_courses() {
global $CFG, $DB;
Expand Down
29 changes: 29 additions & 0 deletions lang/en_utf8/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,33 @@
$string['error709'] = 'The remote site failed to obtain a SSL key from you.';
$string['error7026'] = 'The key that your message was signed with differs from the key that the remote host has on file for your server. Further, the remote host attempted to fetch your current key and failed to do so. Please manually re-key with the remote host and try again.';

$string['installnosuchmethod'] = 'Coding error! Something is trying to install a mnet xmlrpc method ($a->method) on a class ($a->class) and it can\'t be found!';
$string['installnosuchfunction'] = 'Coding error! Something is trying to install a mnet xmlrpc function ($a->method) from a file ($a->file) and it can\'t be found!';
$string['installreflectionfunctionerror'] = 'Coding error! MNET introspection failed for function \'$a->method\' in file \'$a->file\'. The original error message, in case it helps, is: \'$a->error\'';
$string['installreflectionclasserror'] = 'Coding error! MNET introspection failed for method \'$a->method\' in class \'$a->class\'. The original error message, in case it helps, is: \'$a->error\'';

// admin strings
$string['hostlist'] = 'List of Networked Hosts';
$string['servicesavailableonhost'] = 'Services available on $a';
$string['serviceid'] = 'Service ID';
$string['service'] = 'Service Name';
$string['version'] = 'Version';
$string['theypublish'] = 'They publish';
$string['theysubscribe'] = 'They subscribe';
$string['listservices'] = 'List services';
$string['methodsavailableonhostinservice'] = 'Methods available for $a->service on $a->host';
$string['methodsavailableonhost'] = 'Methods available on $a';
$string['method'] = 'Method';
$string['options'] = 'Options';
$string['inspect'] = 'Inspect';
$string['methodsignature'] = 'Method signature for $a';
$string['position'] = 'Position';
$string['name'] = 'Name';
$string['type'] = 'Type';
$string['description'] = 'Description';
$string['returnvalue'] = 'Return value';
$string['methodhelp'] = 'Method help for $a';
$string['testclient'] = 'Moodle Network Test Client';
$string['unknown'] = 'Unknown';
$string['notmoodleapplication'] = 'WARNING: This is not a moodle application, so some of the inspection methods may not work properly.';
?>
15 changes: 9 additions & 6 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100106" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100126" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -1324,12 +1324,15 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="Unique Function ID" NEXT="function_name"/>
<FIELD NAME="function_name" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="xmlrpc_path"/>
<FIELD NAME="xmlrpc_path" TYPE="char" LENGTH="80" NOTNULL="true" SEQUENCE="false" PREVIOUS="function_name" NEXT="parent_type"/>
<FIELD NAME="parent_type" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="xmlrpc_path" NEXT="parent"/>
<FIELD NAME="parent" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="parent_type" NEXT="enabled"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="parent" NEXT="help"/>
<FIELD NAME="xmlrpc_path" TYPE="char" LENGTH="80" NOTNULL="true" SEQUENCE="false" PREVIOUS="function_name" NEXT="plugintype"/>
<FIELD NAME="plugintype" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="xmlrpc_path" NEXT="pluginname"/>
<FIELD NAME="pluginname" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="plugintype" NEXT="enabled"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="pluginname" NEXT="help"/>
<FIELD NAME="help" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" PREVIOUS="enabled" NEXT="profile"/>
<FIELD NAME="profile" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Method signature" PREVIOUS="help"/>
<FIELD NAME="profile" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Method signature" PREVIOUS="help" NEXT="filename"/>
<FIELD NAME="filename" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="profile" NEXT="classname"/>
<FIELD NAME="classname" TYPE="char" LENGTH="150" NOTNULL="false" SEQUENCE="false" PREVIOUS="filename" NEXT="static"/>
<FIELD NAME="static" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" PREVIOUS="classname"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the mnet_rpc table"/>
Expand Down
31 changes: 31 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2868,10 +2868,41 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2010011200);
}


if ($result && $oldversion < 2010012500) {
upgrade_fix_incorrect_mnethostids();
upgrade_main_savepoint($result, 2010012500);
}

if ($result && $oldversion < 2010012600) {
// do stuff to the mnet table
$table = new xmldb_table('mnet_rpc');

$field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
$dbman->rename_field($table, $field, 'plugintype');

$field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
$dbman->rename_field($table, $field, 'pluginname');

$field = new xmldb_field('filename', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'profile');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('classname', XMLDB_TYPE_CHAR, '150', null, null, null, null, 'filename');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('static', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'classname');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

/// Main savepoint reached
upgrade_main_savepoint($result, 2010012600);
}

return $result;
}

Expand Down
9 changes: 0 additions & 9 deletions lib/portfolio/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,6 @@ public function cleanup() {
return true;
}

/**
* return array of mnet methods, keyed by service (pf)
* in the same format used everywhere else in moodle.
* see the mahara portfolio plugin for an example
*/
public static function mnet_publishes() {
return array();
}

/**
* whether this plugin supports multiple exports in the same session
* most plugins should handle this, but some that require a redirect for authentication
Expand Down
30 changes: 18 additions & 12 deletions lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);
$endcallback($component, true, $verbose);
}
}
Expand Down Expand Up @@ -366,6 +368,8 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
$endcallback($component, true, $verbose);
Expand Down Expand Up @@ -394,6 +398,8 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
$endcallback($component, false, $verbose);
Expand Down Expand Up @@ -462,6 +468,8 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);
$endcallback($component, true, $verbose);
}
}
Expand Down Expand Up @@ -491,6 +499,8 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
$endcallback($component, true, $verbose);
Expand Down Expand Up @@ -518,6 +528,8 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
remove_dir($CFG->dataroot.'/cache', true); // flush cache
Expand Down Expand Up @@ -606,6 +618,8 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);
$endcallback($component, true, $verbose);
}
}
Expand Down Expand Up @@ -643,6 +657,8 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
$endcallback($component, true, $verbose);
Expand Down Expand Up @@ -675,6 +691,8 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
external_update_descriptions($component);
events_update_definition($component);
message_update_providers($component);
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/adminlib.php');
upgrade_plugin_mnet_functions($component);

theme_reset_all_caches();
$endcallback($component, false, $verbose);
Expand Down Expand Up @@ -1258,18 +1276,6 @@ function upgrade_noncore($verbose) {
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}

// Check for changes to RPC functions
if ($CFG->mnet_dispatcher_mode != 'off') {
try {
// this needs a full rewrite, sorry to mention that :-(
// we have to make it part of standard WS framework
require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
upgrade_RPC_functions(); // Return here afterwards
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/zend/readme_moodle.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Description of Zend framework 1.9.4 import into Moodle
Please note the zend framework is severly crippled - everything not needed in /webservice/* is removed.

Do not use outside of our /webservice/* !!
Do not use outside of our /webservice/* or mnet !!


Changes:
Expand Down
Loading

0 comments on commit de260e0

Please sign in to comment.