]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16180 - add portfolio support to mnet
authormjollnir_ <mjollnir_>
Sat, 30 Aug 2008 11:25:29 +0000 (11:25 +0000)
committermjollnir_ <mjollnir_>
Sat, 30 Aug 2008 11:25:29 +0000 (11:25 +0000)
admin/mnet/adminlib.php
admin/mnet/mnet_services.html
lib/adminlib.php
mnet/lib.php
mnet/remote_client.php
mnet/xmlrpc/server.php

index 8c5455499f1493263198923a78a1b268cc7a47fc..2e91159e6c6fef947d0b97294d4be23b1bf75268 100644 (file)
@@ -35,6 +35,12 @@ function mnet_get_functions($type, $parentname) {
         if (function_exists($mnet_publishes)) {
             (array)$publishes = $mnet_publishes();
         }
+    } else if ('portfolio' == $type) {
+        $docname = 'lib.php';
+        $relname = '/portfolio/type/' . $parentname . '/'. $docname;
+        $filename = $CFG->dirroot . $relname;
+        require_once($CFG->libdir . '/portfoliolib.php');
+        $publishes = (array)portfolio_static_function($parentname, 'mnet_publishes');
     } else {
         // auth or enrol
         $relname  = '/'.$type.'/'.$parentname.'/'.$docname;
@@ -179,5 +185,11 @@ function upgrade_RPC_functions($returnurl) {
             mnet_get_functions('enrol', $dir);
         }
     }
+
+    if ($plugins = get_list_of_plugins('portfolio/type')) {
+        foreach ($plugins as $p) {
+            mnet_get_functions('portfolio', $p);
+        }
+    }
 }
 ?>
index ae83cb7ea80abe9afb03b304199ebfb7205f17e5..dcfa80d7abd257a5f7919f37c48c4b1ed30585e6 100644 (file)
@@ -44,6 +44,9 @@ print_simple_box_start("center", "");
             echo $breakstring;
 ?>
     <input type="hidden" name="exists[<?php echo  $version['serviceid']; ?>]" value="1" />
+<?php if ($name == 'pf_out') { // see MDL-16269 ?>
+    <input type="hidden" name="publish[<?php echo $version['serviceid']; ?>]" value="0" />
+<?php } else { ?>
     <input type="checkbox" name="publish[<?php echo $version['serviceid']; ?>]" <?php echo (!empty($version['I_publish']))? 'checked="checked" ': '' ; ?>/>
 <?php 
             print_string('publish','mnet');
@@ -55,7 +58,7 @@ print_simple_box_start("center", "");
                 print_string("enabled_for_all",'mnet',!empty($version['I_publish']));
             } 
             echo '<br />';
-?>
+?>
     <input type="checkbox" name="subscribe[<?php echo $version['serviceid']; ?>]" <?php echo (!empty($version['I_subscribe']))? 'checked="checked" ': '' ; ?>/>
 <?php 
             print_string('subscribe','mnet');
index fe2a7cfcc362384c4bb8499e274931d91237d3ea..e2b2a6a381139cd3eb9b629aab1fea57bdc708ea 100644 (file)
@@ -282,6 +282,12 @@ function get_db_directories() {
         }
     }
 
+    if ($plugins = get_list_of_plugins('portfolio/type', 'db')) {
+        foreach ($plugins as $plugin) {
+            $dbdirs[] = $CFG->dirroot . '/portfolio/type/' . $plugin . '/db';
+        }
+    }
+
 /// Local database changes, if the local folder exists.
     if (file_exists($CFG->dirroot . '/local')) {
         $dbdirs[] = $CFG->dirroot.'/local/db';
index 958695f5c7fa5cd3f607fd27b8da5c03ee39fdcd..f6cc6ce5cd4bcf7c77a73059f10f849f8d04ba02 100644 (file)
@@ -494,22 +494,42 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) {
             return RPC_NOSUCHCLASS;
         }
 
-        $object = new $class();
+        $object = false;
+        $static = false;
+
+        try {
+            // @todo set here whatever we can to ensure that errors cause exceptions :(
+            // see MDL-16175 - long term solution is teaching the dispatcher about:
+            // a: the difference between static and class methods
+            // b: object constructor arguments
+            $object = @new $class();
+            if (!method_exists($object, $functionname)) {
+                // Generate error response - unable to locate method
+                return RPC_NOSUCHMETHOD;
+            }
 
-        if (!method_exists($object, $functionname)) {
-            // Generate error response - unable to locate method
-            return RPC_NOSUCHMETHOD;
-        }
+            if (!method_exists($object, 'mnet_publishes')) {
+                // Generate error response - the class doesn't publish
+                // *any* methods, because it doesn't have an mnet_publishes
+                // method
+                return RPC_FORBIDDENMETHOD;
+            }
 
-        if (!method_exists($object, 'mnet_publishes')) {
-            // Generate error response - the class doesn't publish
-            // *any* methods, because it doesn't have an mnet_publishes
-            // method
-            return RPC_FORBIDDENMETHOD;
+            // Get the list of published services - initialise method array
+            $servicelist = $object->mnet_publishes();
+        }
+        catch (Exception $e) {
+            if (method_exists($class, $functionname)) {
+                // static... don't try to instantiate it.
+                if (!method_exists($class, 'mnet_publishes')) {
+                    return RPC_FORBIDDENMETHOD;
+                } else {
+                    $servicelist = call_user_func(array($class, 'mnet_publishes'));
+                }
+                $static = $class;
+            }
         }
 
-        // Get the list of published services - initialise method array
-        $servicelist = $object->mnet_publishes();
         $methodapproved = false;
 
         // If the method is in the list of approved methods, set the
@@ -527,6 +547,8 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) {
 
         // Stash the object so we can call the method on it later
         $MNET_REMOTE_CLIENT->object_to_call($object);
+        $MNET_REMOTE_CLIENT->static_location($static);
+
     // WE'RE LOOKING AT A FUNCTION
     } else {
         if (!function_exists($functionname)) {
index 0cfd06df70e95b18a4df9b47c49109bcd28f7296..d618bf93e61a93cd7dec597f726610c8b53ad878 100644 (file)
@@ -12,8 +12,9 @@ class mnet_remote_client extends mnet_peer {
 
     // If the remote client is trying to execute a method on an object instead
     // of just a function, we'll instantiate the proper class and store it in
-    // this 'object_to_call' property.
+    // this 'object_to_call' property, or 'static_location' if it wants to be called statically
     var $object_to_call         = false;
+    var $static_location        = false;
     var $request_was_encrypted  = false;
     var $request_was_signed     = false;
 
@@ -29,6 +30,10 @@ class mnet_remote_client extends mnet_peer {
         $this->object_to_call = $object;
     }
 
+    function static_location($location) {
+        $this->static_location = $location;
+    }
+
     function plaintext_is_ok() {
         global $CFG;
 
index c937003d615142a66fe6a8c2075b898164217439..f8f26fd13b8cc7a330f615f568e415af541d576b 100644 (file)
@@ -314,10 +314,12 @@ function mnet_server_fault_xml($code, $text, $privatekey = null) {
 function mnet_server_dummy_method($methodname, $argsarray, $functionname) {
     global $MNET_REMOTE_CLIENT;
     
-    if (!is_object($MNET_REMOTE_CLIENT->object_to_call)) {
-        return @call_user_func_array($functionname, $argsarray);
-    } else {
+    if (is_object($MNET_REMOTE_CLIENT->object_to_call)) {
         return @call_user_method_array($functionname, $MNET_REMOTE_CLIENT->object_to_call, $argsarray);
+    } else if (!empty($MNET_REMOTE_CLIENT->static_location)) {
+        return @call_user_func_array(array($MNET_REMOTE_CLIENT->static_location, $functionname), $argsarray);
+    } else {
+        return @call_user_func_array($functionname, $argsarray);
     }
 }
 
@@ -471,6 +473,21 @@ function mnet_server_dispatch($payload) {
             exit(mnet_server_fault(703, 'nosuchfunction'));
         }
 
+    } else if ($callstack[0] == 'portfolio') {
+        // Break out the callstack into its elements
+        list($base, $plugin, $filename, $methodname) = $callstack;
+
+        if ($filename == 'lib.php') {
+            $pluginclass = 'portfolio_plugin_' . $plugin;
+            $includefile = '/portfolio/type/'.$plugin.'/lib.php';
+            $response    = mnet_server_invoke_method($includefile, $methodname, $method, $payload, $pluginclass);
+            $response = mnet_server_prepare_response($response);
+            echo $response;
+        } else {
+            // Generate error response - unable to locate function
+            exit(mnet_server_fault(7012, 'nosuchfunction'));
+        }
+
     ////////////////////////////////////// STRICT MOD/*
     } elseif ($callstack[0] == 'mod' || 'dangerous' == $CFG->mnet_dispatcher_mode) {
         list($base, $module, $filename, $functionname) = $callstack;