namespace BookStack\Exports\Controllers;
-use BookStack\Activity\ActivityType;
+use BookStack\Exceptions\ZipImportException;
use BookStack\Exceptions\ZipValidationException;
use BookStack\Exports\ImportRepo;
use BookStack\Http\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());
}
]);
}
+ /**
+ * Run the import process against an uploaded import ZIP.
+ */
public function run(int $id, Request $request)
{
- // TODO - Test access/visibility
$import = $this->imports->findVisible($id);
$parent = null;
- if ($import->getType() === 'page' || $import->getType() === 'chapter') {
+ if ($import->type === 'page' || $import->type === 'chapter') {
+ session()->setPreviousUrl($import->getUrl());
$data = $this->validate($request, [
- 'parent' => ['required', 'string']
+ 'parent' => ['required', 'string'],
]);
$parent = $data['parent'];
}
- // TODO - Run import
- // TODO - Validate again before
- // TODO - Check permissions before (create for main item, create for children, create for related items [image, attachments])
- // TODO - Redirect to result
- // TODO - Or redirect back with errors
+ 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());
}
/**
$import = $this->imports->findVisible($id);
$this->imports->deleteImport($import);
- $this->logActivity(ActivityType::IMPORT_DELETE, $import);
-
return redirect('/import');
}
}