namespace BookStack\Exports\Controllers;
-use BookStack\Activity\ActivityType;
+use BookStack\Exceptions\ZipImportException;
use BookStack\Exceptions\ZipValidationException;
use BookStack\Exports\ImportRepo;
use BookStack\Http\Controller;
* Show the view to start a new import, and also list out the existing
* in progress imports that are visible to the user.
*/
- public function start(Request $request)
+ public function start()
{
- // TODO - Test visibility access for listed items
$imports = $this->imports->getVisibleImports();
$this->setPageTitle(trans('entities.import'));
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());
}
*/
public function show(int $id)
{
- // TODO - Test visibility access
$import = $this->imports->findVisible($id);
$this->setPageTitle(trans('entities.import_continue'));
return view('exports.import-show', [
'import' => $import,
+ 'data' => $import->decodeMetadata(),
]);
}
+ /**
+ * Run the import process against an uploaded import ZIP.
+ */
+ public function run(int $id, Request $request)
+ {
+ $import = $this->imports->findVisible($id);
+ $parent = null;
+
+ if ($import->type === 'page' || $import->type === 'chapter') {
+ session()->setPreviousUrl($import->getUrl());
+ $data = $this->validate($request, [
+ 'parent' => ['required', 'string'],
+ ]);
+ $parent = $data['parent'];
+ }
+
+ try {
+ $entity = $this->imports->runImport($import, $parent);
+ } catch (ZipImportException $exception) {
+ session()->flush();
+ $this->showErrorNotification(trans('errors.import_zip_failed_notification'));
+ return redirect($import->getUrl())->with('import_errors', $exception->errors);
+ }
+
+ return redirect($entity->getUrl());
+ }
+
/**
* Delete an active pending import from the filesystem and database.
*/
public function delete(int $id)
{
- // TODO - Test visibility access
$import = $this->imports->findVisible($id);
$this->imports->deleteImport($import);
- $this->logActivity(ActivityType::IMPORT_DELETE, $import);
-
return redirect('/import');
}
}