mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-15 07:33:36 +08:00
8f6f81948e
Some checks are pending
analyse-php / build (push) Waiting to run
lint-php / build (push) Waiting to run
test-migrations / build (8.1) (push) Waiting to run
test-migrations / build (8.2) (push) Waiting to run
test-migrations / build (8.3) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
test-php / build (8.1) (push) Waiting to run
100 lines
2.5 KiB
PHP
100 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BookStack\Exports\Controllers;
|
|
|
|
use BookStack\Activity\ActivityType;
|
|
use BookStack\Exceptions\ZipValidationException;
|
|
use BookStack\Exports\ImportRepo;
|
|
use BookStack\Http\Controller;
|
|
use BookStack\Uploads\AttachmentService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ImportController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ImportRepo $imports,
|
|
) {
|
|
$this->middleware('can:content-import');
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
$imports = $this->imports->getVisibleImports();
|
|
|
|
$this->setPageTitle(trans('entities.import'));
|
|
|
|
return view('exports.import', [
|
|
'imports' => $imports,
|
|
'zipErrors' => session()->pull('validation_errors') ?? [],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Upload, validate and store an import file.
|
|
*/
|
|
public function upload(Request $request)
|
|
{
|
|
$this->validate($request, [
|
|
'file' => ['required', ...AttachmentService::getFileValidationRules()]
|
|
]);
|
|
|
|
$file = $request->file('file');
|
|
try {
|
|
$import = $this->imports->storeFromUpload($file);
|
|
} catch (ZipValidationException $exception) {
|
|
session()->flash('validation_errors', $exception->errors);
|
|
return redirect('/import');
|
|
}
|
|
|
|
$this->logActivity(ActivityType::IMPORT_CREATE, $import);
|
|
|
|
return redirect($import->getUrl());
|
|
}
|
|
|
|
/**
|
|
* Show a pending import, with a form to allow progressing
|
|
* with the import process.
|
|
*/
|
|
public function show(int $id)
|
|
{
|
|
$import = $this->imports->findVisible($id);
|
|
|
|
$this->setPageTitle(trans('entities.import_continue'));
|
|
|
|
return view('exports.import-show', [
|
|
'import' => $import,
|
|
]);
|
|
}
|
|
|
|
public function run(int $id)
|
|
{
|
|
// TODO - Test access/visibility
|
|
|
|
$import = $this->imports->findVisible($id);
|
|
|
|
// TODO - Run import
|
|
// Validate again before
|
|
// TODO - Redirect to result
|
|
// TOOD - Or redirect back with errors
|
|
}
|
|
|
|
/**
|
|
* Delete an active pending import from the filesystem and database.
|
|
*/
|
|
public function delete(int $id)
|
|
{
|
|
$import = $this->imports->findVisible($id);
|
|
$this->imports->deleteImport($import);
|
|
|
|
$this->logActivity(ActivityType::IMPORT_DELETE, $import);
|
|
|
|
return redirect('/import');
|
|
}
|
|
}
|