]> BookStack Code Mirror - bookstack/commitdiff
ZIP Imports: Added book content ordering to import preview
authorDan Brown <redacted>
Fri, 22 Nov 2024 21:03:04 +0000 (21:03 +0000)
committerDan Brown <redacted>
Fri, 22 Nov 2024 21:03:04 +0000 (21:03 +0000)
app/Exports/ZipExports/Models/ZipExportBook.php
app/Exports/ZipExports/Models/ZipExportChapter.php
app/Exports/ZipExports/Models/ZipExportPage.php
app/Exports/ZipExports/ZipExportReader.php
resources/views/exports/parts/import-item.blade.php

index 47ab8f0a699ce82f58fee261443eeae9b07e45ee..4f641d25bd71cd05025b4c95f5d90944ba3123b4 100644 (file)
@@ -36,6 +36,20 @@ class ZipExportBook extends ZipExportModel
         }
     }
 
+    public function children(): array
+    {
+        $children = [
+            ...$this->pages,
+            ...$this->chapters,
+        ];
+
+        usort($children, function ($a, $b) {
+            return ($a->priority ?? 0) - ($b->priority ?? 0);
+        });
+
+        return $children;
+    }
+
     public static function fromModel(Book $model, ZipExportFiles $files): self
     {
         $instance = new self();
index 5a5fe350f3a06c5d3519f79c30591e59434e1132..bf2dc78f8de7bf37eb941b11824196aec76978fe 100644 (file)
@@ -20,7 +20,7 @@ class ZipExportChapter extends ZipExportModel
 
     public function metadataOnly(): void
     {
-        $this->description_html = $this->priority = null;
+        $this->description_html = null;
 
         foreach ($this->pages as $page) {
             $page->metadataOnly();
@@ -30,6 +30,11 @@ class ZipExportChapter extends ZipExportModel
         }
     }
 
+    public function children(): array
+    {
+        return $this->pages;
+    }
+
     public static function fromModel(Chapter $model, ZipExportFiles $files): self
     {
         $instance = new self();
index 16e7e925539eb90678a60a260c9f9b84c621d7e4..097443df02bce73ec7a54c65112c1455faccfa31 100644 (file)
@@ -23,7 +23,7 @@ class ZipExportPage extends ZipExportModel
 
     public function metadataOnly(): void
     {
-        $this->html = $this->markdown = $this->priority = null;
+        $this->html = $this->markdown = null;
 
         foreach ($this->attachments as $attachment) {
             $attachment->metadataOnly();
index 6b88ef61c33f45fbe966bae68c3d95dde274e1af..c3d5c23cfec73559e29b13da9023b1e7659791a2 100644 (file)
@@ -5,7 +5,6 @@ namespace BookStack\Exports\ZipExports;
 use BookStack\Exceptions\ZipExportException;
 use BookStack\Exports\ZipExports\Models\ZipExportBook;
 use BookStack\Exports\ZipExports\Models\ZipExportChapter;
-use BookStack\Exports\ZipExports\Models\ZipExportModel;
 use BookStack\Exports\ZipExports\Models\ZipExportPage;
 use BookStack\Util\WebSafeMimeSniffer;
 use ZipArchive;
index 811a3b31bda8f1ec303705af43027e9b0345c073..5da4b21405d002813fba185758405a4a988dae93 100644 (file)
@@ -16,11 +16,13 @@ $model - object
                 <span>@icon('tag'){{ count($model->tags) }}</span>
             @endif
         </div>
-        @foreach($model->chapters ?? [] as $chapter)
-            @include('exports.parts.import-item', ['type' => 'chapter', 'model' => $chapter])
-        @endforeach
-        @foreach($model->pages ?? [] as $page)
-            @include('exports.parts.import-item', ['type' => 'page', 'model' => $page])
-        @endforeach
+        @if(method_exists($model, 'children'))
+            @foreach($model->children() as $child)
+                @include('exports.parts.import-item', [
+                    'type' => ($child instanceof \BookStack\Exports\ZipExports\Models\ZipExportPage) ? 'page' : 'chapter',
+                    'model' => $child
+                ])
+            @endforeach
+        @endif
     </div>
 </div>
\ No newline at end of file