NOW MANAGED ON CODEBERG
ZIP Import & Exports: Addressed issues during testing
Dan Brown9ecc91929a60
diff --git a/app/Exports/Controllers/ImportController.php b/app/Exports/Controllers/ImportController.phpindex a20c341fb..b938dac8e 100644--- a/app/Exports/Controllers/ImportController.php+++ b/app/Exports/Controllers/ImportController.php@@ -89,6 +89,8 @@ class ImportController extends Controllertry {$entity = $this->imports->runImport($import, $parent);} catch (ZipImportException $exception) {+ session()->flush();+ $this->showErrorNotification(trans('errors.import_zip_failed_notification'));return redirect($import->getUrl())->with('import_errors', $exception->errors);}diff --git a/app/Exports/ZipExports/ZipExportReferences.php b/app/Exports/ZipExports/ZipExportReferences.phpindex 0de409fa1..bf5e02133 100644--- a/app/Exports/ZipExports/ZipExportReferences.php+++ b/app/Exports/ZipExports/ZipExportReferences.php@@ -127,11 +127,12 @@ class ZipExportReferencesreturn null;}- // We don't expect images to be part of book/chapter content- if (!($exportModel instanceof ZipExportPage)) {- return null;+ // Handle simple links outside of page content+ if (!($exportModel instanceof ZipExportPage) && isset($this->images[$model->id])) {+ return "[[bsexport:image:{$model->id}]]";}+ // Find and include images if in visibility$page = $model->getPage();if ($page && userCan('view', $page)) {if (!isset($this->images[$model->id])) {diff --git a/lang/en/errors.php b/lang/en/errors.phpindex ced80a32c..9d7383796 100644--- a/lang/en/errors.php+++ b/lang/en/errors.php@@ -110,6 +110,7 @@ return ['import_zip_cant_decode_data' => 'Could not find and decode ZIP data.json content.','import_zip_no_data' => 'ZIP file data has no expected book, chapter or page content.','import_validation_failed' => 'Import ZIP failed to validate with errors:',+ 'import_zip_failed_notification' => 'Failed to import ZIP file.','import_perms_books' => 'You are lacking the required permissions to create books.','import_perms_chapters' => 'You are lacking the required permissions to create chapters.','import_perms_pages' => 'You are lacking the required permissions to create pages.',diff --git a/tests/Exports/ZipExportTest.php b/tests/Exports/ZipExportTest.phpindex 12531239f..6e8462f59 100644--- a/tests/Exports/ZipExportTest.php+++ b/tests/Exports/ZipExportTest.php@@ -274,6 +274,32 @@ class ZipExportTest extends TestCase$this->assertStringContainsString('href="[[bsexport:book:' . $book->id . ']]?view=true"', $pageData['html']);}+ public function test_book_and_chapter_description_links_to_images_in_pages_are_converted()+ {+ $book = $this->entities->bookHasChaptersAndPages();+ $chapter = $book->chapters()->first();+ $page = $chapter->pages()->first();++ $this->asEditor();+ $this->files->uploadGalleryImageToPage($this, $page);+ /** @var Image $image */+ $image = Image::query()->where('type', '=', 'gallery')+ ->where('uploaded_to', '=', $page->id)->first();++ $book->description_html = '<p><a href="' . $image->url . '">Link to image</a></p>';+ $book->save();+ $chapter->description_html = '<p><a href="' . $image->url . '">Link to image</a></p>';+ $chapter->save();++ $zipResp = $this->get($book->getUrl("/export/zip"));+ $zip = $this->extractZipResponse($zipResp);+ $bookData = $zip->data['book'];+ $chapterData = $bookData['chapters'][0];++ $this->assertStringContainsString('href="[[bsexport:image:' . $image->id . ']]"', $bookData['description_html']);+ $this->assertStringContainsString('href="[[bsexport:image:' . $image->id . ']]"', $chapterData['description_html']);+ }+public function test_cross_reference_links_external_to_export_are_not_converted(){$page = $this->entities->page();