From a50a256939ea6907f156859f4ba16c10c180cfae Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 11 Aug 2025 14:19:48 +0100 Subject: [PATCH] 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. --- app/Exports/ZipExports/ZipExportReferences.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Exports/ZipExports/ZipExportReferences.php b/app/Exports/ZipExports/ZipExportReferences.php index b9f356a6a..b21248ffd 100644 --- a/app/Exports/ZipExports/ZipExportReferences.php +++ b/app/Exports/ZipExports/ZipExportReferences.php @@ -17,17 +17,17 @@ use BookStack\Uploads\Image; class ZipExportReferences { - /** @var ZipExportPage[] */ + /** @var array */ protected array $pages = []; - /** @var ZipExportChapter[] */ + /** @var array */ protected array $chapters = []; - /** @var ZipExportBook[] */ + /** @var array */ protected array $books = []; - /** @var ZipExportAttachment[] */ + /** @var array */ protected array $attachments = []; - /** @var ZipExportImage[] */ + /** @var array */ protected array $images = []; public function __construct( @@ -134,11 +134,12 @@ class ZipExportReferences // Find and include images if in visibility $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])) { $exportImage = ZipExportImage::fromModel($model, $files); $this->images[$model->id] = $exportImage; - $exportModel->images[] = $exportImage; + $pageExportModel->images[] = $exportImage; } return "[[bsexport:image:{$model->id}]]"; }