From e6f6d4e37d569ed1fc69bf5942761ef497a647f1 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Tue, 13 Feb 2024 12:09:22 +0100 Subject: [PATCH] IBX-7579:Richtext: Rows are added to ezurl_object_link on every save --- src/lib/eZ/FieldType/RichText/RichTextStorage.php | 5 ++++- .../FieldType/RichText/RichTextStorage/Gateway.php | 10 ++++++++++ .../eZ/FieldType/RichText/RichTextStorageTest.php | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/lib/eZ/FieldType/RichText/RichTextStorage.php b/src/lib/eZ/FieldType/RichText/RichTextStorage.php index e59029ad..2286c519 100644 --- a/src/lib/eZ/FieldType/RichText/RichTextStorage.php +++ b/src/lib/eZ/FieldType/RichText/RichTextStorage.php @@ -83,7 +83,10 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co $urlIdMap = $this->gateway->getUrlIdMap(array_keys($urlSet)); $contentIds = $this->gateway->getContentIds(array_keys($remoteIdSet)); - $urlLinkSet = []; + $urlLinkSet = $this->gateway->getUrlsFromUrlLink( + $field->id, + $versionInfo->versionNo + ); foreach ($links as $index => $link) { list(, $scheme, $url, $fragment) = $linksInfo[$index]; diff --git a/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php b/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php index 2a3e8dd3..03f3415c 100644 --- a/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php +++ b/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php @@ -78,6 +78,16 @@ public function insertUrl($url) return $this->urlGateway->insertUrl($url); } + /** + * Return a list of URLs used by the given field and version. + * + * @return bool[] An array of URLs, with urls as keys + */ + public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array + { + return $this->urlGateway->getUrlsFromUrlLink($fieldId, $versionNo); + } + /** * Creates link to URL with $urlId for field with $fieldId in $versionNo. * diff --git a/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php b/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php index 4c9cd1e9..c8b4417c 100644 --- a/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php +++ b/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php @@ -325,6 +325,13 @@ public function testStoreFieldDataThrowsNotFoundException( ->method('getContentIds') ->with($this->equalTo($remoteIds)) ->willReturn($contentIds); + + $gateway + ->expects($this->once()) + ->method('getUrlsFromUrlLink') + ->with($this->equalTo(42), $this->equalTo(1)) + ->willReturn([]); + $gateway->expects($this->never())->method('getIdUrlMap'); if (empty($insertLinks)) { $gateway->expects($this->never())->method('insertUrl'); @@ -338,9 +345,12 @@ public function testStoreFieldDataThrowsNotFoundException( ->willReturn($linkMap['id']); } - $versionInfo = new VersionInfo(); + $versionInfo = new VersionInfo(['versionNo' => 1]); $value = new FieldValue(['data' => $xmlString]); - $field = new Field(['value' => $value]); + $field = new Field([ + 'value' => $value, + 'id' => 42, + ]); $storage = $this->getPartlyMockedStorage($gateway); $storage->storeFieldData(