Permalink
Browse files

MDL-27171 messages: populate messaging defaults after the installation

This makes the order of plugins returned by get_plugin_types not important as
all messaging defaults population is done at the end.

Signed-off-by: Ruslan Kabalin <ruslan.kabalin@luns.net.uk>
  • Loading branch information...
1 parent 60bbe76 commit 67147c25508c7f6b5fd6936e02c3646b4d0a83ba Ruslan Kabalin committed May 31, 2011
Showing with 28 additions and 14 deletions.
  1. +3 −5 admin/index.php
  2. +23 −5 lib/installlib.php
  3. +2 −4 lib/moodlelib.php
View
@@ -43,6 +43,7 @@
require('../config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
+require_once($CFG->libdir.'/installlib.php'); // general upgrade/install related functions
$id = optional_param('id', '', PARAM_TEXT);
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
@@ -320,11 +321,8 @@
// If this is the first install, indicate that this site is fully configured
// except the admin password
if (during_initial_install()) {
- // ensure message preferences for the core message providers are set
- $fileproviders = message_get_providers_from_file('moodle');
- foreach ($fileproviders as $messagename => $fileprovider) {
- message_set_default_message_preference('moodle', $messagename, $fileprovider);
- }
+ // ensure default message preferences for message providers are set
+ install_populate_default_messaging_prefs();
set_config('rolesactive', 1); // after this, during_initial_install will return false.
set_config('adminsetuppending', 1);
View
@@ -558,11 +558,8 @@ function install_cli_database(array $options, $interactive) {
// install all plugins types, local, etc.
upgrade_noncore(true);
- // ensure message preferences for the core message providers are set
- $fileproviders = message_get_providers_from_file('moodle');
- foreach ($fileproviders as $messagename => $fileprovider) {
- message_set_default_message_preference('moodle', $messagename, $fileprovider);
- }
+ // ensure default message preferences for message providers are set
+ install_populate_default_messaging_prefs();
// set up admin user password
$DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin'));
@@ -594,3 +591,24 @@ function install_cli_database(array $options, $interactive) {
$DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site'));
}
}
+
+/**
+ * Populate default messaging preferences after installation.
+ *
+ * @return void
+ */
+function install_populate_default_messaging_prefs() {
+ global $DB;
+
+ $providers = $DB->get_records_sql('SELECT DISTINCT component FROM {message_providers}');
+
+ $transaction = $DB->start_delegated_transaction();
+ foreach ($providers as $provider) {
+ // load message providers from files
+ $fileproviders = message_get_providers_from_file($provider->component);
+ foreach ($fileproviders as $messagename => $fileprovider) {
+ message_set_default_message_preference($provider->component, $messagename, $fileprovider);
+ }
+ }
+ $transaction->allow_commit();
+}
View
@@ -7067,12 +7067,10 @@ function get_plugin_types($fullpaths=true) {
static $fullinfo = null;
if (!$info) {
- // BEWARE: message/output should always be the first as we need to have
- // message outputs installed before installing every other plugin.
- $info = array('message' => 'message/output',
- 'mod' => 'mod',
+ $info = array('mod' => 'mod',
'auth' => 'auth',
'enrol' => 'enrol',
+ 'message' => 'message/output',
'block' => 'blocks',
'filter' => 'filter',
'editor' => 'lib/editor',

0 comments on commit 67147c2

Please sign in to comment.