mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-27171 messages: implement new syntax in messages.php and update processing
The new messaging default settings can be set in messages.php and deployed during installation. This also ensures the removing of settings on plugin uninstallation and contains the update script to populate current default settings on the existing system when the new feature is introduced. For security reason we have to avoid using library functions in upgrade function, so we set defaults the blind way. At this point we do not expect plugins to have individual messaging defaults presets anyway. The site defaults are the same as were set for each user using message_set_default_message_preferences function. Signed-off-by: Ruslan Kabalin <ruslan.kabalin@luns.net.uk>
This commit is contained in:
parent
3bcbd80ebe
commit
7a04c476a2
11 changed files with 201 additions and 60 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20110523" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20110525" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
|
@ -2220,8 +2220,9 @@
|
|||
</TABLE>
|
||||
<TABLE NAME="message_processors" COMMENT="List of message output plugins" PREVIOUS="message_providers" NEXT="message_working">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" COMMENT="Default comment for the field, please edit me" PREVIOUS="id"/>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" COMMENT="Name of the message processor" PREVIOUS="id" NEXT="enabled"/>
|
||||
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT="Defines if processor is enabled" PREVIOUS="name"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
|
||||
|
|
|
@ -39,6 +39,10 @@ $messageproviders = array (
|
|||
),
|
||||
|
||||
'instantmessage' => array (
|
||||
'defaults' => array(
|
||||
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
|
||||
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDOFF,
|
||||
),
|
||||
),
|
||||
|
||||
'backup' => array (
|
||||
|
|
|
@ -6122,6 +6122,11 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
|||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Populate default messaging settings
|
||||
upgrade_populate_default_messaging_prefs();
|
||||
|
||||
upgrade_main_savepoint(true, 2011052500.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -645,3 +645,54 @@ function update_fix_automated_backup_config() {
|
|||
unset_config('backup_sche_gradebook_history');
|
||||
unset_config('disablescheduleddbackups');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to set default messaging preferences when the new
|
||||
* admin-level messaging defaults settings have been introduced.
|
||||
*/
|
||||
function upgrade_populate_default_messaging_prefs() {
|
||||
global $DB;
|
||||
|
||||
$providers = $DB->get_records('message_providers');
|
||||
$processors = $DB->get_records('message_processors');
|
||||
$defaultpreferences = $DB->get_records_menu('config_plugins', array('plugin'=>'message'), '', 'name,value');
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
$setting = new stdClass();
|
||||
$setting->plugin = 'message';
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
$componentproviderbase = $provider->component.'_'.$provider->name;
|
||||
// set MESSAGE_PERMITTED to all combinations of message types
|
||||
// (providers) and outputs (processors)
|
||||
foreach ($processors as $processor) {
|
||||
$preferencename = $processor->name.'_provider_'.$componentproviderbase.'_permitted';
|
||||
if (!array_key_exists($preferencename, $defaultpreferences)) {
|
||||
$setting->name = $preferencename;
|
||||
$setting->value = 'permitted';
|
||||
$DB->insert_record('config_plugins', $setting);
|
||||
}
|
||||
}
|
||||
// for email output we also have to set MESSAGE_DEFAULT_OFFLINE + MESSAGE_DEFAULT_ONLINE
|
||||
foreach(array('loggedin', 'loggedoff') as $state) {
|
||||
$preferencename = 'message_provider_'.$componentproviderbase.'_'.$state;
|
||||
if (!array_key_exists($preferencename, $defaultpreferences)) {
|
||||
$setting->name = $preferencename;
|
||||
$setting->value = 'email';
|
||||
// except instant message where default for popup should be
|
||||
// MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF and for email
|
||||
// MESSAGE_DEFAULT_LOGGEDOFF.
|
||||
if ($componentproviderbase == 'moodle_instantmessage') {
|
||||
if ($state == 'loggedoff') {
|
||||
$setting->value = 'email,popup';
|
||||
} else {
|
||||
$setting->value = 'popup';
|
||||
}
|
||||
}
|
||||
$DB->insert_record('config_plugins', $setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue