Circular link when using VichUploader with KnpGaufrette and doctrine in Symfony2
I tried to use the following setup in my Symfony2 project:
- VichUploader Bundle to handle file uploads
- KnpGaufrette Bundle to be used by VichUploader as storage adapter
Problem: As soon as I try to use the Gaufrette "doctrine_dbal" storage adapter, I get the following error:
[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> vich_uploader.upload_handler -> vich_uploader.storage.gaufrette -> knp_gaufrette.filesystem_map -> gaufrette.storage_fs_filesystem".
The problem comes up as soon as Symfony tries to check the configuration, eg. on the
app/console cache:clear
How can I solve this problem?
My setup
My project setup is the default setup symfony/framework-standard-edition
with a version 2.5.*
without AcmeDemo package.
I just added Bundles via Composer:
composer require knplabs/knp-gaufrette-bundle vich/uploader-bundle
... added them to AppKernel registerBundles()
:
//...
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Vich\UploaderBundle\VichUploaderBundle(), //NEW
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), //NEW
);
//...
... and added the following config to config.yml
, which is based on the VichUploader docs with Gaufrette and KnpGaufrette with Doctrine DBAL :
# ...
knp_gaufrette:
stream_wrapper: ~
adapters:
storage_adapter:
doctrine_dbal:
connection_name: default
table: data_storage
columns:
key: id
content: file
mtime: mtime
checksum: checksum
filesystems:
storage_fs:
adapter: storage_adapter
vich_uploader:
db_driver: orm
storage: gaufrette
mappings:
storage:
uri_prefix: /images/products
upload_destination: storage_fs
source to share
This is a bug in version 0.14.0 ( https://github.com/dustin10/VichUploaderBundle/issues/370 ) which is fixed in this commit: https://github.com/dustin10/VichUploaderBundle/commit/4abf4180afaf318a66d3e34736c3bd3aa088
source to share