From: Dan Brown Date: Mon, 11 Aug 2025 13:19:48 +0000 (+0100) Subject: ZIP Exports: Fixed reference handling for images X-Git-Tag: v25.07.1~1^2 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/HEAD 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. --- 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}]]"; }