示例#1
0
 public function test_add_communication()
 {
     global $DB;
     $this->resetAfterTest(true);
     $hub = new local_hub();
     $sitetohubcommunication = new stdClass();
     $sitetohubcommunication->token = '123456';
     $sitetohubcommunication->type = WSSERVER;
     $sitetohubcommunication->remoteentity = REGISTEREDSITE;
     $sitetohubcommunication->remotename = 'test site';
     $sitetohubcommunication->remoteurl = 'http://example.com';
     $sitetohubcommunication->confirmed = 1;
     $sitetohubcommunication->id = $hub->add_communication($sitetohubcommunication);
     $this->assertTrue($sitetohubcommunication->id > 0);
     // Deleting a communication just toggles a deleted flage.
     // Adding another communication with the same details
     // should result in the ID of the new and old communication matching.
     $originalID = $sitetohubcommunication->id;
     $hub->delete_communication($sitetohubcommunication);
     $newID = $hub->add_communication($sitetohubcommunication);
     $this->assertTrue($originalID == $newID);
 }
示例#2
0
        require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php";
        $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token);
        try {
            $result = $xmlrpcclient->call($function, $params);
        } catch (Exception $e) {
            $error = get_string('errorunregistration', 'local_hub', $e->getMessage());
        }
    }
    if (empty($error)) {
        if (!empty($directorytohubcommunication)) {
            //delete the web service token
            $webservice_manager = new webservice();
            $tokentodelete = $webservice_manager->get_user_ws_token($directorytohubcommunication->token);
            $webservice_manager->delete_user_ws_token($tokentodelete->id);
            //delete the communication
            $hub->delete_communication($directorytohubcommunication);
        }
        if (!empty($hubtodirectorycommunication)) {
            $hub->delete_communication($hubtodirectorycommunication);
        }
    }
    redirect(new moodle_url('/local/hub/admin/register.php', array('sesskey' => sesskey(), 'error' => $error)));
}
/////// UPDATE ACTION ////////
// update the hub registration (in fact it is a new registration)
$update = optional_param('update', 0, PARAM_INT);
if ($update && confirm_sesskey()) {
    //update the registration
    $function = 'hubdirectory_update_hub_info';
    $hubinfo = $hub->get_info();
    $hubinfo['name'] = clean_param($hubinfo['name'], PARAM_TEXT);
示例#3
0
 /**
  * Unregister site
  * @return bool 1 if unregistration was successfull
  */
 public static function unregister_site()
 {
     global $DB, $CFG;
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('local/hub:updateinfo', $context);
     //clean params
     $params = self::validate_parameters(self::unregister_site_parameters(), array());
     //retieve the site communication
     $token = optional_param('wstoken', '', PARAM_ALPHANUM);
     $hub = new local_hub();
     $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, null, $token);
     //retrieve the site
     $siteurl = $communication->remoteurl;
     $site = $hub->get_site_by_url($siteurl);
     //unregister the site
     if (!empty($site)) {
         $hub->unregister_site($site);
     }
     //delete the web service token
     require_once $CFG->dirroot . '/webservice/lib.php';
     $webservice_manager = new webservice();
     $tokentodelete = $webservice_manager->get_user_ws_token($communication->token);
     $webservice_manager->delete_user_ws_token($tokentodelete->id);
     //delete the site communication
     $hub->delete_communication($communication);
     return true;
 }