Ejemplo n.º 1
0
 function delete_site($id, $unregistercourses = false)
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/hub/locallib.php';
     $sitetodelete = $this->get_site($id);
     //unregister the courses first
     if (!empty($unregistercourses)) {
         $this->delete_courses($sitetodelete->id);
     }
     $sitetohubcommunication = $this->get_communication(WSSERVER, REGISTEREDSITE, $sitetodelete->url);
     if (!empty($sitetohubcommunication)) {
         //delete the token for this site
         require_once $CFG->dirroot . '/webservice/lib.php';
         $webservice_manager = new webservice();
         $tokentodelete = $webservice_manager->get_user_ws_token($sitetohubcommunication->token);
         $webservice_manager->delete_user_ws_token($tokentodelete->id);
         //delete the communications to this hub
         $this->delete_communication($sitetohubcommunication);
     }
     // Send email to the site administrator.
     $contactuser = local_hub_create_contact_user($sitetodelete->contactemail ? $sitetodelete->contactemail : $CFG->noreplyaddress, $sitetodelete->contactname ? $sitetodelete->contactname : get_string('noreplyname'));
     $emailinfo = new stdClass();
     $hubinfo = $this->get_info();
     $emailinfo->hubname = $hubinfo['name'];
     $emailinfo->huburl = $hubinfo['url'];
     $emailinfo->sitename = $sitetodelete->name;
     $emailinfo->siteurl = $sitetodelete->url;
     $emailinfo->unregisterpagelink = $sitetodelete->url . '/admin/registration/index.php?huburl=' . $hubinfo['url'] . '&force=1&unregistration=1';
     email_to_user($contactuser, get_admin(), get_string('emailtitlesitedeleted', 'local_hub', $emailinfo), get_string('emailmessagesitedeleted', 'local_hub', $emailinfo));
     $this->unregister_site($sitetodelete);
 }
Ejemplo n.º 2
0
        $function = 'hubdirectory_unregister_hub';
        $params = array();
        $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
        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
Ejemplo n.º 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;
 }