mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-67753 registration: Enable Push Notifications when site register
There are some changes to make this possible: - Enable by default the Mobile notifications plugin - Implement a new callback for core -> plugins communication - Generate an Airnotifier access key in the callback when needed
This commit is contained in:
parent
a09eb2697f
commit
37bd67f54b
@ -78,15 +78,7 @@ class tool_mobile_api_testcase extends externallib_advanced_testcase {
|
||||
$CFG->debugdisplay = 1;
|
||||
set_config('debugauthdb', 1, 'auth_db');
|
||||
set_config('debugdb', 1, 'enrol_database');
|
||||
$expectedissues = array('nohttpsformobilewarning', 'invaliduserquotawarning', 'adodbdebugwarning', 'displayerrorswarning',
|
||||
'mobilenotificationsdisabledwarning');
|
||||
|
||||
$processors = get_message_processors();
|
||||
foreach ($processors as $processor => $status) {
|
||||
if ($processor == 'airnotifier' && $status->enabled) {
|
||||
unset($expectedissues['mobilenotificationsdisabledwarning']);
|
||||
}
|
||||
}
|
||||
$expectedissues = array('nohttpsformobilewarning', 'invaliduserquotawarning', 'adodbdebugwarning', 'displayerrorswarning');
|
||||
|
||||
$issues = api::get_potential_config_issues();
|
||||
$this->assertCount(count($expectedissues), $issues);
|
||||
|
@ -362,6 +362,14 @@ class registration {
|
||||
api::update_registration($siteinfo);
|
||||
self::$registration = null;
|
||||
}
|
||||
|
||||
// Finally, allow other plugins to perform actions once a site is registered for first time.
|
||||
$pluginsfunction = get_plugins_with_function('post_site_registration_confirmed');
|
||||
foreach ($pluginsfunction as $plugins) {
|
||||
foreach ($plugins as $pluginfunction) {
|
||||
$pluginfunction($registration->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,9 @@ defined('MOODLE_INTERNAL') || die;
|
||||
*/
|
||||
class message_airnotifier_manager {
|
||||
|
||||
/** @var string The Airnotifier public instance URL */
|
||||
const AIRNOTIFIER_PUBLICURL = 'https://messages.moodle.net';
|
||||
|
||||
/**
|
||||
* Include the relevant javascript and language strings for the device
|
||||
* toolbox YUI module
|
||||
|
@ -32,7 +32,6 @@ function xmldb_message_airnotifier_install() {
|
||||
|
||||
$provider = new stdClass();
|
||||
$provider->name = 'airnotifier';
|
||||
$provider->enabled = 0;
|
||||
$DB->insert_record('message_processors', $provider);
|
||||
|
||||
return $result;
|
||||
|
50
message/output/airnotifier/lib.php
Normal file
50
message/output/airnotifier/lib.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Callbacks for message_airnotifier.
|
||||
*
|
||||
* @package message_airnotifier
|
||||
* @category external
|
||||
* @copyright 2020 Moodle Pty Ltd <juan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback for when a site is first registered. The function generates an Airnotifier accesskey for the new site.
|
||||
*
|
||||
* @param int $registrationid the new registration id (registration_hubs table)
|
||||
*/
|
||||
function message_airnotifier_post_site_registration_confirmed(int $registrationid) {
|
||||
global $CFG;
|
||||
|
||||
// Do nothing if the site already has an Airnotifier access key configured.
|
||||
if (!empty($CFG->airnotifieraccesskey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$manager = new message_airnotifier_manager();
|
||||
|
||||
// Do nothing for custom Airnotifier instances.
|
||||
if (strpos($CFG->airnotifierurl, $manager::AIRNOTIFIER_PUBLICURL) === false ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($key = $manager->request_accesskey()) {
|
||||
set_config('airnotifieraccesskey', $key);
|
||||
}
|
||||
}
|
@ -24,8 +24,6 @@
|
||||
|
||||
require('../../../config.php');
|
||||
|
||||
define('AIRNOTIFIER_PUBLICURL', 'https://messages.moodle.net');
|
||||
|
||||
$PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php'));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
@ -48,7 +46,7 @@ $msg = "";
|
||||
|
||||
// If we are requesting a key to the official message system, verify first that this site is registered.
|
||||
// This check is also done in Airnotifier.
|
||||
if (strpos($CFG->airnotifierurl, AIRNOTIFIER_PUBLICURL) !== false ) {
|
||||
if (strpos($CFG->airnotifierurl, message_airnotifier_manager::AIRNOTIFIER_PUBLICURL) !== false ) {
|
||||
$adminrenderer = $PAGE->get_renderer('core', 'admin');
|
||||
$msg = $adminrenderer->warn_if_not_registered();
|
||||
if ($msg) {
|
||||
|
@ -27,7 +27,8 @@ if ($ADMIN->fulltree) {
|
||||
// The processor should be enabled by the same enable mobile setting.
|
||||
$settings->add(new admin_setting_configtext('airnotifierurl',
|
||||
get_string('airnotifierurl', 'message_airnotifier'),
|
||||
get_string('configairnotifierurl', 'message_airnotifier'), 'https://messages.moodle.net', PARAM_URL));
|
||||
get_string('configairnotifierurl', 'message_airnotifier'), message_airnotifier_manager::AIRNOTIFIER_PUBLICURL,
|
||||
PARAM_URL));
|
||||
$settings->add(new admin_setting_configtext('airnotifierport',
|
||||
get_string('airnotifierport', 'message_airnotifier'),
|
||||
get_string('configairnotifierport', 'message_airnotifier'), 443, PARAM_INT));
|
||||
|
Loading…
x
Reference in New Issue
Block a user