echo $OUTPUT->notification(implode('<br />', $rpc_client_2->getErrors($edited_host))); if (debugging()) { echo '<pre>'; var_dump($rpc_client_2); echo '</pre>'; } // echo $OUTPUT->footer(); } unset($rpc_client_2); } } /* * Rebind peer to the new subnetwork members, and connect * it to them, if it is subnetworking and not creating new subnetwork. */ if ($submitteddata->mnet > 0 && $submitteddata->mnet <= vmoodle_get_last_subnetwork_number()) { vmoodle_bind_to_network($submitteddata, $edited_host); } // first check for global mnet disabing/reviving if ($submitteddata->mnet > -1) { $edited_host->updateparams->deleted = 0; } else { // this host has been unbound from all others // we should remotely disable its network $edited_host->updateparams->deleted = 1; $edited_host->commit(); } // Every step was SUCCESS. $success = true; } else { // Every step was SUCCESS.
/** * @param object $submitteddata * */ function vmoodle_bind_to_network($submitteddata, &$newmnet_host) { global $USER, $CFG, $DB, $OUTPUT; // debug_trace("step 4.4 : binding to subnetwork"); // Getting services schemes to apply // debug_trace("step 4.4.1 : getting services"); vmoodle_get_service_strategy($submitteddata, $services, $peerservices, 'peer'); // debug_trace("step 4.4.2 : getting possible peers"); $idnewblock = $DB->get_field('local_vmoodle', 'id', array('vhostname' => $submitteddata->vhostname)); // last mnet has been raised by one at step 3 so we add to network if less if ($submitteddata->mnet < vmoodle_get_last_subnetwork_number()) { // Retrieves the subnetwork member(s). $subnetwork_hosts = array(); $select = 'id != ? AND mnet = ? AND enabled = 1'; $subnetwork_members = $DB->get_records_select('local_vmoodle', $select, array($idnewblock, $submitteddata->mnet)); if (!empty($subnetwork_members)) { // debug_trace("step 4.4.3 : preparing peers"); foreach ($subnetwork_members as $subnetwork_member) { $temp_host = new stdClass(); $temp_host->wwwroot = $subnetwork_member->vhostname; $temp_host->name = utf8_decode($subnetwork_member->name); $subnetwork_hosts[] = $temp_host; } } // Member(s) of the subnetwork add the new host. if (!empty($subnetwork_hosts)) { // debug_trace("step 4.4.4 : bind peers"); $rpc_client = new \local_vmoodle\XmlRpc_Client(); $rpc_client->reset_method(); $rpc_client->set_method('local/vmoodle/rpclib.php/mnetadmin_rpc_bind_peer'); // Authentication params. $rpc_client->add_param($USER->username, 'string'); $userhostroot = $DB->get_field('mnet_host', 'wwwroot', array('id' => $USER->mnethostid)); $rpc_client->add_param($userhostroot, 'string'); $rpc_client->add_param($CFG->wwwroot, 'string'); // Peer to bind to. $rpc_client->add_param((array) $newmnet_host, 'array'); $rpc_client->add_param($peerservices, 'array'); foreach ($subnetwork_hosts as $subnetwork_host) { // debug_trace("step 4.4.4.1 : bind to -> $subnetwork_host->wwwroot"); $temp_member = new \local_vmoodle\Mnet_Peer(); $temp_member->set_wwwroot($subnetwork_host->wwwroot); if (!$rpc_client->send($temp_member)) { echo $OUTPUT->notification(implode('<br />', $rpc_client->getErrors($temp_member))); if (debugging()) { echo '<pre>'; // var_dump($rpc_client); echo '</pre>'; } } // debug_trace("step 4.4.4.1 : bind from <- $subnetwork_host->wwwroot"); $rpc_client_2 = new \local_vmoodle\XmlRpc_Client(); $rpc_client_2->reset_method(); $rpc_client_2->set_method('local/vmoodle/rpclib.php/mnetadmin_rpc_bind_peer'); // Authentication params. $rpc_client_2->add_param($USER->username, 'string'); $userhostroot = $DB->get_field('mnet_host', 'wwwroot', array('id' => $USER->mnethostid)); $rpc_client_2->add_param($userhostroot, 'string'); $rpc_client_2->add_param($CFG->wwwroot, 'string'); // Peer to bind to. $rpc_client_2->add_param((array) $temp_member, 'array'); $rpc_client_2->add_param($services, 'array'); if (!$rpc_client_2->send($newmnet_host)) { echo $OUTPUT->notification(implode('<br />', $rpc_client_2->getErrors($newmnet_host))); if (debugging()) { echo '<pre>'; // var_dump($rpc_client_2); echo '</pre>'; } } unset($rpc_client_2); // free some resource } } } // Getting services schemes to apply to main // debug_trace("step 4.4.5 : getting services"); vmoodle_get_service_strategy($submitteddata, $services, $peerservices, 'main'); // debug_trace("step 4.4.5.1 : bind to -> $CFG->wwwroot"); $mainhost = new \local_vmoodle\Mnet_Peer(); // this is us $mainhost->set_wwwroot($CFG->wwwroot); // debug_trace('step 4.4.5.2 : Binding our main service strategy to remote'); // bind the local service strategy to new host if (!empty($peerservices)) { $DB->delete_records('mnet_host2service', array('hostid' => $newmnet_host->id)); // eventually deletes something on the way foreach ($peerservices as $servicename => $servicestate) { $service = $DB->get_record('mnet_service', array('name' => $servicename)); $host2service = new stdclass(); $host2service->hostid = $newmnet_host->id; $host2service->serviceid = $service->id; $host2service->publish = 0 + @$servicestate->publish; $host2service->subscribe = 0 + @$servicestate->subscribe; $DB->insert_record('mnet_host2service', $host2service); // debug_trace("step 4.4.5.2 : adding ".serialize($host2service)); } } // debug_trace('step 4.4.5.4 : Binding remote service strategy to main'); $rpc_client = new \local_vmoodle\XmlRpc_Client(); $rpc_client->reset_method(); $rpc_client->set_method('local/vmoodle/rpclib.php/mnetadmin_rpc_bind_peer'); $rpc_client->add_param($USER->username, 'string'); $userhostroot = $DB->get_field('mnet_host', 'wwwroot', array('id' => $USER->mnethostid)); $rpc_client->add_param($userhostroot, 'string'); $rpc_client->add_param($CFG->wwwroot, 'string'); // Peer to bind to : this is us. $rpc_client->add_param((array) $mainhost, 'array'); $rpc_client->add_param($services, 'array'); // debug_trace('step 4.4.5.4 : Sending'); if (!$rpc_client->send($newmnet_host)) { // echo $OUTPUT->notification(implode('<br />', $rpc_client->getErrors($newmnet_host))); if (debugging()) { echo '<pre>'; // var_dump($rpc_client); echo '</pre>'; } } }