Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a50a256

Browse files
committed
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.
1 parent 4830248 commit a50a256

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

app/Exports/ZipExports/ZipExportReferences.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717

1818
class ZipExportReferences
1919
{
20-
/** @var ZipExportPage[] */
20+
/** @var array<int, ZipExportPage> */
2121
protected array $pages = [];
22-
/** @var ZipExportChapter[] */
22+
/** @var array<int, ZipExportChapter> */
2323
protected array $chapters = [];
24-
/** @var ZipExportBook[] */
24+
/** @var array<int, ZipExportBook> */
2525
protected array $books = [];
2626

27-
/** @var ZipExportAttachment[] */
27+
/** @var array<int, ZipExportAttachment> */
2828
protected array $attachments = [];
2929

30-
/** @var ZipExportImage[] */
30+
/** @var array<int, ZipExportImage> */
3131
protected array $images = [];
3232

3333
public function __construct(
@@ -134,11 +134,12 @@ protected function handleModelReference(Model $model, ZipExportModel $exportMode
134134

135135
// Find and include images if in visibility
136136
$page = $model->getPage();
137-
if ($page && userCan('view', $page) && $exportModel instanceof ZipExportPage) {
137+
$pageExportModel = $this->pages[$page->id] ?? ($exportModel instanceof ZipExportPage ? $exportModel : null);
138+
if (isset($this->images[$model->id]) || ($page && $pageExportModel && userCan('view', $page))) {
138139
if (!isset($this->images[$model->id])) {
139140
$exportImage = ZipExportImage::fromModel($model, $files);
140141
$this->images[$model->id] = $exportImage;
141-
$exportModel->images[] = $exportImage;
142+
$pageExportModel->images[] = $exportImage;
142143
}
143144
return "[[bsexport:image:{$model->id}]]";
144145
}

0 commit comments

Comments
 (0)