Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/eZ/FieldType/RichText/RichTextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean> 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.
*
Expand Down
14 changes: 12 additions & 2 deletions tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(
Expand Down