Commit 3a61b674 authored by Penny Leach's avatar Penny Leach
Browse files

changed the way installing templates works a bit so that the good ones get

installed rather than none of them.
parent b14692f7
......@@ -39,15 +39,14 @@ if ($install) {
$message = '';
if (!get_config('installed')) {
try {
core_install_defaults();
$exceptions = core_install_defaults();
}
catch (SQLException $e) {
json_reply(true, $e->getMessage());
}
catch (TemplateParserException $e) {
if (is_array($exceptions) && count($exceptions) > 0) {
// these ones are non fatal...
$message = $e->getMessage()
. ' ' . '<a href="' . get_config('wwwroot') .'admin/templates.php">'
$message = '<a href="' . get_config('wwwroot') .'admin/extensions/templates.php">'
. get_string('fixtemplatescontinue', 'admin') . '</a>';
}
}
......
......@@ -44,7 +44,7 @@ $string['upgradeloading'] = 'Loading...';
$string['upgradesuccess'] = 'Successfully upgraded to version ';
$string['upgradefailure'] = 'Failed to upgrade!';
$string['noupgrades'] = 'Nothing to upgrade! You are fully up to date!';
$string['fixtemplatescontinue'] = 'Try fixing this and continuing here (templates were not installed)';
$string['fixtemplatescontinue'] = 'Some view templates failed to install. Continue here for more information and a fix.';
// Admin navigation menu
$string['adminhome'] = 'Admin home';
......@@ -186,5 +186,11 @@ $string['institutionupdatedsuccessfully'] = 'Institution updated successfully';
$string['registrationallowed'] = 'Registration allowed?';
$string['registrationalloweddescription'] = 'Whether users can register for the system with this institution';
// general stuff
$string['notificationssaved'] = 'Notification settings saved';
$string['installed'] = 'Installed';
$string['errors'] = 'Errors';
?>
......@@ -411,26 +411,29 @@ function core_install_defaults() {
set_profile_field($user->id, 'lastname', $user->lastname);
require('template.php');
try {
upgrade_templates();
}
catch (TemplateParserException $e) {
set_config('installed', true);
db_commit();
throw $e;
}
$exceptions = upgrade_templates(true);
set_config('installed', true);
db_commit();
return $exceptions;
}
function upgrade_templates() {
function upgrade_templates($continue=false) {
$exceptions = array();
$dbtemplates = array();
// check dataroot first, they get precedence.
$templates = get_dir_contents(get_config('dataroot') . 'templates/');
foreach ($templates as $dir) {
$dbtemplates[$dir] = template_parse($dir);
try {
$dbtemplates[$dir] = template_parse($dir);
}
catch (TemplateParserException $e) {
if (empty($continue)) {
throw $e;
}
$exceptions[] = $e;
}
}
// and now system templates
......@@ -439,12 +442,25 @@ function upgrade_templates() {
if (array_key_exists($dir, $dbtemplates)) { // dataroot gets preference
continue;
}
$dbtemplates[$dir] = template_parse($dir);
try {
$dbtemplates[$dir] = template_parse($dir);
}
catch (TemplateParserException $e) {
if (empty($continue)) {
throw $e;
}
$exceptions[] = $e;
}
}
foreach ($dbtemplates as $name => $guff) {
if (!is_readable($guff['location'] . 'config.php')) {
throw new TemplateParserException("missing config.php for template $name");
$e = new TemplateParserException("missing config.php for template $name");
if (empty($continue)) {
throw $e;
}
$exceptions[] = $e;
continue;
}
require_once($guff['location'] . 'config.php');
$fordb = new StdClass;
......@@ -481,7 +497,7 @@ function upgrade_templates() {
else {
set_field('template', 'deleted', 1);
}
return $exceptions;
}
......
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