From 806c06fc7b435dea11361b6c566549abdb103197 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 26 Jan 2015 12:07:07 +0100 Subject: [PATCH] MDL-48894 core_registration: make it more obvious if site is registered --- admin/registration/lib.php | 11 +++++++---- admin/registration/register.php | 15 ++++++++++++++- lang/en/admin.php | 4 ++-- lib/db/install.xml | 5 +++-- lib/db/upgrade.php | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/admin/registration/lib.php b/admin/registration/lib.php index a8086e17568..6aed4376f30 100644 --- a/admin/registration/lib.php +++ b/admin/registration/lib.php @@ -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; diff --git a/admin/registration/register.php b/admin/registration/register.php index 1fd0e33efac..42060898d47 100644 --- a/admin/registration/register.php +++ b/admin/registration/register.php @@ -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(); diff --git a/lang/en/admin.php b/lang/en/admin.php index fe654e633df..342d9ca7f27 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -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'; diff --git a/lib/db/install.xml b/lib/db/install.xml index ee5f49dc230..b82d64e4cbd 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2663,6 +2663,7 @@ + @@ -3095,4 +3096,4 @@ - + \ No newline at end of file diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 59417d2aa1d..d74c4c4e400 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; }