verbb / vizy

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

Importing empty values into a Vizy field with Feed Me throws an Error #189

Closed yoannisj closed 4 months ago

yoannisj commented 1 year ago

Describe the bug

I am trying to import data from a legacy Wordpress website into Craft-CMS using Feed-Me, and mapping a rich-text field from Wordpress to a Vizy field in Craft-CMS. The expectation is that the rich-text is imported as a text into the Vizy field.

This works great for posts/entries where the rich-text field is not empty (i.e the XML node for the field in the Feed-Me feed is not empty). However, for posts/entries where the field is empty most part of the content is missing after the import and I can see the Trying to access array offset on value of type null error in Craft's log files:

2022-12-02 23:23:25 [queue.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Trying to access array offset on value of type null in /var/www/html/vendor/verbb/vizy/src/integrations/feedme/fields/Vizy.php:59
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Trying to acces...', '/var/www/html/v...', 59)
#1 /var/www/html/vendor/verbb/vizy/src/integrations/feedme/fields/Vizy.php(59): craft\web\ErrorHandler->handleError(2, 'Trying to acces...', '/var/www/html/v...', 59)
#2 /var/www/html/vendor/craftcms/feed-me/src/services/Fields.php(216): verbb\vizy\integrations\feedme\fields\Vizy->parseField()
#3 /var/www/html/vendor/craftcms/feed-me/src/services/Process.php(392): 

Steps to reproduce

  1. Create a Vizy field with handle richContent (no need to setup block types)
  2. Create a Test Entries section with a Test Entry type using the Vizy field created in step 1
  3. Create a Feed-Me feed with the following settings:
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <post>
    <slug>test-post-with-content</slug>
    <title>Test Post With Content</title>
    <content><![CDATA[Donec id elit non mi porta gravida at eget metus.]]></content>
  </post>
  <post>
    <slug>test-post-without-content</slug>
    <title>Test Post Without Content</title>
    <content><![CDATA[]]></content>
  </post>
</data>

You should now see the successfully imported "Test Post With Content" entry in the Test Section, with its "Rich Content" field properly populated. The "Test Post Without Content" should be missing due to the bug reported here.

If you open the storage/logs/queue-<date>.log file you should see a line with the Trying to access array offset on value of type null error message.

Craft CMS version

4.3.4

Plugin version

2.0.9

Multi-site?

No

Additional context

yoannisj commented 5 months ago

@engram-design thanks for merging the proposed solution! Unfortunately, me and my colleagues just bumped into what seems to be a related error with the latest version of Vizy, when importing empty feed nodes into a Vizy field.

2024-02-08 08:00:25 [queue.ERROR] [TypeError] TypeError: Tiptap\Core\DOMParser::getDocumentBody(): Return value must be of type DOMElement, null returned in /var/www/html/vendor/ueberdosis/tiptap-php/src/Core/DOMParser.php:66
Stack trace:
#0 /var/www/html/vendor/ueberdosis/tiptap-php/src/Core/DOMParser.php(28): Tiptap\Core\DOMParser->getDocumentBody()
#1 /var/www/html/vendor/ueberdosis/tiptap-php/src/Editor.php(46): Tiptap\Core\DOMParser->process(‘’)
#2 /var/www/html/vendor/ueberdosis/tiptap-php/src/Editor.php(36): Tiptap\Editor->setContent(‘’)
#3 /var/www/html/vendor/verbb/vizy/src/integrations/feedme/fields/Vizy.php(47): Tiptap\Editor->__construct(Array)
#4 /var/www/html/vendor/craftcms/feed-me/src/services/Fields.php(230): verbb\vizy\integrations\feedme\fields\Vizy->parseField()
...
engram-design commented 5 months ago

Can you post the XML you're using, if it's different from your original post? I'm testing with that, and things seem to be importing correctly for me.

I have just pushed up a potential fix for this regardless - if you can test it. To get this early, run composer require verbb/vizy:"dev-craft-4 as 2.1.15".

engram-design commented 4 months ago

Fixed in 2.1.16