Skip to content

Commit

Permalink
MDL-27171 messages: populate messaging defaults after the installation
Browse files Browse the repository at this point in the history
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
Ruslan Kabalin committed May 31, 2011
1 parent 60bbe76 commit 67147c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
8 changes: 3 additions & 5 deletions admin/index.php
Expand Up @@ -43,6 +43,7 @@
require('../config.php'); require('../config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions 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.'/upgradelib.php'); // general upgrade/install related functions
require_once($CFG->libdir.'/installlib.php'); // general upgrade/install related functions


$id = optional_param('id', '', PARAM_TEXT); $id = optional_param('id', '', PARAM_TEXT);
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
Expand Down Expand Up @@ -320,11 +321,8 @@
// If this is the first install, indicate that this site is fully configured // If this is the first install, indicate that this site is fully configured
// except the admin password // except the admin password
if (during_initial_install()) { if (during_initial_install()) {
// ensure message preferences for the core message providers are set // ensure default message preferences for message providers are set
$fileproviders = message_get_providers_from_file('moodle'); install_populate_default_messaging_prefs();
foreach ($fileproviders as $messagename => $fileprovider) {
message_set_default_message_preference('moodle', $messagename, $fileprovider);
}


set_config('rolesactive', 1); // after this, during_initial_install will return false. set_config('rolesactive', 1); // after this, during_initial_install will return false.
set_config('adminsetuppending', 1); set_config('adminsetuppending', 1);
Expand Down
28 changes: 23 additions & 5 deletions lib/installlib.php
Expand Up @@ -558,11 +558,8 @@ function install_cli_database(array $options, $interactive) {
// install all plugins types, local, etc. // install all plugins types, local, etc.
upgrade_noncore(true); upgrade_noncore(true);


// ensure message preferences for the core message providers are set // ensure default message preferences for message providers are set
$fileproviders = message_get_providers_from_file('moodle'); install_populate_default_messaging_prefs();
foreach ($fileproviders as $messagename => $fileprovider) {
message_set_default_message_preference('moodle', $messagename, $fileprovider);
}


// set up admin user password // set up admin user password
$DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin')); $DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin'));
Expand Down Expand Up @@ -594,3 +591,24 @@ function install_cli_database(array $options, $interactive) {
$DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site')); $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();
}
6 changes: 2 additions & 4 deletions lib/moodlelib.php
Expand Up @@ -7067,12 +7067,10 @@ function get_plugin_types($fullpaths=true) {
static $fullinfo = null; static $fullinfo = null;


if (!$info) { if (!$info) {
// BEWARE: message/output should always be the first as we need to have $info = array('mod' => 'mod',
// message outputs installed before installing every other plugin.
$info = array('message' => 'message/output',
'mod' => 'mod',
'auth' => 'auth', 'auth' => 'auth',
'enrol' => 'enrol', 'enrol' => 'enrol',
'message' => 'message/output',
'block' => 'blocks', 'block' => 'blocks',
'filter' => 'filter', 'filter' => 'filter',
'editor' => 'lib/editor', 'editor' => 'lib/editor',
Expand Down

0 comments on commit 67147c2

Please sign in to comment.