sonata-project / SonataClassificationBundle

Symfony SonataClassificationBundle
https://docs.sonata-project.org/projects/SonataClassificationBundle
MIT License
89 stars 115 forks source link

duplicated Entity #407

Closed nassimabiddz closed 4 years ago

nassimabiddz commented 6 years ago

Hi im using Symfony 4.1

When you install SonataMediaBundle and SonataClassificationBundle after configure the both of them. and you want execute the commande

php bin/console doctrine:schema:update --force

you got this Error

The table with name 'shop.classification__collection' already exists.

same for all other table of classification like category and tag if you try to change the name of table in the entity of classification__collection to classification_collection

you will get a second error like

An exception occurred while executing 'CREATE UNIQUE INDEX tag_collection ON classification__collection (slug, context): SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

pix0r commented 6 years ago

@nassimabiddz I'm running into the same issue. It seems that the composer require sonata-project/classification-bundle is generating entities in my src/App/Entity/ directory, and then the instructions are to run this command which generates another set of entities:

bin/console sonata:easy-extends:generate SonataClassificationBundle --dest=src --namespace_prefix=App.

If I skip that step I am able to generate a Doctrine migration bin/console make:migration and don't get the duplicate entity error you're seeing. I think maybe the docs are out of date with the installation script.

kunicmarko20 commented 6 years ago

Installation needs to be updated on all packages that recieved flex recipe.

Easy extends shouldn’t be used with flex. cc @covex-nn am I right?

OskarStark commented 6 years ago

App/Entities? Not App/Entity ?

OskarStark commented 6 years ago

Yes, no easy extends needed then

pix0r commented 6 years ago

App/Entities? Not App/Entity ?

You're correct, it is src/App/Entity. I updated my comment.

nassimabiddz commented 6 years ago

@OskarStark im not using the flex i use the standard one i think sonata just need to update the package of the bundle to work ?

kratekk commented 5 years ago

Hey @nassimabiddz or @pix0r did you find the solution?

latheva commented 5 years ago

Hello, Symfony4.2 seems ok when I've skipped _bin/console sonata:easy-extends:generate SonataClassificationBundle --dest=src --namespaceprefix=App

anetka31 commented 5 years ago

Hey all. I'm running into the same issue, too. I have: symfony 4.2, admin-bundle and media-bundle. I use flex. When I skipp _bin/console sonata:easy-extends:generate SonataClassificationBundle --dest=src --namespaceprefix=App during install classification-bundle I get error:

Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled.

I can't add in config/bundles.php

return [
    //...
    App\Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle::class => ['all' => true],
];

because I haven't catalogue src\Application\Sonata\ClassificationBundle

So, what should I do now?

quisse commented 5 years ago

@anetka31 The flex recipe for the ClassificationBundle should've created files in the src/Entity directory, not in a bundle. So you don't need to register that non-existing ApplicationSonataClassificationBundle bundle.

kunicmarko20 commented 5 years ago

Installation docs really need a refresher and recipes should be added for all packages so we can drop easy extends docs.

anetka31 commented 5 years ago

Ok, so what should I do to avoid error: Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled. ?

kunicmarko20 commented 5 years ago

can you give us a stack trace of the error?

anetka31 commented 5 years ago

I think, it was like that (I'm not sure because since yesterday I have done so many times that I do not remember):

  1. I do steps 2.1 and 2.2 from https://sonata-project.org/bundles/classification/master/doc/reference/installation.html (version: master) 1.1 after composer require sonata-project/classification-bundle everything looked good 1.3 I skipp to:

    And configure ClassificationBundle to use the newly generated classes

and modify sonata_classification.yaml file:

sonata_classification:
    class:
        category: App\Entity\SonataClassificationCategory
        collection: App\Entity\SonataClassificationCollection
        context: App\Entity\SonataClassificationContext
        tag: App\Entity\SonataClassificationTag
        media: App\Entity\SonataMediaMedia

After bin/console doctrine:schema:update --force in my console I get error: In AbstractDoctrineExtension.php line 85:

Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled.

More details:


(1/1)                                     InvalidArgumentException                                                                  Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled.
--
in AbstractDoctrineExtension.php line 85
at AbstractDoctrineExtension->loadMappingInformation(array('naming_strategy' => 'doctrine.orm.naming_strategy.underscore', 'auto_mapping' => false, 'mappings' => array('App' => array('is_bundle' => false,  'type' => 'annotation', 'dir' =>  '/home/vagrant/Kalisz/src/Entity', 'prefix' => 'App\\Entity', 'alias'  => 'App', 'mapping' => true), 'SonataMediaBundle' => array('mapping' => true), 'ApplicationSonataMediaBundle' => array('mapping' => true), 'ApplicationSonataClassificationBundle' => array('mapping' => true), 'SonataClassificationBundle' => array('mapping' => true), 'FrameworkBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineCacheBundle' => array('mapping' => true, 'is_bundle' => true), 'SensioFrameworkExtraBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineMigrationsBundle' => array('mapping' => true, 'is_bundle' => true), 'SecurityBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataCoreBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataBlockBundle' => array('mapping' => true, 'is_bundle' => true), 'KnpMenuBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataAdminBundle' => array('mapping' => true, 'is_bundle' => true), 'SwiftmailerBundle' => array('mapping' => true, 'is_bundle' => true), 'TwigBundle' => array('mapping' => true, 'is_bundle' => true), 'WebProfilerBundle' => array('mapping' => true, 'is_bundle' => true), 'MonologBundle' => array('mapping' => true, 'is_bundle' => true), 'DebugBundle' => array('mapping' => true, 'is_bundle' => true), 'MakerBundle' => array('mapping' => true, 'is_bundle' => true), 'WebServerBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataEasyExtendsBundle' => array('mapping' => true, 'is_bundle' => true), 'JMSSerializerBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataDoctrineORMAdminBundle' => array('mapping' => true, 'is_bundle' => true)), 'query_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null), 'metadata_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null), 'result_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null),  'class_metadata_factory_name' =>  'Doctrine\\ORM\\Mapping\\ClassMetadataFactory',  'default_repository_class' => 'Doctrine\\ORM\\EntityRepository',  'quote_strategy' => 'doctrine.orm.quote_strategy.default',  'entity_listener_resolver' => null, 'repository_factory' => 'doctrine.orm.container_repository_factory', 'hydrators' => array(), 'filters' => array(), 'name' => 'default'), object(MergeExtensionConfigurationContainerBuilder))in DoctrineExtension.php line 608
quisse commented 5 years ago

I think, it was like that (I'm not sure because since yesterday I have done so many times that I do not remember):

  1. I do steps 2.1 and 2.2 from sonata-project.org/bundles/classification/master/doc/reference/installation.html (version: master) 1.1 after composer require sonata-project/classification-bundle everything looked good 1.3 I skipp to:

And configure ClassificationBundle to use the newly generated classes

and modify sonata_classification.yaml file:

sonata_classification:
    class:
        category: App\Entity\SonataClassificationCategory
        collection: App\Entity\SonataClassificationCollection
        context: App\Entity\SonataClassificationContext
        tag: App\Entity\SonataClassificationTag
        media: App\Entity\SonataMediaMedia

After bin/console doctrine:schema:update --force in my console I get error:

In AbstractDoctrineExtension.php line 85:

Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled.

More details:


## (1/1) InvalidArgumentException Bundle "ApplicationSonataClassificationBundle" does not exist or it is not enabled.
in AbstractDoctrineExtension.php line 85
at AbstractDoctrineExtension->loadMappingInformation(array('naming_strategy' => 'doctrine.orm.naming_strategy.underscore', 'auto_mapping' => false, 'mappings' => array('App' => array('is_bundle' => false, 'type' => 'annotation', 'dir' => '/home/vagrant/Kalisz/src/Entity', 'prefix' => 'App\Entity', 'alias' => 'App', 'mapping' => true), 'SonataMediaBundle' => array('mapping' => true), 'ApplicationSonataMediaBundle' => array('mapping' => true), 'ApplicationSonataClassificationBundle' => array('mapping' => true), 'SonataClassificationBundle' => array('mapping' => true), 'FrameworkBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineCacheBundle' => array('mapping' => true, 'is_bundle' => true), 'SensioFrameworkExtraBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineBundle' => array('mapping' => true, 'is_bundle' => true), 'DoctrineMigrationsBundle' => array('mapping' => true, 'is_bundle' => true), 'SecurityBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataCoreBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataBlockBundle' => array('mapping' => true, 'is_bundle' => true), 'KnpMenuBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataAdminBundle' => array('mapping' => true, 'is_bundle' => true), 'SwiftmailerBundle' => array('mapping' => true, 'is_bundle' => true), 'TwigBundle' => array('mapping' => true, 'is_bundle' => true), 'WebProfilerBundle' => array('mapping' => true, 'is_bundle' => true), 'MonologBundle' => array('mapping' => true, 'is_bundle' => true), 'DebugBundle' => array('mapping' => true, 'is_bundle' => true), 'MakerBundle' => array('mapping' => true, 'is_bundle' => true), 'WebServerBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataEasyExtendsBundle' => array('mapping' => true, 'is_bundle' => true), 'JMSSerializerBundle' => array('mapping' => true, 'is_bundle' => true), 'SonataDoctrineORMAdminBundle' => array('mapping' => true, 'is_bundle' => true)), 'query_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null), 'metadata_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null), 'result_cache_driver' => array('type' => 'array', 'namespace' => null, 'cache_provider' => null), 'class_metadata_factory_name' => 'Doctrine\ORM\Mapping\ClassMetadataFactory', 'default_repository_class' => 'Doctrine\ORM\EntityRepository', 'quote_strategy' => 'doctrine.orm.quote_strategy.default', 'entity_listener_resolver' => null, 'repository_factory' => 'doctrine.orm.container_repository_factory', 'hydrators' => array(), 'filters' => array(), 'name' => 'default'), object(MergeExtensionConfigurationContainerBuilder))in DoctrineExtension.php line 608

fixed formatting

kunicmarko20 commented 5 years ago

Did you add this:

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    ApplicationSonataClassificationBundle: ~
                    SonataClassificationBundle: ~

If yes, ApplicationSonataClassificationBundle should be removed

anetka31 commented 5 years ago

@kunicmarko20 Ok, now it's better. Now, after: bin/console doctrine:schema:update --force I get:

In MappingException.php line 772:



  The target-entity Application\Sonata\MediaBundle\Entity\Media cannot be found in 'App\Entity\SonataClassificationCollecti
  on#media'.```
quisse commented 5 years ago

@anetka31 Have you checked the namespace of the media entity? I guess it'll be more like App\Application\Sonata\MediaBundle\Entity\Media. Since the classification entities were App\Application\Sonata\ClassificationBundle\... (= one App or Application too much, made the same mistake. Perhaps the docs could be updated to prevent this)

kunicmarko20 commented 5 years ago

Based on config:

sonata_classification:
    class:
        category: App\Entity\SonataClassificationCategory
        collection: App\Entity\SonataClassificationCollection
        context: App\Entity\SonataClassificationContext
        tag: App\Entity\SonataClassificationTag
        media: App\Entity\SonataMediaMedia

I would say it is App\Entity\SonataMediaMedia?

anetka31 commented 5 years ago

I am lost, environmental matters are foreign to me :( @kunicmarko20 > in my sonata_classification.yaml line with media is commented. WYSWIG cut off this @guisse > Yes, in my media entity namespace is App\Application\Sonata\MediaBundle\Entity but if I change to Application\Sonata\MediaBundle\Entity in console I get the same error. Only in page sonata/media/media/list the error is diffrent:

  1. for App\Application\Sonata... is The target-entity Application\Sonata\ClassificationBundle\Entity\Category cannot be found in 'App\Application\Sonata\MediaBundle\Entity\Media#category'.
  2. for Application\Sonata\MediaBundle\Entity is The autoloader expected class "App\Application\Sonata\MediaBundle\Entity\Media" to be defined in file "/home/vagrant/Kalisz/vendor/composer/../../src/Application/Sonata/MediaBundle/Entity/Media.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
quisse commented 5 years ago

sonata_classification.yml

sonata_classification:
    class:
        tag: App\Entity\SonataClassificationTag
        category: App\Entity\SonataClassificationCategory
        collection: App\Entity\SonataClassificationCollection
        context: App\Entity\SonataClassificationContext
        media:  App\Application\Sonata\MediaBundle\Entity\Media

src/Application/Sonata/MediaBundle/Entity/Media.php

<?php

namespace App\Application\Sonata\MediaBundle\Entity;

use Sonata\MediaBundle\Entity\BaseMedia;
class Media extends BaseMedia {
    /**
     * @var \App\Entity\SonataClassificationCategory
    protected $category;
    ...
}

It's just a matter of linking all the correct classes, which an IDE like PhpStorm is a great help in solving.

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.