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

ArticleViewDocument class cannot be parsed as document because @Document annotation is missing #563

Closed kfrohwein closed 2 years ago

kfrohwein commented 3 years ago

https://github.com/sulu/SuluArticleBundle/blob/c7016d09074f4b57ff7f2cf371f0d49d43b4db86/Document/ArticleViewDocument.php#L23

Uncaught PHP Exception ONGR\ElasticsearchBundle\Exception\MissingDocumentAnnotationException: "Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument" class cannot be parsed as document because @Document annotation is missing."

I am following your documentation at https://github.com/sulu/SuluArticleBundle/blob/2.x/Resources/doc/article-view-document.md to extend the index with some fields.

But then I get the error above. If I add an @ everything works fine again. Typo? Am I missing something?

niklasnatter commented 3 years ago

Hello, the annotation should be set by the AnnotationReader service that was implemented in #515. Can you debug if this service is called for you?

kfrohwein commented 3 years ago

image

It just won't stop inside of the if(). But you can see the articleViewDocumentClass is set to my AppBunle. The only real difference to the example is my namespace that has to begin with /App. Maybe that is the problem?

niklasnatter commented 3 years ago

It just won't stop inside of the if()

It should only execute that statements if you have not overridden the document, so this is alright in your case 🙂

The only real difference to the example is my namespace that has to begin with /App. Maybe that is the problem?

Yes, this could be a problem indeed. As stated in the documentation, the ElasticsearchBundle requires an AppBundle to overwrite document classes. Have you tried to change this?

What is the exact error that you are encountering? What is the stacktrace of the error? When does it happen?

kfrohwein commented 3 years ago

@nnatter Thank you for your support. The solution was that the namespace in the end has to be namespace App\Document; and then everything works again. So all in all I guess the documentation is not precise or faulty?

niklasnatter commented 3 years ago

I think you are right, I created a PR to adjust the documentation (#577). Thanks for reporting this!