1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

ZIP Exports: Finished up format doc, move files, started builder

Moved all existing export related app files into their new own dir.
This commit is contained in:
Dan Brown
2024-10-15 16:14:11 +01:00
parent 42bd07d733
commit 42b9700673
15 changed files with 118 additions and 53 deletions

View File

@@ -0,0 +1,7 @@
<?php
namespace BookStack\Exceptions;
class ZipExportException extends \Exception
{
}

View File

@@ -1,9 +1,9 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\BookQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\ApiController;
use Throwable;

View File

@@ -1,9 +1,9 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\BookQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\Controller;
use Throwable;

View File

@@ -1,9 +1,9 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\ChapterQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\ApiController;
use Throwable;

View File

@@ -1,10 +1,10 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\ChapterQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\Controller;
use Throwable;

View File

@@ -1,9 +1,9 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\PageQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\ApiController;
use Throwable;

View File

@@ -1,11 +1,11 @@
<?php
namespace BookStack\Entities\Controllers;
namespace BookStack\Exports\Controllers;
use BookStack\Entities\Queries\PageQueries;
use BookStack\Entities\Tools\ExportFormatter;
use BookStack\Entities\Tools\PageContent;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exports\ExportFormatter;
use BookStack\Http\Controller;
use Throwable;

View File

@@ -1,11 +1,13 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Exports;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\Markdown\HtmlToMarkdown;
use BookStack\Entities\Tools\PageContent;
use BookStack\Uploads\ImageService;
use BookStack\Util\CspService;
use BookStack\Util\HtmlDocument;

View File

@@ -1,10 +1,10 @@
<?php
namespace BookStack\Entities\Tools;
namespace BookStack\Exports;
use BookStack\Exceptions\PdfExportException;
use Knp\Snappy\Pdf as SnappyPdf;
use Dompdf\Dompdf;
use Knp\Snappy\Pdf as SnappyPdf;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;

View File

@@ -0,0 +1,48 @@
<?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;
}
}