1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-09-09 06:29:32 +03:00

ZIP Exports: Fixed reference handling for images

Recent changes could mean missed references for images in non-page
locations. This fixes that, and tries to ensure images are used if we
already have a page-based image as part of the ZIP, otherwise ensure we
have a page as part of the export to attach the image to.
This commit is contained in:
Dan Brown
2025-08-11 14:19:48 +01:00
parent 4830248a1e
commit a50a256939

View File

@@ -17,17 +17,17 @@ use BookStack\Uploads\Image;
class ZipExportReferences class ZipExportReferences
{ {
/** @var ZipExportPage[] */ /** @var array<int, ZipExportPage> */
protected array $pages = []; protected array $pages = [];
/** @var ZipExportChapter[] */ /** @var array<int, ZipExportChapter> */
protected array $chapters = []; protected array $chapters = [];
/** @var ZipExportBook[] */ /** @var array<int, ZipExportBook> */
protected array $books = []; protected array $books = [];
/** @var ZipExportAttachment[] */ /** @var array<int, ZipExportAttachment> */
protected array $attachments = []; protected array $attachments = [];
/** @var ZipExportImage[] */ /** @var array<int, ZipExportImage> */
protected array $images = []; protected array $images = [];
public function __construct( public function __construct(
@@ -134,11 +134,12 @@ class ZipExportReferences
// Find and include images if in visibility // Find and include images if in visibility
$page = $model->getPage(); $page = $model->getPage();
if ($page && userCan('view', $page) && $exportModel instanceof ZipExportPage) { $pageExportModel = $this->pages[$page->id] ?? ($exportModel instanceof ZipExportPage ? $exportModel : null);
if (isset($this->images[$model->id]) || ($page && $pageExportModel && userCan('view', $page))) {
if (!isset($this->images[$model->id])) { if (!isset($this->images[$model->id])) {
$exportImage = ZipExportImage::fromModel($model, $files); $exportImage = ZipExportImage::fromModel($model, $files);
$this->images[$model->id] = $exportImage; $this->images[$model->id] = $exportImage;
$exportModel->images[] = $exportImage; $pageExportModel->images[] = $exportImage;
} }
return "[[bsexport:image:{$model->id}]]"; return "[[bsexport:image:{$model->id}]]";
} }