Commit 64f3d964 authored by Robert Lyon's avatar Robert Lyon

Bug 1215271: Show warning if db is newer than files

And throw error if the site is a production site

behatnotneeded

Change-Id: I5b92ed0b5ab7e91f71afb2b4f3fc22f3805cc928
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 19a68352
......@@ -336,6 +336,16 @@ if (get_config('installed')) {
if ($upgradeavailable) {
ensure_upgrade_sanity();
}
else if ($config->version < get_config('version')) {
if (get_config('productionmode')) {
throw new ConfigSanityException("Database version of Mahara $corerelease ($coreversion) is newer "
. "than files version $config->release ($config->version). "
. "Please make sure you have the correct Mahara files in place.");
}
else {
define('SITEOUTOFSYNC', 'core');
}
}
if ($upgradeavailable != get_config('siteclosedforupgrade')) {
set_config('siteclosedforupgrade', $upgradeavailable);
}
......
......@@ -148,4 +148,5 @@ $string['wrongsessionhandle'] = 'The session save handler "%s" is not supported
$string['nomemcachedserver'] = 'The memcache server "%s" is not reachable. Please check the $cfg->memcacheservers value to make sure it is correct';
$string['nophpextension'] = 'The PHP extension "%s" is not enabled. Please enable the extension and restart your webserver or choose a different session option.';
$string['nomemcacheserversdefined'] = 'The session save handler "%s" has no related servers defined. Please set the $cfg->memcacheservers value, eg "localhost:11211"';
$string['memcacheusememcached'] = 'The "memcache" session storage is obsolete. Please use "memcached"';
\ No newline at end of file
$string['memcacheusememcached'] = 'The "memcache" session storage is obsolete. Please use "memcached"';
$string['siteoutofsyncfor'] = 'This site has database information newer than %s files indicate it should be.';
......@@ -54,6 +54,7 @@ function check_upgrades($name=null) {
catch (Exception $e) {
$coreversion = 0;
}
$corerelease = get_config('release');
$core = new stdClass();
$core->to = $config->version;
$core->torelease = $config->release;
......@@ -81,7 +82,6 @@ function check_upgrades($name=null) {
$installing = true;
}
else if ($config->version > $coreversion) {
$corerelease = get_config('release');
if (isset($config->minupgradefrom) && isset($config->minupgraderelease)
&& $coreversion < $config->minupgradefrom) {
throw new ConfigSanityException("Must upgrade to $config->minupgradefrom "
......@@ -93,6 +93,16 @@ function check_upgrades($name=null) {
$core->from = $coreversion;
$core->fromrelease = $corerelease;
}
else if ($config->version < $coreversion) {
if (get_config('productionmode')) {
throw new ConfigSanityException("Database version of Mahara $corerelease ($coreversion) is newer "
. "than files version $config->release ($config->version). "
. "Please make sure you have the correct Mahara files in place.");
}
else {
define('SITEOUTOFSYNC', 'core');
}
}
else {
// Core doesn't need to be upgraded. Remove it from the list!
unset($toupgrade['core']);
......@@ -220,6 +230,11 @@ function check_upgrades($name=null) {
$config = new StdClass;
require(get_config('docroot') . $pluginpath . '/version.php');
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
// Check if there is a displayname
$plugindisplayname = call_static_method($classname, 'get_plugin_display_name');
if (empty($pluginversion)) {
$newinstall = false;
if (empty($installing) && $pluginkey != $name) {
......@@ -235,11 +250,7 @@ function check_upgrades($name=null) {
if (property_exists($config, 'requires_parent')) {
$plugininfo->requires_parent = $config->requires_parent;
}
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
// Check if there is a displayname
$plugininfo->displayname = call_static_method($classname, 'get_plugin_display_name');
$plugininfo->displayname = $plugindisplayname;
try {
$classname::sanity_check();
......@@ -281,11 +292,8 @@ function check_upgrades($name=null) {
if (property_exists($config, 'requires_parent')) {
$plugininfo->requires_parent = $config->requires_parent;
}
$plugininfo->displayname = $plugindisplayname;
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
// Check if there is a displayname
$plugininfo->displayname = call_static_method($classname, 'get_plugin_display_name');
try {
$classname::sanity_check();
}
......@@ -300,6 +308,18 @@ function check_upgrades($name=null) {
$toupgrade[$pluginkey] = $plugininfo;
}
else if ($config->version < $pluginversion) {
$plugindisplayname = !empty($plugindisplayname) ? $plugindisplayname : $config->name;
if (get_config('productionmode')) {
throw new ConfigSanityException("Database version of Mahara plugin " . $plugindisplayname . " "
. $pluginrelease . " (" . $pluginversion . ") is newer "
. "than files version " . $config->release . " (" . $config->version . "). "
. "Please make sure you have the correct Mahara plugin files in place.");
}
else {
define('SITEOUTOFSYNC', $plugindisplayname);
}
}
}
// if we've just asked for one, don't return an array...
......
......@@ -694,6 +694,9 @@ EOF;
}
$smarty->assign('PRODUCTIONMODE', get_config('productionmode'));
if (defined('SITEOUTOFSYNC')) {
$smarty->assign('SITEOUTOFSYNC', SITEOUTOFSYNC);
}
if (function_exists('local_header_top_content')) {
$sitetop = (isset($sitetop) ? $sitetop : '') . local_header_top_content();
}
......
......@@ -25,6 +25,12 @@
{str tag=notproductionsite section=error}
</div>
{/if}
{if $SITEOUTOFSYNC}
<div class="site-message alert alert-warning" role="alert">
<span class="icon icon-lg icon-info-circle left" role="presentation" aria-hidden="true"></span>
{str tag=siteoutofsyncfor section=error arg1=$SITEOUTOFSYNC}
</div>
{/if}
{if $SITECLOSED}
<div class="site-message alert alert-danger" role="alert">
<span class="icon icon-lg icon-lock left" role="presentation" aria-hidden="true"></span>
......
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