Commit f62cafd8 authored by Robert Lyon's avatar Robert Lyon

Bug 1487815: Dealing with missing theme select box error

On site config page after upgrade some themes will not exist anymore
so we need to reset the theme to the default theme whatever that is
and alert the user about this.

We also need to set institution theme to sitedefault if their set theme
has gone.

behatnotneeded

Change-Id: I9459a920f1d870b71a9a0d48cc0ed39761152143
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent d1c6ae24
......@@ -20,6 +20,7 @@ require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php');
if (get_config('installed')) {
define('TITLE', get_string('administration', 'admin'));
validate_theme(get_config('theme'));
}
else {
define('TITLE', get_string('installation', 'admin'));
......
......@@ -33,6 +33,8 @@ $countries = getoptions_country();
$notificationelements = get_notification_settings_elements(null, true);
validate_theme(get_config('theme'));
$spamtraps = available_spam_traps();
$siteoptionform = array(
'name' => 'siteoptions',
......
......@@ -253,7 +253,9 @@ if ($institution || $add) {
$themeoptions = get_institution_themes($institution);
$themeoptions['sitedefault'] = '- ' . get_string('sitedefault', 'admin') . ' (' . $themeoptions[get_config('theme')] . ') -';
uksort($themeoptions, 'theme_sort');
if (validate_theme($data->theme, $institution) === false) {
$data->theme = 'sitedefault';
}
$showonlineusersoptions = array('0' => get_string('none'), '1' => get_string('institutiononly', 'admin'), '2' => get_string('all', 'admin'));
$sitename = get_config('sitename');
......
......@@ -101,7 +101,7 @@ $string['networking'] = 'Networking';
$string['networkingdescription'] = 'Configure networking for Mahara';
$string['cookieconsent'] = 'Cookie Consent';
$string['cookieconsentdescription'] = 'Configure the "Cookie Consent" user privacy system.';
$string['thememissing'] = 'The theme "%s" is missing. The theme has been set to the default theme.';
$string['staffusers'] = 'Staff users';
$string['staffusersdescription'] = 'Assign users staff permissions';
$string['adminusers'] = 'Admin users';
......
......@@ -792,6 +792,34 @@ function get_all_theme_objects() {
return $themes;
}
/**
* Checks if theme still exists and if not resets it to default option
*
* @param $theme string Name of theme
* @param $institution string Name of Institution
*
* @return bool True if theme exists
*/
function validate_theme($theme, $institution = null) {
global $SESSION;
if ($institution) {
$themeoptions = get_institution_themes($institution);
}
else {
$themeoptions = get_all_themes();
}
if (!array_key_exists($theme, $themeoptions)) {
if ($institution) {
set_config_institution($institution, 'theme', null);
}
else {
set_config('theme', 'default');
}
$SESSION->add_info_msg(get_string('thememissing', 'admin', $theme));
return false;
}
return true;
}
/**
* This function is only used from {@link get_string()}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment