sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
339 stars 487 forks source link

Getting errors because of API code bundle needs #686

Closed AntonioCS closed 6 years ago

AntonioCS commented 8 years ago

Hey,

I have "sonata-project/user-bundle": "^2.2" in my composer.json. I do not plan to use any type of API component. When I do composer update I get this:

[Doctrine\Common\Annotations\AnnotationException]
  [Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction() does not exist, or could not be auto-loaded.

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:

    [Doctrine\Common\Annotations\AnnotationException]
    [Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction() does not exist, or could not be auto-loaded.

  .

Do I need to install & configure FOSRestBundle and NelmioApiDocBundle? Is this something that you are forcing users to do???

core23 commented 8 years ago

Hi,

for the 2.2 version of the this bundle, the dependency is requires. In the current master, the ApiBundle is removed (https://github.com/sonata-project/SonataUserBundle/pull/650).

AntonioCS commented 8 years ago

Thanks. I will change to dev-master in the composer.json.

core23 commented 8 years ago

Be aware of using the master version, because you are using a bleeding edge version. This should not be used for a production environment.

AntonioCS commented 8 years ago

Right. Any version that I can use that does not have this bundle issue?

core23 commented 8 years ago

I see there was a new release. You could use version 2.2.4.

AntonioCS commented 8 years ago

Changed to 2.2.4, did composer update and got this:

PHP Fatal error: Declaration of Sonata\UserBundle\Block\AccountBlockService::validateBlock() must be compatible with Sonata\BlockBundle\Block\BlockAdminServiceInterface::validateBlock(Sonata\CoreBundle\Validator\ErrorElement $errorElement, Sonata\BlockBundle\Model\BlockInterface $block) in /var/www/mylocalpitch/rc_mlp_20140609/vendor/sonata-project/user-bundle/Block/AccountBlockService.php on line 110

core23 commented 8 years ago

Can you show your composer config? @AntonioCS

kaiwa commented 8 years ago

I am experiencing the same problem, but I don't think it's SonataUserBundle's fault in my case. I am using the master branch, the api controllers do not get loaded by SonataUserBundle, which is correct, but for some reason JMSDiExtraBundle loads the controllers anyway (or at least they are not loaded if I disable JMSDiExtraBundle) and therefore it comes to the same exception as OP's initial one.

Something is fucked up since i explicitly configured

jms_di_extra:
    locations:
        all_bundles: false

I guess this is the point when magic starts kicking your butt :-/

gremo commented 7 years ago

I have the same problem: using JMSDiExtraBundle without NelmioApiDocBundle.

Maybe the problem relies in the cache warmer scanning all bundles folders and looking for controllers (note that all_bundles: false is ignored).

It works if you disable the warmer:

jms_di_extra:
    cache_warmer:
        enabled: false

There is a blacklist option but it relies on the controller realpath.

What about prepending the blacklist option if JMSDiExtraBundle is found but NelmioApiDocBundle not?

Edit: I made a quick test with the following prepended configuration and it seems to work just fine (other sonata bundles have the same issue, like SonataClassificationBundle). I can work on a PR.

public function prepend(ContainerBuilder $container)
{
    $bundles = $container->getParameter('kernel.bundles');
    if (isset($bundles['JMSDiExtraBundle']) &&
        (!isset($bundles['NelmioApiDocBundle']) || !isset($bundles['FOSRestBundle']))) {
        $blacklistedControllers = [];
        foreach (glob(__DIR__.'/../Controller/Api/*.php', GLOB_NOSORT) as $filename) {
            $blacklistedControllers[] = realpath($filename);
        }

        if (!empty($blacklistedControllers)) {
            $container->prependExtensionConfig('jms_di_extra', [
                'cache_warmer' => [
                    'controller_file_blacklist' => $blacklistedControllers,
                ],
            ]);
        }
    }
}
greg0ire commented 7 years ago

I can work on a PR.

Amazing work. Please do!

kaiwa commented 7 years ago

@gremo Nice workaround. But I guess it would be preferrable if this would be fixed in JmsDiExtraBundle itself, so that all_bundles: false is working correctly. Maybe better put your effort into an PR over at https://github.com/schmittjoh/JMSDiExtraBundle ? Anyway, looking forward to a solution :)

gremo commented 7 years ago

@kaiwa I agree, but a PR (shouldn't hard to write) on JMSDiExtraBundle could take months to be accepted. In addition we have BC to older version of JMSDiExtraBundle.

greg0ire commented 7 years ago

Did someone report the bug to JMSDiExtraBundle ?

In addition we have BC to older version of JMSDiExtraBundle.

I think we can drop older versions if it's not a major version we're dropping.

kaiwa commented 7 years ago

@greg0ire

Did someone report the bug to JMSDiExtraBundle ?

Yes I did, here you go:

https://github.com/schmittjoh/JMSDiExtraBundle/issues/248

gremo commented 7 years ago

I just opened a new one https://github.com/schmittjoh/JMSDiExtraBundle/issues/269 and I'm sending a PR.

jordisala1991 commented 6 years ago

This seems to be solved, or atleast belongs to JMSDiExtraBundle. If I am wrong ping me and I will reopen