Skip to content

Commit e6f6d4e

Browse files
committed
IBX-7579:Richtext: Rows are added to ezurl_object_link on every save
1 parent 314fd1f commit e6f6d4e

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/lib/eZ/FieldType/RichText/RichTextStorage.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co
8383

8484
$urlIdMap = $this->gateway->getUrlIdMap(array_keys($urlSet));
8585
$contentIds = $this->gateway->getContentIds(array_keys($remoteIdSet));
86-
$urlLinkSet = [];
86+
$urlLinkSet = $this->gateway->getUrlsFromUrlLink(
87+
$field->id,
88+
$versionInfo->versionNo
89+
);
8790

8891
foreach ($links as $index => $link) {
8992
list(, $scheme, $url, $fragment) = $linksInfo[$index];

src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function insertUrl($url)
7878
return $this->urlGateway->insertUrl($url);
7979
}
8080

81+
/**
82+
* Return a list of URLs used by the given field and version.
83+
*
84+
* @return bool[] An array of URLs, with urls as keys
85+
*/
86+
public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array
87+
{
88+
return $this->urlGateway->getUrlsFromUrlLink($fieldId, $versionNo);
89+
}
90+
8191
/**
8292
* Creates link to URL with $urlId for field with $fieldId in $versionNo.
8393
*

tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ public function testStoreFieldDataThrowsNotFoundException(
325325
->method('getContentIds')
326326
->with($this->equalTo($remoteIds))
327327
->willReturn($contentIds);
328+
329+
$gateway
330+
->expects($this->once())
331+
->method('getUrlsFromUrlLink')
332+
->with($this->equalTo(42), $this->equalTo(1))
333+
->willReturn([]);
334+
328335
$gateway->expects($this->never())->method('getIdUrlMap');
329336
if (empty($insertLinks)) {
330337
$gateway->expects($this->never())->method('insertUrl');
@@ -338,9 +345,12 @@ public function testStoreFieldDataThrowsNotFoundException(
338345
->willReturn($linkMap['id']);
339346
}
340347

341-
$versionInfo = new VersionInfo();
348+
$versionInfo = new VersionInfo(['versionNo' => 1]);
342349
$value = new FieldValue(['data' => $xmlString]);
343-
$field = new Field(['value' => $value]);
350+
$field = new Field([
351+
'value' => $value,
352+
'id' => 42,
353+
]);
344354

345355
$storage = $this->getPartlyMockedStorage($gateway);
346356
$storage->storeFieldData(

0 commit comments

Comments
 (0)