Closed flohw closed 8 years ago
Can you upgrade Composer and try the commands again ?
Also, can you provide a stack trace ?
Done.
Also, can you provide a stack trace ?
Sorry, we edited at the same time I think...
[1] Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing 'INSERT INTO classification__context (name, enabled, created_at, updated_at, id) VALUES (?, ?, ?, ?, ?)' with params ["news", 1, "2016-06-22 14:09:06", "2016-06-22 14:09:06", "news"]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'news' for key 'PRIMARY'
at n/a
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 66
at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception occurred while executing 'INSERT INTO classification__context (name, enabled, created_at, updated_at, id) VALUES (?, ?, ?, ?, ?)' with params ["news", 1, "2016-06-22 14:09:06", "2016-06-22 14:09:06", "news"]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'news' for key 'PRIMARY'', object(PDOException))
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 116
at Doctrine\DBAL\DBALException::driverExceptionDuringQuery(object(Driver), object(PDOException), 'INSERT INTO classification__context (name, enabled, created_at, updated_at, id) VALUES (?, ?, ?, ?, ?)', array('news', '1', '2016-06-22 14:09:06', '2016-06-22 14:09:06', 'news'))
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 174
at Doctrine\DBAL\Statement->execute()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 281
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1018
at Doctrine\ORM\UnitOfWork->executeInserts(object(ClassMetadata))
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 378
at Doctrine\ORM\UnitOfWork->commit(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 356
at Doctrine\ORM\EntityManager->flush(null)
in /home/florian/Sites/odaconnect/app/cache/pl_dev/jms_diextra/doctrine/EntityManager_576a7fd3dfdc1.php line 313
at EntityManager576a7fd3dfdc1_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager->flush()
in /home/florian/Sites/odaconnect/vendor/sonata-project/core-bundle/Model/BaseManager.php line 120
at Sonata\CoreBundle\Model\BaseManager->save(object(Media), true)
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Entity/MediaManager.php line 41
at Sonata\MediaBundle\Entity\MediaManager->save(object(Media))
in /home/florian/Sites/odaconnect/src/ODA/CoreBundle/Model/MyDoctrineORMManager.php line 29
at ODA\CoreBundle\Model\MyDoctrineORMManager->create(object(Media))
in /home/florian/Sites/odaconnect/app/cache/pl_dev/classes.php line 3497
at Sonata\AdminBundle\Admin\Admin->create(object(Media))
in /home/florian/Sites/odaconnect/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 684
at Sonata\AdminBundle\Controller\CRUDController->createAction()
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Controller/MediaAdminController.php line 39
at Sonata\MediaBundle\Controller\MediaAdminController->createAction(object(Request))
in line
at call_user_func_array(array(object(MediaAdminController), 'createAction'), array(object(Request)))
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3128
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3090
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3241
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 2455
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /home/florian/Sites/odaconnect/web/odadev.php line 44
[2] Doctrine\DBAL\Driver\PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'news' for key 'PRIMARY'
at n/a
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 93
at Doctrine\DBAL\Driver\PDOStatement->execute(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 165
at Doctrine\DBAL\Statement->execute()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 281
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1018
at Doctrine\ORM\UnitOfWork->executeInserts(object(ClassMetadata))
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 378
at Doctrine\ORM\UnitOfWork->commit(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 356
at Doctrine\ORM\EntityManager->flush(null)
in /home/florian/Sites/odaconnect/app/cache/pl_dev/jms_diextra/doctrine/EntityManager_576a7fd3dfdc1.php line 313
at EntityManager576a7fd3dfdc1_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager->flush()
in /home/florian/Sites/odaconnect/vendor/sonata-project/core-bundle/Model/BaseManager.php line 120
at Sonata\CoreBundle\Model\BaseManager->save(object(Media), true)
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Entity/MediaManager.php line 41
at Sonata\MediaBundle\Entity\MediaManager->save(object(Media))
in /home/florian/Sites/odaconnect/src/ODA/CoreBundle/Model/MyDoctrineORMManager.php line 29
at ODA\CoreBundle\Model\MyDoctrineORMManager->create(object(Media))
in /home/florian/Sites/odaconnect/app/cache/pl_dev/classes.php line 3497
at Sonata\AdminBundle\Admin\Admin->create(object(Media))
in /home/florian/Sites/odaconnect/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 684
at Sonata\AdminBundle\Controller\CRUDController->createAction()
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Controller/MediaAdminController.php line 39
at Sonata\MediaBundle\Controller\MediaAdminController->createAction(object(Request))
in line
at call_user_func_array(array(object(MediaAdminController), 'createAction'), array(object(Request)))
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3128
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3090
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3241
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 2455
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /home/florian/Sites/odaconnect/web/odadev.php line 44
[3] PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'news' for key 'PRIMARY'
at n/a
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 91
at PDOStatement->execute(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 91
at Doctrine\DBAL\Driver\PDOStatement->execute(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 165
at Doctrine\DBAL\Statement->execute()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php line 281
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts()
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1018
at Doctrine\ORM\UnitOfWork->executeInserts(object(ClassMetadata))
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 378
at Doctrine\ORM\UnitOfWork->commit(null)
in /home/florian/Sites/odaconnect/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 356
at Doctrine\ORM\EntityManager->flush(null)
in /home/florian/Sites/odaconnect/app/cache/pl_dev/jms_diextra/doctrine/EntityManager_576a7fd3dfdc1.php line 313
at EntityManager576a7fd3dfdc1_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager->flush()
in /home/florian/Sites/odaconnect/vendor/sonata-project/core-bundle/Model/BaseManager.php line 120
at Sonata\CoreBundle\Model\BaseManager->save(object(Media), true)
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Entity/MediaManager.php line 41
at Sonata\MediaBundle\Entity\MediaManager->save(object(Media))
in /home/florian/Sites/odaconnect/src/ODA/CoreBundle/Model/MyDoctrineORMManager.php line 29
at ODA\CoreBundle\Model\MyDoctrineORMManager->create(object(Media))
in /home/florian/Sites/odaconnect/app/cache/pl_dev/classes.php line 3497
at Sonata\AdminBundle\Admin\Admin->create(object(Media))
in /home/florian/Sites/odaconnect/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 684
at Sonata\AdminBundle\Controller\CRUDController->createAction()
in /home/florian/Sites/odaconnect/vendor/sonata-project/media-bundle/Controller/MediaAdminController.php line 39
at Sonata\MediaBundle\Controller\MediaAdminController->createAction(object(Request))
in line
at call_user_func_array(array(object(MediaAdminController), 'createAction'), array(object(Request)))
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3128
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3090
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 3241
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/florian/Sites/odaconnect/app/bootstrap.php.cache line 2455
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /home/florian/Sites/odaconnect/web/odadev.php line 44
In expected results : can you make it more helpful ? Do you expect :
classification context 'news' already exist and should not be created. New media should be associated to the existing context 'news'
Do you think this is where this should happen? If yes, can you debug that line?
Yes this line should be executed to associate the new media to the category. All data are consistent, context and category retrieved are retrieved correctly and exist in database. Media has no category before this line and has one after.
I have created multiple sub environment depending on the locale (sorry about that previous version was worth than that, thank you previous dev) : fr, pl, ua, en. Each sub env has its own cache dir : fr_prod, pl_prod... and its own configuration : app/config/fr/parameters.yml, app/config/fr/config.yml to override or not common configuration : app/config/config.yml (same for dev and prod envs) There is a common database 'intl' for all common data and one database per locale : fr, pl, ua, en. Medias are stored in the localized databases.
Media creation works fine with for fr locale but the error occurs with pl. Context 'news' is identical in both of them. Not tested with the other locales.
Sorry about the architecture. I am doing my best to restructur all the stuff correctly !
Just after the line, the entity manager know about the classification context entity. Just before persisting it in /sonata-project/core-bundle/Model/BaseManager.php line 120
it probably does not know it anymore.
Can you
Un use step by step. I use it for the first time. Very usefull, I will use it more often ! I hope I read the debug correctly but aparently the entity Category is detected as new entity insteand of managed. I tested the same process with my fr sub environment and Category is detected as managed entity.
Ok now, still using step by step debugging, try to find when it changes from managed to new (assuming it starts as managed).
\Doctrine\ORM\UnitOfWork line 1672. Detected as new for all entities. My new media and my (supposed existing) Category and Context wich are cascade persisted.
The oids seems to not exist[1] in UnitOfWork::$entityStates
but I have no idea why as both entities were retrieved in BaseMediaAdmin line 117.
[1]: entityStates properties contains 5 oids instead of three. Oids 4 and 5 are related to Category and Context but are different of the oids 1 and 2. They should be equal as the entities come from the db. Oid 3 is my new Media.
Maybe the entity manager was cleared at some point? Find the clear() method and add a breakpoint in it to check that.
Indeed, clear method is called one time. When EntityManager::close() is called at the end of EntityManager::commit().
When close is called, only three entities are managed. UnitOfWork::$identityMap contains my existing Category and Context.
So the call to clear()
happens before the entity manager is flushed then? Can you throw an exception in clear()
? This will give you a stack trace, look for sonata code in the stack trace.
Here is a part of my doctrine configuration when the bug is produced
# doctrine connections configurations
connections:
fr:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_fr"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
en:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_en"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
pl:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_pl"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
ru:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_ru"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
intl:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_intl"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# doctrine entity managers configurations
default_entity_manager: %locale%
entity_managers:
fr:
connection: fr
mappings:
# bundles tu use with fr. SonataMediaBundle and SonataClassification are here.
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
pl:
connection: pl
mappings:
# bundles tu use with pl. SonataMediaBundle and SonataClassification are here.
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
en:
connection: en
mappings:
# bundles tu use with en. SonataMediaBundle and SonataClassification are here.
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
ru:
connection: ru
mappings:
# bundles tu use with ru. SonataMediaBundle and SonataClassification are here.
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
intl:
connection: intl
mappings:
# bundle to use with intl em
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
I used my new toy (xdebug+debuger :smiley:) to see wich entity manager and connection were used and when. I find that at some point the 'fr' connexion is used to retrieve the category. I can't determine how and why as default_entity_manager
is %locale%
and %locale%
depends on parameters wich is correct.
Si I refactored this config to only use %locale%
parameter wherever possible :
# doctrine connections configurations
connections:
%locale%:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_%locale%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
intl:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%_intl"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# doctrine entity managers configurations
default_entity_manager: %locale%
entity_managers:
%locale%:
connection: %locale%
mappings:
# bundles tu use with fr. SonataMediaBundle and SonataClassification are here.
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
intl:
connection: intl
mappings:
# bundle to use with intl em
metadata_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
query_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
result_cache_driver:
type: "%doctrine.cache_driver.type%"
host: "%doctrine.cache_driver.host%"
port: "%doctrine.cache_driver.port%"
As I have one cache directery per sub env (fr_prod, en_prod...) I think all will be fine now.
Thanks a lot for the assist and your time !
Glad you managed to find a solution!
Environment
Sonata packages
sonata media bundle 3.0.0 sonata classification bundle 3.0.0 some other not related to this issue
Symfony packages
PHP version
Subject
Upload a media via sonata media bundle using sonata classification bundle
Steps to reproduce
That could depend on my project wich is really awkward. I use the standard upload form provided by the bundle with two fields : file and category. I set an image in the first field and use an existing category for the second field
Expected results
New media created related to the classification context. classification context 'news' already exist and should not be created. New media should be associated to the existing context 'news'.
Actual results
An exception occurred while executing 'INSERT INTO classification__context (name, enabled, created_at, updated_at, id) VALUES (?, ?, ?, ?, ?)' with params ["news", 1, "2016-06-22 13:28:00", "2016-06-22 13:28:00", "news"]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'news' for key 'PRIMARY'