From 5a279ffbe5e83339709cc103620d220aaa02d34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20R?= Date: Mon, 23 Dec 2019 14:36:22 +0100 Subject: [PATCH 1/2] Port fix for EZP-29958 & EZP-29984 from kernel Ports over fixes for: - EZP-29984: Fix LIKE support for * as wildcard across engines, deprecate % usage - https://github.com/ezsystems/ezpublish-kernel/pull/2517 Which also happens to align RichText with how XmlText had been fixed for: - "Creating paragraph longer than 32766 bytes in RichText Editor will fail with Solr Error" - https://jira.ez.no/browse/EZP-29958 --- src/lib/eZ/FieldType/RichText/SearchField.php | 12 +++++++++--- src/lib/eZ/FieldType/RichText/Type.php | 6 +++--- .../Legacy/RichTextFieldValueConverter.php | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib/eZ/FieldType/RichText/SearchField.php b/src/lib/eZ/FieldType/RichText/SearchField.php index dfbf3dab..a6ef8084 100644 --- a/src/lib/eZ/FieldType/RichText/SearchField.php +++ b/src/lib/eZ/FieldType/RichText/SearchField.php @@ -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( @@ -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) { $result = null; + // try to extract first paragraph/tag if ($section = $document->documentElement->firstChild) { $textDom = $section->firstChild; @@ -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)); } /** diff --git a/src/lib/eZ/FieldType/RichText/Type.php b/src/lib/eZ/FieldType/RichText/Type.php index 94782c9d..787b7647 100644 --- a/src/lib/eZ/FieldType/RichText/Type.php +++ b/src/lib/eZ/FieldType/RichText/Type.php @@ -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); } /** diff --git a/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php b/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php index 57622964..0fe78ea5 100644 --- a/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php +++ b/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php @@ -40,6 +40,7 @@ public static function create() public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) { $storageFieldValue->dataText = $value->data; + $storageFieldValue->sortKeyString = $value->sortKey; } /** @@ -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; } /** @@ -86,6 +88,6 @@ public function toFieldDefinition(StorageFieldDefinition $storageDefinition, Fie */ public function getIndexColumn() { - return false; + return 'sort_key_string'; } } From 2161559527b87ec3b77b33585122e79ba99f0e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R?= Date: Wed, 8 Jan 2020 17:06:36 +0100 Subject: [PATCH 2/2] Update src/lib/eZ/FieldType/RichText/SearchField.php Co-Authored-By: Andrew Longosz --- src/lib/eZ/FieldType/RichText/SearchField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/eZ/FieldType/RichText/SearchField.php b/src/lib/eZ/FieldType/RichText/SearchField.php index a6ef8084..7e814744 100644 --- a/src/lib/eZ/FieldType/RichText/SearchField.php +++ b/src/lib/eZ/FieldType/RichText/SearchField.php @@ -78,7 +78,7 @@ private function extractText(DOMNode $node) * * @return string */ - public static function extractShortText(DOMDocument $document) + public static function extractShortText(DOMDocument $document): string { $result = null; // try to extract first paragraph/tag