MDL-48894 core_registration: make it more obvious if site is registered

This commit is contained in:
Andrew Davis 2015-01-26 12:07:07 +01:00
parent 88cd577ef3
commit 806c06fc7b
5 changed files with 42 additions and 9 deletions

View File

@ -69,6 +69,7 @@ class registration_manager {
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
try {
$result = $xmlrpcclient->call($function, $params);
$this->update_registeredhub($hub); // To update timemodified.
mtrace(get_string('siteupdatedcron', 'hub', $hub->hubname));
} catch (Exception $e) {
$errorparam = new stdClass();
@ -118,6 +119,7 @@ class registration_manager {
*/
public function add_registeredhub($hub) {
global $DB;
$hub->timemodified = time();
$id = $DB->insert_record('registration_hubs', $hub);
return $id;
}
@ -171,15 +173,16 @@ class registration_manager {
/**
* Update a registered hub (mostly use to update the confirmation status)
* @param object $communication the hub
* @param object $hub the hub
*/
public function update_registeredhub($communication) {
public function update_registeredhub($hub) {
global $DB;
$DB->update_record('registration_hubs', $communication);
$hub->timemodified = time();
$DB->update_record('registration_hubs', $hub);
}
/**
* Return all hubs where the site is registered on
* Return all hubs where the site is registered
*/
public function get_registered_on_hubs() {
global $DB;

View File

@ -116,6 +116,7 @@ if ($update and confirm_sesskey()) {
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
try {
$result = $xmlrpcclient->call($function, $params);
$registrationmanager->update_registeredhub($registeredhub); // To update timemodified.
} catch (Exception $e) {
$error = $OUTPUT->notification(get_string('errorregistration', 'hub', $e->getMessage()));
}
@ -175,8 +176,20 @@ if (!empty($error)) {
echo $error;
}
//some Moodle.org resitration explanation
// Some Moodle.org registration explanation.
if ($huburl == HUB_MOODLEORGHUBURL) {
if (!empty($registeredhub->token)) {
if ($registeredhub->timemodified == 0) {
$registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
} else {
$lastupdated = userdate($registeredhub->timemodified, get_string('strftimedate', 'langconfig'));
$registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
}
} else {
$registrationmessage = get_string('registrationwarning', 'admin');
}
echo $OUTPUT->notification($registrationmessage);
echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
$renderer = $PAGE->get_renderer('core', 'register');
echo $renderer->moodleorg_registration_message();

View File

@ -800,8 +800,8 @@ $string['performance'] = 'Performance';
$string['pgcluster'] = 'PostgreSQL Cluster';
$string['pgclusterdescription'] = 'PostgreSQL version/cluster parameter for command line operations. If you only have one postgresql on your system or you are not sure what this is, leave this blank.';
$string['phpfloatproblem'] = 'Detected unexpected problem in handling of PHP float numbers - {$a}';
$string['pleaserefreshregistration'] = 'Your site has been registered with moodle.org, please consider updating the registration if significant changes happened since your last update, on {$a}';
$string['pleaseregister'] = 'Please register your site to remove this button';
$string['pleaserefreshregistration'] = 'Your site has been registered. Registration last updated {$a}. You can manually update your registration at any time.';
$string['pleaserefreshregistrationunknown'] = 'Your site has been registered but the registration date is unknown. Please update your registration using the \'Update registration\' button or enable the \'Site registration\' scheduled task so that your registration is automatically updated.';
$string['plugin'] = 'Plugin';
$string['plugins'] = 'Plugins';
$string['pluginscheck'] = 'Plugin dependencies check';

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20141202" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20150127" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -2663,6 +2663,7 @@
<FIELD NAME="huburl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="confirmed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="secret" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="the unique site identifier for this hub"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@ -3095,4 +3096,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -4161,5 +4161,21 @@ function xmldb_main_upgrade($oldversion) {
// Main savepoint reached.
upgrade_main_savepoint(true, 2015012600.01);
}
if ($oldversion < 2015012900.01) {
// Define field timemodified to be added to registration_hubs.
$table = new xmldb_table('registration_hubs');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'secret');
// Conditionally launch add field timemodified.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015012900.01);
}
return true;
}