mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-23 18:06:32 +08:00
42b9700673
Some checks failed
test-migrations / build (8.3) (push) Has been cancelled
analyse-php / build (push) Has been cancelled
lint-js / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-js / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
Moved all existing export related app files into their new own dir.
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Exports;
|
|
|
|
use BookStack\Entities\Models\Page;
|
|
use BookStack\Exceptions\ZipExportException;
|
|
use ZipArchive;
|
|
|
|
class ZipExportBuilder
|
|
{
|
|
protected array $data = [];
|
|
|
|
/**
|
|
* @throws ZipExportException
|
|
*/
|
|
public function buildForPage(Page $page): string
|
|
{
|
|
$this->data['page'] = [
|
|
'id' => $page->id,
|
|
];
|
|
|
|
return $this->build();
|
|
}
|
|
|
|
/**
|
|
* @throws ZipExportException
|
|
*/
|
|
protected function build(): string
|
|
{
|
|
$this->data['exported_at'] = date(DATE_ATOM);
|
|
$this->data['instance'] = [
|
|
'version' => trim(file_get_contents(base_path('version'))),
|
|
'id_ciphertext' => encrypt('bookstack'),
|
|
];
|
|
|
|
$zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
|
|
$zip = new ZipArchive();
|
|
$opened = $zip->open($zipFile, ZipArchive::CREATE);
|
|
if ($opened !== true) {
|
|
throw new ZipExportException('Failed to create zip file for export.');
|
|
}
|
|
|
|
$zip->addFromString('data.json', json_encode($this->data));
|
|
$zip->addEmptyDir('files');
|
|
|
|
return $zipFile;
|
|
}
|
|
}
|