Skip to content

Commit

Permalink
MDL-57791 analytics: Set logstore during install
Browse files Browse the repository at this point in the history
get_analytics_logstore updated to fix an edge case.
  • Loading branch information
dmonllao committed Jul 25, 2017
1 parent 466f683 commit 85e50ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions admin/settings/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@
}
$options[$plugin] = $reader->get_name();
}

if (empty($defaultreader)) {
// We fall here during initial site installation because log stores are not
// enabled until admin/tool/log/db/install.php is executed and get_readers
// return nothing.

if ($enabledlogstores = get_config('tool_log', 'enabled_stores')) {
$enabledlogstores = explode(',', $enabledlogstores);
$defaultreader = reset($enabledlogstores);

// No need to set the correct name, just the value, this will not be displayed.
$options[$defaultreader] = $defaultreader;
}
}
$settings->add(new admin_setting_configselect('analytics/logstore',
new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
$defaultreader, $options));
Expand Down
8 changes: 5 additions & 3 deletions analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,12 @@ public static function is_valid($fullclassname, $baseclass) {
public static function get_analytics_logstore() {
$readers = get_log_manager()->get_readers('core\log\sql_reader');
$analyticsstore = get_config('analytics', 'logstore');
if (empty($analyticsstore)) {
$logstore = reset($readers);
} else if (!empty($readers[$analyticsstore])) {

if (!empty($analyticsstore) && !empty($readers[$analyticsstore])) {
$logstore = $readers[$analyticsstore];
} else if (empty($analyticsstore) && !empty($readers)) {
// The first one, it is the same default than in settings.
$logstore = reset($readers);
} else if (!empty($readers)) {
$logstore = reset($readers);
debugging('The selected log store for analytics is not available anymore. Using "' .
Expand Down

0 comments on commit 85e50ba

Please sign in to comment.