verbb / vizy

A flexible visual editor for Craft CMS
Other
43 stars 8 forks source link

Vizy Failing to Create Search Indexes #302

Open danielsiemers opened 5 days ago

danielsiemers commented 5 days ago

Describe the bug

We are having issues with search indexes being updated for entries that contain Vizy fields, making it hard to search for specific keywords around the site.

We have created a Vizy field and checked "Use this field’s values as search keywords".

We are however getting issues now when saving this field. We are having issues in 2 ways.

  1. When we save an entry that contains this field, the queue runs the "Creating search indexes" job. This job fails with the below errors:

error: Array to string conversion

2024-06-26 08:58:47 [console.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Array to string conversion in /var/www/html/vendor/verbb/vizy/src/fields/VizyField.php:734 Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'Array to string...', '/var/www/html/v...', 734)
#1 /var/www/html/vendor/verbb/vizy/src/fields/VizyField.php(734): array_unique(Array)
#2 /var/www/html/vendor/craftcms/cms/src/base/Field.php(583): verbb\vizy\fields\VizyField->searchKeywords(Object(verbb\vizy\models\NodeCollection), Object(craft\elements\Entry))
#3 /var/www/html/vendor/craftcms/cms/src/services/Search.php(189): craft\base\Field->getSearchKeywords(Object(verbb\vizy\models\NodeCollection), Object(craft\elements\Entry))
#4 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(3535): craft\services\Search->indexElementAttributes(Object(craft\elements\Entry), Array)
#5 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1395): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, true, Array, false)
#6 /var/www/html/vendor/craftcms/cms/src/console/controllers/ResaveController.php(642): craft\services\Elements->resaveElements(Object(craft\elements\db\EntryQuery), true, true, true, false)
#7 /var/www/html/vendor/craftcms/cms/src/console/controllers/ResaveController.php(472): craft\console\controllers\ResaveController->_resaveElements(Object(craft\elements\db\EntryQuery))
#8 /var/www/html/vendor/craftcms/cms/src/console/controllers/ResaveController.php(388): craft\console\controllers\ResaveController->resaveElements('craft\\elements\\...', Array)
#9 [internal function]: craft\console\controllers\ResaveController->actionEntries()
#10 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('entries', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\console\Controller->runAction('entries', Array) #14 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('entries', Array) #15 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('entries', Array) #16 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('resave/entries', Array) #17 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('resave/entries', Array)
#18 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('resave/entries', Array)
#19 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#20 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#21 /var/www/html/craft(13): yii\base\Application->run() #22 {main} {"memory":42040568,"exception":"[object] (yii\\base\\ErrorException(code: 2): Array to string conversion at /var/www/html/vendor/verbb/vizy/src/fields/VizyField.php:734)"}
  1. When you run the command php craft resave/entries --update-search-index a large number of pages returns this same error.

Steps to reproduce

  1. Create a vizy field and enable "Use this field’s values as search keywords"
  2. Create an entry that uses this field
  3. Add some content
  4. Add a nested block (e.g. a form) and fill out the content - attaching other entries (e.g. "Add a form")
  5. Save the entry and the queue job for "Creating search indexes" should fail with the above error
  6. Run the command php craft resave/entries --update-search-index and you should see a red error when trying to save this entry.

Craft CMS version

4.10.2

Plugin version

2.1.19

Multi-site?

Yes

Additional context

It seems to be related to Vizy fields that have nested blocks within them. When these blocks are removed rerunning the --update-search-index command works fine and there are no errors.

engram-design commented 5 days ago

This is a little tricky to debug without knowing what your content structure looks like.

Can you comment on what your Vizy field setup looks like? And in particular, what the content side of things looks like for an entry you're trying to save? I have been testing a few different Vizy setups, including nested Vizy fields. A screenshot or two would be amazing.

danielsiemers commented 11 hours ago

Thanks for coming back so quickly.

Attached is a screenshot of some example content in Vizy fields causing this issue. I've also included the Yaml for the field structure.

Additionally, plugins that we are using for the fields in here include Hyper, Formie and nested Vizy blocks. They are all running the latest Craft 4 versions

Please let me know if you think any other info might be helpful here, thanks!

Screenshot of Vizy Fields ![pages_82552-test-entry_site=default](https://github.com/verbb/vizy/assets/49675893/c444a463-5807-46d5-ba72-3227a8329fbc)
Field Structure Yaml ``` columnSuffix: putdlvfc contentColumnType: text fieldGroup: 922c5bee-8245-41f9-b671-f034ad9cc672 # Common handle: body instructions: null name: Body searchable: true settings: availableTransforms: '' availableVolumes: - 233d88d4-cb54-479b-97bb-4418f0d427ce # Assets blockTypeBehaviour: click columnType: text configSelectionMode: choose defaultTransform: '' defaultUploadLocationSource: 'volume:233d88d4-cb54-479b-97bb-4418f0d427ce' # Assets editorMode: combined fieldData: - __assoc__: - - id - group-IAWmP7xRJ6 - - name - BLOCKS - - blockTypes - - __assoc__: 0: - id - type-cqG4WO2tkP 1: - name - 'Button Group' 2: - handle - buttonGroup 3: - icon - __assoc__: - - label - Link - - value - link-solid 5: - enabled - true 6: - layoutUid - 25fdd2a9-af45-4977-83e9-879f9500b1c0 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - 1e22996f-8571-4eab-beee-0bed50a28fe0 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, f93a97e0-4056-48d4-9c3d-71eed0a2e17a] 10: [fieldUid, ce339ad8-a285-47a5-ae55-4ac8bff87d49] # Buttons - __assoc__: 0: - id - type-GP9Qmgphy6 1: - name - 'Accordion Item' 2: - handle - accordionItem 3: - icon - __assoc__: - - label - 'Caret Square Down' - - value - caret-square-down-solid 5: - enabled - true 6: - layoutUid - aef63b81-ce68-4bc6-898f-f2e2167dda65 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - 3547f1d3-6729-47f0-afb1-afdcdd4c5c96 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, 9a3ee2e4-b926-43fd-ba0c-5d97f1bddfca] 10: [fieldUid, d9faa01d-c4a9-49cc-b559-d2941ef891b9] # Heading - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, 862eca91-1b48-40f2-98dd-27d075b44f5c] 10: [fieldUid, 0bfa6b54-242e-450b-a46c-55f9c849b8ac] # Text - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, b6decf31-ae78-4420-b3e6-d70a394a3a16] 10: [fieldUid, 5ce15010-0605-47c8-a42e-eaeeeab21a89] # Image - __assoc__: 0: - id - type-FXFRYEOMLn 1: - name - Form 2: - handle - form 3: - icon - __assoc__: - - label - Envelope - - value - envelope-solid 5: - enabled - true 6: - layoutUid - 7d31453e-c198-4ea5-b82f-6a30c2ce3a5d 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - ecf6c9d5-5ece-43ed-9bac-3584c1978c8f 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, b49d80ec-4177-46fa-8174-2fdf669349f8] 10: [fieldUid, d9faa01d-c4a9-49cc-b559-d2941ef891b9] # Heading - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, 0a47922a-af44-4903-9921-1e02982c2191] 10: [fieldUid, 0bfa6b54-242e-450b-a46c-55f9c849b8ac] # Text - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, db467974-924c-44e7-bfdc-4b89d94c0820] 10: [fieldUid, cd178812-576c-49d3-826e-01903ff78d69] # Form - __assoc__: - - id - group-xJ6n0SAGR3 - - name - Cards - - blockTypes - - __assoc__: 0: - id - type-RlJrJG6Uh9 1: - name - 'Event Card' 2: - handle - eventCard 3: - icon - __assoc__: - - label - Calendar - - value - calendar-solid 5: - enabled - true 6: - layoutUid - cbbec5b8-e844-47c4-9bdc-f3a2274b4385 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - 18cec386-5fbf-44c8-a59d-d03c28bc5c06 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, df921802-1a81-4770-9128-b50c6bb69dcf] 10: [fieldUid, dcadae70-94e9-4623-b336-10dee7884ed3] # Event - __assoc__: 0: - id - type-79VGi13cGe 1: - name - 'Horizontal Card' 2: - handle - horizontalCard 3: - icon - __assoc__: - - label - 'Address Card' - - value - address-card-solid 5: - enabled - true 6: - layoutUid - ca86b7f0-ed1e-44ec-9f18-5843e30b41e4 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - 02f4bc05-2046-4c3d-957a-a25a3e1b72ea 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 50] 7: [uid, 1b925e93-eab4-4000-bbda-d2b271f9ed0e] 10: [fieldUid, d9faa01d-c4a9-49cc-b559-d2941ef891b9] # Heading - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 50] 7: [uid, 84b5f59a-3724-4dda-ad39-3c25537d54d0] 10: [fieldUid, 0bfc9d1f-87ce-4919-ab79-98e477ad0f59] # Subheading - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, 8de8367f-cc90-488d-b520-a09420996e8d] 10: [fieldUid, 5ce15010-0605-47c8-a42e-eaeeeab21a89] # Image - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, 8b05e685-30f4-45bf-bae3-dc9d46f86ec6] 10: [fieldUid, 0bfa6b54-242e-450b-a46c-55f9c849b8ac] # Text - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, 635c24ce-6ff1-45a8-b9aa-2096919e52cf] 10: [fieldUid, cc76e7e6-e26d-47cd-adf9-db2595fe12fb] # Button - __assoc__: 0: - id - type-E0wZ1nficH 1: - name - 'Quote Card' 2: - handle - quoteCard 3: - icon - __assoc__: - - label - quote-right - - value - quote-right-solid 5: - enabled - true 6: - layoutUid - 7ecd2165-7d78-440f-8a21-910a0abace9b 7: - layoutConfig - __assoc__: - - tabs - - __assoc__: 0: - name - Content 1: - uid - 3e902ef0-b47f-4dd6-91d4-4dce47c446d6 4: - elements - - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, false] 6: [width, 100] 7: [uid, c2298078-306b-4f54-a056-a364f9ae69da] 10: [fieldUid, 5ce15010-0605-47c8-a42e-eaeeeab21a89] # Image - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, 37ab941e-b2f2-481e-a3fe-bb29af3f1882] 10: [fieldUid, 0bfa6b54-242e-450b-a46c-55f9c849b8ac] # Text - __assoc__: 0: [type, craft\fieldlayoutelements\CustomField] 5: [required, true] 6: [width, 100] 7: [uid, 9d8d0c26-2031-4852-bd09-11b6297b1f52] 10: [fieldUid, 0e11caaf-caf9-45ae-b29d-420c93b46ebb] # Full Name initialRows: 7 manualConfig: '' maxBlocks: null minBlocks: null pasteAsPlainText: false showUnpermittedFiles: false showUnpermittedVolumes: false trimEmptyParagraphs: true vizyConfig: Body.json translationKeyFormat: null translationMethod: site type: verbb\vizy\fields\VizyField ```