3 namespace BookStack\Exports;
5 use BookStack\Entities\Models\Page;
6 use BookStack\Exceptions\ZipExportException;
11 protected array $data = [];
14 * @throws ZipExportException
16 public function buildForPage(Page $page): string
18 $this->data['page'] = [
22 return $this->build();
26 * @throws ZipExportException
28 protected function build(): string
30 $this->data['exported_at'] = date(DATE_ATOM);
31 $this->data['instance'] = [
32 'version' => trim(file_get_contents(base_path('version'))),
33 'id_ciphertext' => encrypt('bookstack'),
36 $zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
37 $zip = new ZipArchive();
38 $opened = $zip->open($zipFile, ZipArchive::CREATE);
39 if ($opened !== true) {
40 throw new ZipExportException('Failed to create zip file for export.');
43 $zip->addFromString('data.json', json_encode($this->data));
44 $zip->addEmptyDir('files');