Skip to content

Commit

Permalink
IBX-7579:Richtext: Rows are added to ezurl_object_link on every save
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Feb 13, 2024
1 parent 314fd1f commit e6f6d4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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
10 changes: 10 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,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);

Check failure on line 88 in src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php

View workflow job for this annotation

GitHub Actions / Tests (8.0)

Call to an undefined method eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway::getUrlsFromUrlLink().

Check failure on line 88 in src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php

View workflow job for this annotation

GitHub Actions / Tests (7.4)

Call to an undefined method eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway::getUrlsFromUrlLink().

Check failure on line 88 in src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php

View workflow job for this annotation

GitHub Actions / Tests (8.1)

Call to an undefined method eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway::getUrlsFromUrlLink().

Check failure on line 88 in src/lib/eZ/FieldType/RichText/RichTextStorage/Gateway.php

View workflow job for this annotation

GitHub Actions / Tests (7.3)

Call to an undefined method eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway::getUrlsFromUrlLink().
}

/**
* 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

0 comments on commit e6f6d4e

Please sign in to comment.