]> BookStack Code Mirror - bookstack/commitdiff
Input WYSIWYG: Updated reference link updating for descriptions
authorDan Brown <redacted>
Mon, 18 Dec 2023 18:12:36 +0000 (18:12 +0000)
committerDan Brown <redacted>
Mon, 18 Dec 2023 18:12:36 +0000 (18:12 +0000)
app/Entities/Models/BookChild.php
app/Entities/Repos/BaseRepo.php
app/Entities/Repos/PageRepo.php
app/References/ReferenceUpdater.php

index ed08f16e6ac9783be4581e87b33a1af651c5cffa..18735e56b72e74cdf08c7a774f0aadeae1bd7d4c 100644 (file)
@@ -65,7 +65,7 @@ abstract class BookChild extends Entity
         $this->refresh();
 
         if ($oldUrl !== $this->getUrl()) {
-            app()->make(ReferenceUpdater::class)->updateEntityPageReferences($this, $oldUrl);
+            app()->make(ReferenceUpdater::class)->updateEntityReferences($this, $oldUrl);
         }
 
         // Update all child pages if a chapter
index dbdaa921339b49595b5c8ca60dcc5a15f501c927..3d3d16732a6057b89b41084b9ba9f7502555c9f9 100644 (file)
@@ -74,7 +74,7 @@ class BaseRepo
         $this->referenceStore->updateForEntity($entity);
 
         if ($oldUrl !== $entity->getUrl()) {
-            $this->referenceUpdater->updateEntityPageReferences($entity, $oldUrl);
+            $this->referenceUpdater->updateEntityReferences($entity, $oldUrl);
         }
     }
 
index d491b7f2c571f96dee321985f6671245f1a726a0..7b14ea7d278c93b45bb0599251e8bbab6abfa337 100644 (file)
@@ -305,7 +305,7 @@ class PageRepo
         $this->revisionRepo->storeNewForPage($page, $summary);
 
         if ($oldUrl !== $page->getUrl()) {
-            $this->referenceUpdater->updateEntityPageReferences($page, $oldUrl);
+            $this->referenceUpdater->updateEntityReferences($page, $oldUrl);
         }
 
         Activity::add(ActivityType::PAGE_RESTORE, $page);
index db1bce4fbb8112eb62f02e410aebea7715c070f4..db355f211307d0381070a066cdfd40b7b50b4890 100644 (file)
@@ -4,6 +4,7 @@ namespace BookStack\References;
 
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Entity;
+use BookStack\Entities\Models\HasHtmlDescription;
 use BookStack\Entities\Models\Page;
 use BookStack\Entities\Repos\RevisionRepo;
 use BookStack\Util\HtmlDocument;
@@ -12,20 +13,19 @@ class ReferenceUpdater
 {
     public function __construct(
         protected ReferenceFetcher $referenceFetcher,
-        protected RevisionRepo $revisionRepo
+        protected RevisionRepo $revisionRepo,
     ) {
     }
 
-    public function updateEntityPageReferences(Entity $entity, string $oldLink)
+    public function updateEntityReferences(Entity $entity, string $oldLink): void
     {
         $references = $this->getReferencesToUpdate($entity);
         $newLink = $entity->getUrl();
 
-        /** @var Reference $reference */
         foreach ($references as $reference) {
-            /** @var Page $page */
-            $page = $reference->from;
-            $this->updateReferencesWithinPage($page, $oldLink, $newLink);
+            /** @var Entity $entity */
+            $entity = $reference->from;
+            $this->updateReferencesWithinEntity($entity, $oldLink, $newLink);
         }
     }
 
@@ -57,7 +57,28 @@ class ReferenceUpdater
         return array_values($deduped);
     }
 
-    protected function updateReferencesWithinPage(Page $page, string $oldLink, string $newLink)
+    protected function updateReferencesWithinEntity(Entity $entity, string $oldLink, string $newLink): void
+    {
+        if ($entity instanceof Page) {
+            $this->updateReferencesWithinPage($entity, $oldLink, $newLink);
+            return;
+        }
+
+        if (in_array(HasHtmlDescription::class, class_uses($entity))) {
+            $this->updateReferencesWithinDescription($entity, $oldLink, $newLink);
+        }
+    }
+
+    protected function updateReferencesWithinDescription(Entity $entity, string $oldLink, string $newLink): void
+    {
+        /** @var HasHtmlDescription&Entity $entity */
+        $entity = (clone $entity)->refresh();
+        $html = $this->updateLinksInHtml($entity->description_html ?: '', $oldLink, $newLink);
+        $entity->description_html = $html;
+        $entity->save();
+    }
+
+    protected function updateReferencesWithinPage(Page $page, string $oldLink, string $newLink): void
     {
         $page = (clone $page)->refresh();
         $html = $this->updateLinksInHtml($page->html, $oldLink, $newLink);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.