-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'portazips' into development
- Loading branch information
Showing
84 changed files
with
5,269 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace BookStack\Exceptions; | ||
|
||
class ZipExportException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace BookStack\Exceptions; | ||
|
||
class ZipImportException extends \Exception | ||
{ | ||
public function __construct( | ||
public array $errors | ||
) { | ||
$message = "Import failed with errors:" . implode("\n", $this->errors); | ||
parent::__construct($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace BookStack\Exceptions; | ||
|
||
class ZipValidationException extends \Exception | ||
{ | ||
public function __construct( | ||
public array $errors | ||
) { | ||
parent::__construct(); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...s/Controllers/BookExportApiController.php → ...s/Controllers/BookExportApiController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ontrollers/ChapterExportApiController.php → ...ontrollers/ChapterExportApiController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BookStack\Exports\Controllers; | ||
|
||
use BookStack\Exceptions\ZipImportException; | ||
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) { | ||
return redirect('/import')->with('validation_errors', $exception->errors); | ||
} | ||
|
||
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, | ||
'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) | ||
{ | ||
$import = $this->imports->findVisible($id); | ||
$this->imports->deleteImport($import); | ||
|
||
return redirect('/import'); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...s/Controllers/PageExportApiController.php → ...s/Controllers/PageExportApiController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
app/Entities/Tools/ExportFormatter.php → app/Exports/ExportFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.