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:
@@ -17,17 +17,17 @@ use BookStack\Uploads\Image;
|
||||
|
||||
class ZipExportReferences
|
||||
{
|
||||
/** @var ZipExportPage[] */
|
||||
/** @var array<int, ZipExportPage> */
|
||||
protected array $pages = [];
|
||||
/** @var ZipExportChapter[] */
|
||||
/** @var array<int, ZipExportChapter> */
|
||||
protected array $chapters = [];
|
||||
/** @var ZipExportBook[] */
|
||||
/** @var array<int, ZipExportBook> */
|
||||
protected array $books = [];
|
||||
|
||||
/** @var ZipExportAttachment[] */
|
||||
/** @var array<int, ZipExportAttachment> */
|
||||
protected array $attachments = [];
|
||||
|
||||
/** @var ZipExportImage[] */
|
||||
/** @var array<int, ZipExportImage> */
|
||||
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}]]";
|
||||
}
|
||||
|
Reference in New Issue
Block a user