mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-25 20:17:57 +08:00

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.1) (push) Waiting to run
test-php / build (8.2) (push) Waiting to run
test-php / build (8.3) (push) Waiting to run
Split attachment service storage work out so it can be shared.
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Exports;
|
|
|
|
use BookStack\Exceptions\ZipValidationException;
|
|
use BookStack\Exports\ZipExports\ZipExportReader;
|
|
use BookStack\Exports\ZipExports\ZipExportValidator;
|
|
use BookStack\Uploads\FileStorage;
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
|
|
class ImportRepo
|
|
{
|
|
public function __construct(
|
|
protected FileStorage $storage,
|
|
) {
|
|
}
|
|
|
|
public function storeFromUpload(UploadedFile $file): Import
|
|
{
|
|
$zipPath = $file->getRealPath();
|
|
|
|
$errors = (new ZipExportValidator($zipPath))->validate();
|
|
if ($errors) {
|
|
throw new ZipValidationException($errors);
|
|
}
|
|
|
|
$zipEntityInfo = (new ZipExportReader($zipPath))->getEntityInfo();
|
|
$import = new Import();
|
|
$import->name = $zipEntityInfo['name'];
|
|
$import->book_count = $zipEntityInfo['book_count'];
|
|
$import->chapter_count = $zipEntityInfo['chapter_count'];
|
|
$import->page_count = $zipEntityInfo['page_count'];
|
|
$import->created_by = user()->id;
|
|
$import->size = filesize($zipPath);
|
|
|
|
$path = $this->storage->uploadFile(
|
|
$file,
|
|
'uploads/files/imports/',
|
|
'',
|
|
'zip'
|
|
);
|
|
|
|
$import->path = $path;
|
|
$import->save();
|
|
|
|
return $import;
|
|
}
|
|
}
|