zikula / core

Zikula Core Framework
GNU Lesser General Public License v3.0
238 stars 66 forks source link

[Categories] association mixed up #1956

Closed craigh closed 9 years ago

craigh commented 10 years ago

This might be an edge case. I hooked Dizkus to PC and got this.

Doctrine\ORM\ORMException: Found entity of type DoctrineProxyCG\Zikula_Doctrine2_Entity_Category on association Zikula\Module\CategoriesModule\Entity\CategoryAttributeEntity#category, but expecting Zikula\Module\CategoriesModule\Entity\CategoryEntity at n/a in /Applications/MAMP/htdocs/core.git/src/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 791

at Doctrine\ORM\UnitOfWork->computeAssociationChanges(array('fieldName' => 'category', 'id' => true, 'joinColumns' => array(array('name' => 'category_id', 'unique' => false, 'nullable' => true, 'onDelete' => null, 'columnDefinition' => null, 'referencedColumnName' => 'id')), 'cascade' => array(), 'inversedBy' => 'attributes', 'targetEntity' => 'Zikula\Module\CategoriesModule\Entity\CategoryEntity', 'fetch' => '2', 'type' => '2', 'mappedBy' => null, 'isOwningSide' => true, 'sourceEntity' => 'Zikula\Module\CategoriesModule\Entity\CategoryAttributeEntity', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false, 'sourceToTargetKeyColumns' => array('category_id' => 'id'), 'joinColumnFieldNames' => array('category_id' => 'category_id'), 'targetToSourceKeyColumns' => array('id' => 'category_id'), 'orphanRemoval' => false), object(Zikula_Doctrine2_Entity_Category)) in /Applications/MAMP/htdocs/core.git/src/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 687

at Doctrine\ORM\UnitOfWork->computeChangeSet(object(ClassMetadata), object(CategoryAttributeEntity)) in /Applications/MAMP/htdocs/core.git/src/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 748

at Doctrine\ORM\UnitOfWork->computeChangeSets() in /Applications/MAMP/htdocs/core.git/src/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 297

at Doctrine\ORM\UnitOfWork->commit(null) in /Applications/MAMP/htdocs/core.git/src/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 389

at Doctrine\ORM\EntityManager->flush() in /Applications/MAMP/htdocs/core.git/src/modules/zikula-dizkus/Zikula/Module/DizkusModule/Manager/TopicManager.php line 223

at Zikula\Module\DizkusModule\Manager\TopicManager->incrementViewsCount() in /Applications/MAMP/htdocs/core.git/src/modules/zikula-dizkus/Zikula/Module/DizkusModule/HookHandlers.php line 117

at Zikula\Module\DizkusModule\HookHandlers->uiView(object(Zikula_DisplayHook), 'postcalendar.ui_hooks.events.ui_view', object(TraceableEventDispatcher)) in line

at call_user_func(array(object(HookHandlers), 'uiView'), object(Zikula_DisplayHook), 'postcalendar.ui_hooks.events.ui_view', object(TraceableEventDispatcher)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 389

at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug{closure}(object(Zikula_DisplayHook), 'postcalendar.ui_hooks.events.ui_view', object(Zikula_EventManager)) in line

at call_user_func(object(Closure), object(Zikula_DisplayHook), 'postcalendar.ui_hooks.events.ui_view', object(Zikula_EventManager)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 164

at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure)), 'postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 53

at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php line 167

at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook), null) in /Applications/MAMP/htdocs/core.git/src/lib/legacy/Zikula/EventManager.php line 99

at Zikula_EventManager->dispatch('postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 138

at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch('postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook)) in /Applications/MAMP/htdocs/core.git/src/lib/legacy/Zikula/HookDispatcher.php line 103

at Zikula_HookDispatcher->dispatch('postcalendar.ui_hooks.events.ui_view', object(Zikula_DisplayHook)) in /Applications/MAMP/htdocs/core.git/src/lib/legacy/viewplugins/function.notifydisplayhooks.php line 56

at smarty_function_notifydisplayhooks(array('eventname' => 'postcalendar.ui_hooks.events.ui_view', 'id' => '3'), object(Zikula_View)) in /Applications/MAMP/htdocs/core.git/src/app/cache/dev/ztemp/view_compiled/PostCalendar/user/event--t_Zikula/Theme/ModernBusinessTheme-l_en.php line 37

at include('/Applications/MAMP/htdocs/core.git/src/app/cache/dev/ztemp/view_compiled/PostCalendar/user/event--t_Zikula/Theme/ModernBusinessTheme-l_en.php') in /Applications/MAMP/htdocs/core.git/src/lib/legacy/Zikula/View.php line 2960

at Zikula_View->_fetch('user/event.tpl', '3|2', '', false) in /Applications/MAMP/htdocs/core.git/src/lib/legacy/Zikula/View.php line 763

at Zikula_View->fetch('user/event.tpl') in /Applications/MAMP/htdocs/core.git/src/modules/PostCalendar/lib/PostCalendar/CalendarView/Event.php line 121

at PostCalendar_CalendarView_Event->render() in /Applications/MAMP/htdocs/core.git/src/modules/PostCalendar/lib/PostCalendar/Controller/User.php line 70

at PostCalendar_Controller_User->display(array()) in line

at call_user_func(array(object(PostCalendar_Controller_User), 'display'), array()) in /Applications/MAMP/htdocs/core.git/src/lib/util/ModUtil.php line 1153

at ModUtil::exec('PostCalendar', 'user', 'display', array(), false, null) in /Applications/MAMP/htdocs/core.git/src/lib/util/ModUtil.php line 1203

at ModUtil::func('PostCalendar', 'user', 'display') in /Applications/MAMP/htdocs/core.git/src/lib/Zikula/Bundle/CoreBundle/EventListener/LegacyRouteListener.php line 116

at Zikula\Bundle\CoreBundle\EventListener\LegacyRouteListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher)) in line

at call_user_func(array(object(LegacyRouteListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 389

at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug{closure}(object(GetResponseEvent), 'kernel.request', object(Zikula_EventManager)) in line

at call_user_func(object(Closure), object(GetResponseEvent), 'kernel.request', object(Zikula_EventManager)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 164

at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.request', object(GetResponseEvent)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 53

at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php line 167

at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', object(GetResponseEvent), null) in /Applications/MAMP/htdocs/core.git/src/lib/legacy/Zikula/EventManager.php line 99

at Zikula_EventManager->dispatch('kernel.request', object(GetResponseEvent)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 138

at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 107

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Zikula_Request_Http), '1') in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 66

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Zikula_Request_Http), '1', true) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 64

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Zikula_Request_Http), '1', true) in /Applications/MAMP/htdocs/core.git/src/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185

at Symfony\Component\HttpKernel\Kernel->handle(object(Zikula_Request_Http)) in /Applications/MAMP/htdocs/core.git/src/index.php line 21

Guite commented 10 years ago

Could this be caused by existing data (persisted in your database)?

Guite commented 10 years ago

I think the problem is that PostCalendar_Entity_EventCategory extends Zikula_Doctrine2_Entity_EntityCategory which needs to be changed to Zikula\Core\Doctrine\Entity\AbstractEntityCategory.

Guite commented 10 years ago

See also https://github.com/Guite/MostGenerator/blob/master/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/zclassic/models/entity/extensions/Categories.xtend#L69 relating this change.

craigh commented 10 years ago

This would be a BC problem then. Since it should still work.

Guite commented 10 years ago

I doubt that it is possible to have a Doctrine join to two different classes. So unless there is a volunteer for this issue I don't see a way to solve it.

Guite commented 10 years ago

Also I don't mind about a few bc breaks in a new major version. Avoiding all of these slows down development significantly and raises difficulty.

craigh commented 10 years ago

Also I don't mind about a few bc breaks in a new major version

I sincerely disagree, unless by "new version" you mean 2.0.0. Semver requires all breaking changes to occur only in major versions (e.g. 2.x.x). While Zikula has certainly almost never adhered to this principal, I think we should start. We should work diligently to avoid BC breaks as much as possible.

Guite commented 10 years ago

I agree in general. But introducing namespaces is more sweeping than simple functional changes, isn't it?

craigh commented 10 years ago

It certainly is. The Namespaced portions of the core are intended as either "silent" changes (non-Api breaking and completely BC) or part of a Forward Compatibility layer, such that anything that worked in 1.3 should still work with no changes.

Certainly a case could be made for naming 1.4 as 2.0 but that ship has long since sailed and there is no need to rehash that again. My priority is simply this: maintain BC as much as humanly possible until 2.0.0.

Guite commented 10 years ago

Sure. But I still doubt that this issue can be fixed with ease. Maybe it would be possible to let Zikula_Doctrine2_Entity_EntityCategory inherit from Zikula\Core\Doctrine\Entity\AbstractEntityCategory so the type hint would be satisfied. Can't imagine the side effects of such a change though.

craigh commented 10 years ago

agreed. it will be a challenge. I have already worked on most of the category stuff and solved it with regard to BC issues. I will take a look at this when I have time.

craigh commented 9 years ago

I just tested this again and did not have the problem anymore!