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->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) {
+ session()->flush();
+ $this->showErrorNotification(trans('errors.import_zip_failed_notification'));
+ 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());
}
/**
$import = $this->imports->findVisible($id);
$this->imports->deleteImport($import);
- $this->logActivity(ActivityType::IMPORT_DELETE, $import);
-
return redirect('/import');
}
}