Skip to content

Commit

Permalink
MDL-48894 core_registration: make it more obvious if site is registered
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjdavis committed Feb 10, 2015
1 parent 88cd577 commit 806c06f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
11 changes: 7 additions & 4 deletions admin/registration/lib.php
Expand Up @@ -69,6 +69,7 @@ public function cron() {
$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();
Expand Down Expand Up @@ -118,6 +119,7 @@ public function get_site_secret_for_hub($huburl) {
*/
public function add_registeredhub($hub) {
global $DB;
$hub->timemodified = time();
$id = $DB->insert_record('registration_hubs', $hub);
return $id;
}
Expand Down Expand Up @@ -171,15 +173,16 @@ public function get_unconfirmedhub($huburl) {

/**
* 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;
Expand Down
15 changes: 14 additions & 1 deletion admin/registration/register.php
Expand Up @@ -116,6 +116,7 @@
$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()));
}
Expand Down Expand Up @@ -175,8 +176,20 @@
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();
Expand Down
4 changes: 2 additions & 2 deletions lang/en/admin.php
Expand Up @@ -800,8 +800,8 @@
$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';
Expand Down
5 changes: 3 additions & 2 deletions lib/db/install.xml
@@ -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"
>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -3095,4 +3096,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
16 changes: 16 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -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;
}

0 comments on commit 806c06f

Please sign in to comment.