sulu / SuluArticleBundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system
MIT License
52 stars 77 forks source link

ArticleIndexer throws error when property value is null #597

Open ymc-sise opened 2 years ago

ymc-sise commented 2 years ago
Q A
Bug? maybe
New Feature? no
SuluArticleBundle Version
Sulu Version 2.3.6

Actual Behavior

When I remove a locale of an article programmatically, the ArticleIndexer will throw an error:

  at /var/www/sulu/vendor/sulu/article-bundle/Document/Index/ArticleIndexer.php:294
 Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer->getBlockContentFieldsRecursive() at /var/www/sulu/vendor/sulu/article-bundle/Document/Index/ArticleIndexer.php:279
 Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer->getContentFields() at /var/www/sulu/vendor/sulu/article-bundle/Document/Index/ArticleIndexer.php:245
 Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer->createOrUpdateArticle() at /var/www/sulu/vendor/sulu/article-bundle/Document/Index/ArticleIndexer.php:440
 Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer->removeLocale() at /var/www/sulu/vendor/sulu/article-bundle/Document/Subscriber/ArticleSubscriber.php:471
 Sulu\Bundle\ArticleBundle\Document\Subscriber\ArticleSubscriber->handleRemoveLocale() at /var/www/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php:230
 Symfony\Component\EventDispatcher\EventDispatcher->callListeners() at /var/www/sulu/vendor/symfony/event-dispatcher/EventDispatcher.php:59
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /var/www/sulu/vendor/sulu/sulu/src/Sulu/Component/DocumentManager/DocumentManager.php:70
 Sulu\Component\DocumentManager\DocumentManager->removeLocale() at 

Expected Behavior

removeLocale will run as expected

Steps to Reproduce

The behaviour is strange and difficult to explain. For a particular article, I can't remove the locale because of this error.

It happens in $contentFields = array_merge($contentFields, $this->getBlockContentFieldsRecursive($blocks, $document, $property, $tag)); of getContentFields() in Document/Index/ArticleIndexer.php

$blocks is null and it will throw an error, but it in my opinion $blocks should be [].

The block property which gives a null value does not appear in the according XML content in the phpcr_nodes table. What could be the problem here? Its confusing, because If I add a new article without setting this block property (and the property does not appear in the XML content as well), the locale can be removed without any error.

Possible Solutions

Maybe add an if in getContentFields()-Method?

               if ($blocks === null) {
                    $blocks = [];
                }

If I add the if block, the locale can be removed without any error.