added checkbox to not stop on error

This commit is contained in:
Roland Gruber 2018-09-15 18:25:53 +02:00
parent cd749730a4
commit 0cc31a4391
2 changed files with 13 additions and 1 deletions

View File

@ -43,6 +43,7 @@ class Importer {
const SESSION_KEY_TASKS = 'import_tasks'; const SESSION_KEY_TASKS = 'import_tasks';
const SESSION_KEY_COUNT = 'import_count'; const SESSION_KEY_COUNT = 'import_count';
const SESSION_KEY_STOP_ON_ERROR = 'import_stop_on_error';
const STATUS = 'status'; const STATUS = 'status';
const PROGRESS = 'progress'; const PROGRESS = 'progress';
const DATA = 'data'; const DATA = 'data';
@ -118,6 +119,7 @@ class Importer {
public function doImport() { public function doImport() {
$data = ''; $data = '';
$tasks = &$_SESSION[Importer::SESSION_KEY_TASKS]; $tasks = &$_SESSION[Importer::SESSION_KEY_TASKS];
$stopOnError = $_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR];
// check if any actions are needed at all // check if any actions are needed at all
if (empty($tasks)) { if (empty($tasks)) {
return $this->getStatus($data); return $this->getStatus($data);
@ -129,8 +131,13 @@ class Importer {
$data .= $task->run(); $data .= $task->run();
} }
catch (LAMException $e) { catch (LAMException $e) {
if ($stopOnError) {
return $this->stopImport($data, $e); return $this->stopImport($data, $e);
} }
else {
$data .= Importer::formatMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
} }
return $this->getStatus($data); return $this->getStatus($data);
} }

View File

@ -74,6 +74,9 @@ if (isset($_SESSION[Importer::SESSION_KEY_TASKS])) {
if (isset($_SESSION[Importer::SESSION_KEY_COUNT])) { if (isset($_SESSION[Importer::SESSION_KEY_COUNT])) {
unset($_SESSION[Importer::SESSION_KEY_COUNT]); unset($_SESSION[Importer::SESSION_KEY_COUNT]);
} }
if (isset($_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR])) {
unset($_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR]);
}
include '../../lib/adminHeader.inc'; include '../../lib/adminHeader.inc';
$tabindex = 1; $tabindex = 1;
@ -142,6 +145,7 @@ function printImportTabContent(&$tabindex) {
$container->addVerticalSpacer('1rem'); $container->addVerticalSpacer('1rem');
$container->add(new htmlResponsiveInputFileUpload('file', _('File'), '750'), 12); $container->add(new htmlResponsiveInputFileUpload('file', _('File'), '750'), 12);
$container->add(new htmlResponsiveInputTextarea('text', '', '60', '20', _('LDIF data'), '750'), 12); $container->add(new htmlResponsiveInputTextarea('text', '', '60', '20', _('LDIF data'), '750'), 12);
$container->add(new \htmlResponsiveInputCheckbox('noStop', false, _('Don\'t stop on errors')), 12);
$container->addVerticalSpacer('3rem'); $container->addVerticalSpacer('3rem');
$button = new htmlButton('submitImport', _('Submit')); $button = new htmlButton('submitImport', _('Submit'));
@ -222,6 +226,7 @@ function checkImportData() {
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$_SESSION[Importer::SESSION_KEY_TASKS] = $tasks; $_SESSION[Importer::SESSION_KEY_TASKS] = $tasks;
$_SESSION[Importer::SESSION_KEY_COUNT] = sizeof($tasks); $_SESSION[Importer::SESSION_KEY_COUNT] = sizeof($tasks);
$_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR] = (!isset($_POST['noStop']) || ($_POST['noStop'] != 'on'));
} }
include '../../lib/adminFooter.inc'; include '../../lib/adminFooter.inc';