Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported fix for EZP-29958 and EZP-29984 from kernel #95

Merged
merged 2 commits into from
Jan 14, 2020
Merged
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
12 changes: 9 additions & 3 deletions src/lib/eZ/FieldType/RichText/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
return [
new Search\Field(
'value',
$this->extractShortText($document),
self::extractShortText($document),
new Search\FieldType\StringField()
),
new Search\Field(
Expand Down Expand Up @@ -72,13 +72,16 @@ private function extractText(DOMNode $node)
/**
* Extracts short text content of the given $document.
*
* @internal Only for use by RichText FieldType itself.
*
* @param \DOMDocument $document
*
* @return string
*/
private function extractShortText(DOMDocument $document)
public static function extractShortText(DOMDocument $document): string
{
$result = null;
// try to extract first paragraph/tag
if ($section = $document->documentElement->firstChild) {
$textDom = $section->firstChild;

Expand All @@ -93,7 +96,10 @@ private function extractShortText(DOMDocument $document)
$result = $document->documentElement->textContent;
}

return trim($result);
// In case of newlines, extract first line. Also limit size to 255 which is maxsize on sql impl.
$lines = preg_split('/\r\n|\n|\r/', trim($result), -1, PREG_SPLIT_NO_EMPTY);

return empty($lines) ? '' : trim(mb_substr($lines[0], 0, 255));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/eZ/FieldType/RichText/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value)
}

/**
* Returns sortKey information.
* Returns information for FieldValue->$sortKey relevant to the field type.
*
* @see \eZ\Publish\Core\FieldType
*
* @param \EzSystems\EzPlatformRichText\eZ\FieldType\RichText\Value $value
*
* @return array|bool
* @return string|null
*/
protected function getSortInfo(BaseValue $value)
{
return false;
return SearchField::extractShortText($value->xml);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function create()
public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
{
$storageFieldValue->dataText = $value->data;
$storageFieldValue->sortKeyString = $value->sortKey;
}

/**
Expand All @@ -51,6 +52,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
{
$fieldValue->data = $value->dataText ?: Value::EMPTY_VALUE;
$fieldValue->sortKey = $value->sortKeyString;
}

/**
Expand Down Expand Up @@ -86,6 +88,6 @@ public function toFieldDefinition(StorageFieldDefinition $storageDefinition, Fie
*/
public function getIndexColumn()
{
return false;
return 'sort_key_string';
}
}