Commit 5f2083a9 authored by Penny Leach's avatar Penny Leach
Browse files

fixed the web based installer to not break on templates and report

errors properly
parent 330cb1d9
...@@ -36,21 +36,22 @@ if (!$install) { ...@@ -36,21 +36,22 @@ if (!$install) {
} }
if ($install) { if ($install) {
$message = '';
if (!get_config('installed')) { if (!get_config('installed')) {
try { try {
core_install_defaults(); core_install_defaults();
} }
catch (SQLException $e) { catch (SQLException $e) {
echo json_encode(array( json_reply(true, $e->getMessage());
'success' => 0, }
'errormessage' => $e->getMessage() catch (TemplateParserException $e) {
)); // these ones are non fatal...
exit; $message = $e->getMessage()
. ' ' . '<a href="' . get_config('wwwroot') .'admin/templates.php">'
. get_string('fixtemplatescontinue', 'admin') . '</a>';
} }
} }
json_reply(false, $message);
echo json_encode(array('success' => 1));
exit;
} }
$upgrade = check_upgrades($name); $upgrade = check_upgrades($name);
......
...@@ -59,15 +59,18 @@ if (!empty($upgrades['core']->install)) { ...@@ -59,15 +59,18 @@ if (!empty($upgrades['core']->install)) {
$('coredata').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />'; $('coredata').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';
d.addCallbacks(function (data) { d.addCallbacks(function (data) {
if ( data.success ) { if ( !data.error ) {
var message = '{$coresuccess}'; var message = '{$coresuccess}';
if (data.message) {
message += ' (' + data.message + ')';
}
$('coredata').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message; $('coredata').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
$('finished').style.visibility = 'visible'; $('finished').style.visibility = 'visible';
} }
else { else {
var message = ''; var message = '';
if (data.errormessage) { if (data.message) {
message = data.errormessage; message = data.message;
} }
else { else {
message = '{$failurestring}'; message = '{$failurestring}';
...@@ -99,7 +102,7 @@ $js .= <<< EOJS ...@@ -99,7 +102,7 @@ $js .= <<< EOJS
$(element).innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />'; $(element).innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';
d.addCallbacks(function (data) { d.addCallbacks(function (data) {
if ( data.success ) { if ( !data.error ) {
var message; var message;
if (data.install) { if (data.install) {
message = '{$installsuccessstring}'; message = '{$installsuccessstring}';
...@@ -112,8 +115,8 @@ $js .= <<< EOJS ...@@ -112,8 +115,8 @@ $js .= <<< EOJS
} }
else { else {
var message = ''; var message = '';
if (data.errormessage) { if (data.message) {
message = data.errormessage; message = data.message;
} }
else { else {
message = '{$failurestring}'; message = '{$failurestring}';
......
...@@ -42,6 +42,7 @@ $string['upgradeloading'] = 'Loading...'; ...@@ -42,6 +42,7 @@ $string['upgradeloading'] = 'Loading...';
$string['upgradesuccess'] = 'Successfully upgraded to version '; $string['upgradesuccess'] = 'Successfully upgraded to version ';
$string['upgradefailure'] = 'Failed to upgrade!'; $string['upgradefailure'] = 'Failed to upgrade!';
$string['noupgrades'] = 'Nothing to upgrade! You are fully up to date!'; $string['noupgrades'] = 'Nothing to upgrade! You are fully up to date!';
$string['fixtemplatescontinue'] = 'Try fixing this and continuing here (templates were not installed)';
// Admin navigation menu // Admin navigation menu
$string['usermanagement'] = 'Manage users'; $string['usermanagement'] = 'Manage users';
...@@ -164,4 +165,5 @@ $string['institutionupdatedsuccessfully'] = 'Institution updated successfully'; ...@@ -164,4 +165,5 @@ $string['institutionupdatedsuccessfully'] = 'Institution updated successfully';
$string['registrationallowed'] = 'Registration allowed?'; $string['registrationallowed'] = 'Registration allowed?';
$string['registrationalloweddescription'] = 'Whether users can register for the system with this institution'; $string['registrationalloweddescription'] = 'Whether users can register for the system with this institution';
?> ?>
...@@ -473,4 +473,9 @@ class ArtefactNotFoundException extends Exception {} ...@@ -473,4 +473,9 @@ class ArtefactNotFoundException extends Exception {}
* Exception - view not found * Exception - view not found
*/ */
class ViewNotFoundException extends Exception {} class ViewNotFoundException extends Exception {}
/**
* Exception - anything to do with template parsing
*/
class TemplateParserException extends Exception {}
?> ?>
...@@ -57,7 +57,7 @@ function template_parse($templatename) { ...@@ -57,7 +57,7 @@ function template_parse($templatename) {
if (count($blockids) != count(array_unique($blockids))) { if (count($blockids) != count(array_unique($blockids))) {
$dups = array_unique(array_diff_assoc($blockids, array_unique($blockids))); $dups = array_unique(array_diff_assoc($blockids, array_unique($blockids)));
throw new InvalidArgumentException("This template ($templatename) has duplicate block ids: " . implode(', ', $dups)); throw new TemplateParserException("This template ($templatename) has duplicate block ids: " . implode(', ', $dups));
} }
$temp = array('type' => 'html', $temp = array('type' => 'html',
...@@ -76,7 +76,7 @@ function template_parse_block($blockstr) { ...@@ -76,7 +76,7 @@ function template_parse_block($blockstr) {
// the first bit should be 'block' // the first bit should be 'block'
if ($bits[0] != 'block') { if ($bits[0] != 'block') {
throw new InvalidArgumentException("Invalid block section $blockstr"); throw new TemplateParserException("Invalid block section $blockstr");
} }
array_shift($bits); array_shift($bits);
...@@ -86,16 +86,16 @@ function template_parse_block($blockstr) { ...@@ -86,16 +86,16 @@ function template_parse_block($blockstr) {
} }
if (!isset($data['id']) || empty($data['id']) || strpos($data['id'], 'tpl_') !== 0) { if (!isset($data['id']) || empty($data['id']) || strpos($data['id'], 'tpl_') !== 0) {
throw new InvalidArgumentException("Invalid block section $blockstr - must have an id beginning with tpl_"); throw new TemplateParserException("Invalid block section $blockstr - must have an id beginning with tpl_");
} }
if (!isset($data['type']) || empty($data['type'])) { if (!isset($data['type']) || empty($data['type'])) {
throw new InvalidArgumentException("Invalid block section $blockstr - must have a type"); throw new TemplateParserException("Invalid block section $blockstr - must have a type");
} }
$types = array('artefact', 'label', 'title', 'author', 'description'); $types = array('artefact', 'label', 'title', 'author', 'description');
if (!in_array($data['type'], $types)){ if (!in_array($data['type'], $types)){
throw new InvalidArgumentException("Invalid block section $blockstr (type " . $data['type'] throw new TemplateParserException("Invalid block section $blockstr (type " . $data['type']
. " not one of " . implode(', ', $types)); . " not one of " . implode(', ', $types));
} }
...@@ -110,14 +110,14 @@ function template_parse_block($blockstr) { ...@@ -110,14 +110,14 @@ function template_parse_block($blockstr) {
if (isset($data['artefacttype'])) { if (isset($data['artefacttype'])) {
if (!$plugin = get_field('artefact_installed_type', 'plugin', 'name', $data['artefacttype'])) { if (!$plugin = get_field('artefact_installed_type', 'plugin', 'name', $data['artefacttype'])) {
throw new InvalidArgumentException("artefacttype " . $data['artefacttype'] . " is not installed"); throw new TemplateParserException("artefacttype " . $data['artefacttype'] . " is not installed");
} }
if (isset($data['format'])) { // check the artefacttype can render to this format. if (isset($data['format'])) { // check the artefacttype can render to this format.
safe_require('artefact', $plugin); safe_require('artefact', $plugin);
if (!artefact_can_render_to($data['artefacttype'], $data['format'])) { if (!artefact_can_render_to($data['artefacttype'], $data['format'])) {
throw new InvalidArgumentException("Artefacttype " . $data['artefacttype'] . " can't render to format " throw new TemplateParserException("Artefacttype " . $data['artefacttype'] . " can't render to format "
. $format['format']); . $format['format']);
} }
} }
...@@ -129,23 +129,23 @@ function template_parse_block($blockstr) { ...@@ -129,23 +129,23 @@ function template_parse_block($blockstr) {
safe_require('artefact', $data['plugintype']); safe_require('artefact', $data['plugintype']);
} }
catch (Exception $e) { catch (Exception $e) {
throw new InvalidArgumentException("Couldn't find plugin type " . $data['plugintype']); throw new TemplateParserException("Couldn't find plugin type " . $data['plugintype']);
} }
} }
if (isset($data['defaultartefacttype'])) { if (isset($data['defaultartefacttype'])) {
if (isset($data['artefacttype']) && $data['artefacttype'] != $data['defaultartefacttype']) { if (isset($data['artefacttype']) && $data['artefacttype'] != $data['defaultartefacttype']) {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
. " doesn't make sense given artefact type " . $data['artefacttype']); . " doesn't make sense given artefact type " . $data['artefacttype']);
} }
else if (isset($data['plugintype']) else if (isset($data['plugintype'])
&& !in_array($data['defaultartefacttype'], && !in_array($data['defaultartefacttype'],
call_static_method(generate_class_name($data['plugintype']), 'get_artefact_types'))) { call_static_method(generate_class_name($data['plugintype']), 'get_artefact_types'))) {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
." doesn't make sense given plugin type " . $data['plugintype']); ." doesn't make sense given plugin type " . $data['plugintype']);
} }
if (!$plugin = get_field('artefact_installed_type', 'plugin', 'name', $data['defaultartefacttype'])) { if (!$plugin = get_field('artefact_installed_type', 'plugin', 'name', $data['defaultartefacttype'])) {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
. " is not installed"); . " is not installed");
} }
// look for a default format... // look for a default format...
...@@ -154,7 +154,7 @@ function template_parse_block($blockstr) { ...@@ -154,7 +154,7 @@ function template_parse_block($blockstr) {
$data['defaultformat'] = $data['format']; $data['defaultformat'] = $data['format'];
} }
else { else {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
." specified but with no format method (couldn't find in either " ." specified but with no format method (couldn't find in either "
." default format, or fallback format field"); ." default format, or fallback format field");
} }
...@@ -162,13 +162,13 @@ function template_parse_block($blockstr) { ...@@ -162,13 +162,13 @@ function template_parse_block($blockstr) {
// check the default artefact type can render to the given default format // check the default artefact type can render to the given default format
safe_require('artefact', $plugin); safe_require('artefact', $plugin);
if (!artefact_can_render_to($data['defaultartefacttype'], $data['defaultformat'])) { if (!artefact_can_render_to($data['defaultartefacttype'], $data['defaultformat'])) {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
. " can't render to defaultformat " . $format['defaultformat']); . " can't render to defaultformat " . $format['defaultformat']);
} }
// check this default artefact is a 0 or 1 artefact // check this default artefact is a 0 or 1 artefact
if (!call_static_method(generate_artefact_class_name($data['defaultartefacttype']), 'is_0_or_1')) { if (!call_static_method(generate_artefact_class_name($data['defaultartefacttype']), 'is_0_or_1')) {
throw new InvalidArgumentException("Default artefact type " . $data['defaultartefacttype'] throw new TemplateParserException("Default artefact type " . $data['defaultartefacttype']
." is not a 0 or 1 type artefact"); ." is not a 0 or 1 type artefact");
} }
} }
...@@ -232,7 +232,7 @@ function template_locate($templatename, $fetchdb=true) { ...@@ -232,7 +232,7 @@ function template_locate($templatename, $fetchdb=true) {
return $template; return $template;
} }
throw new InvalidArgumentException("Invalid template name $templatename, couldn't find"); throw new TemplateParserException("Invalid template name $templatename, couldn't find");
} }
/** /**
......
...@@ -438,7 +438,7 @@ function upgrade_templates() { ...@@ -438,7 +438,7 @@ function upgrade_templates() {
foreach ($dbtemplates as $name => $guff) { foreach ($dbtemplates as $name => $guff) {
if (!is_readable($guff['location'] . 'config.php')) { if (!is_readable($guff['location'] . 'config.php')) {
throw new InvalidArgumentException("missing config.php for template $name"); throw new TemplateParserException("missing config.php for template $name");
} }
require_once($guff['location'] . 'config.php'); require_once($guff['location'] . 'config.php');
$fordb = new StdClass; $fordb = new StdClass;
......
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