1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

ZIP Import: Finished base import process & error handling

Added file creation reverting and DB rollback on error.
Added error display on failed import.
Extracted likely shown import form/error text to translation files.
This commit is contained in:
Dan Brown
2024-11-14 15:59:15 +00:00
parent 48c101aa7a
commit b7476a9e7f
10 changed files with 146 additions and 69 deletions

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace BookStack\Exports\Controllers;
use BookStack\Activity\ActivityType;
use BookStack\Exceptions\ZipImportException;
use BookStack\Exceptions\ZipValidationException;
use BookStack\Exports\ImportRepo;
use BookStack\Http\Controller;
@@ -48,12 +48,9 @@ class ImportController extends Controller
try {
$import = $this->imports->storeFromUpload($file);
} catch (ZipValidationException $exception) {
session()->flash('validation_errors', $exception->errors);
return redirect('/import');
return redirect('/import')->with('validation_errors', $exception->errors);
}
$this->logActivity(ActivityType::IMPORT_CREATE, $import);
return redirect($import->getUrl());
}
@@ -80,20 +77,20 @@ class ImportController extends Controller
$parent = null;
if ($import->type === 'page' || $import->type === 'chapter') {
session()->setPreviousUrl($import->getUrl());
$data = $this->validate($request, [
'parent' => ['required', 'string']
'parent' => ['required', 'string'],
]);
$parent = $data['parent'];
}
$entity = $this->imports->runImport($import, $parent);
if ($entity) {
$this->logActivity(ActivityType::IMPORT_RUN, $import);
return redirect($entity->getUrl());
try {
$entity = $this->imports->runImport($import, $parent);
} catch (ZipImportException $exception) {
return redirect($import->getUrl())->with('import_errors', $exception->errors);
}
// TODO - Redirect to result
// TODO - Or redirect back with errors
return 'failed';
return redirect($entity->getUrl());
}
/**
@@ -104,8 +101,6 @@ class ImportController extends Controller
$import = $this->imports->findVisible($id);
$this->imports->deleteImport($import);
$this->logActivity(ActivityType::IMPORT_DELETE, $import);
return redirect('/import');
}
}