public function test_unregister_site() { global $DB; $this->resetAfterTest(true); $hub = new local_hub(); $url = "http://example.com"; $sitevalues = $this->get_sitevalues($url); // Not sure why this behaviour is important but unregister_site() specificaly supports it. $hub->unregister_site(null); $token = $hub->register_site($sitevalues); $this->check_tokens($hub, $sitevalues['url']); $site = $hub->get_site_by_url($url); $hub->unregister_site($site); $this->assertEquals($site->deleted, 1); // Note that lib.php unregister_site() does not do anything but mark the site as deleted. // Deleting tokens is done by externallib.php local_hub_external::unregister_site() and lib.php delete_site(). // Should externallib.php unregister_site() be calling lib.php delete_site() instead of lib.php unregister_site()? }
/** * 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; }