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..c83b07f8 100644 --- a/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php +++ b/src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php @@ -78,6 +78,22 @@ public function insertUrl($url) return $this->urlGateway->insertUrl($url); } + /** + * Return a list of URLs used by the given field and version. + * + * array An array of URLs, with urls as keys + */ + public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array + { + $rows = $this->urlGateway->getUrlsFromUrlLink($fieldId, $versionNo); + $result = []; + foreach ($rows as $url) { + $result[$url] = true; + } + + return $result; + } + /** * 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(