FOSUserBundle icon indicating copy to clipboard operation
FOSUserBundle copied to clipboard

Missing attributes for model User

Open rudirocha opened this issue 10 years ago • 49 comments

Hey, I just ran composer update and for the last commit it seems some attributes were missing on User model class Updating friendsofsymfony/user-bundle dev-master (3015f09 => 507ae09)

/**
     * @var bool
     */
    protected $locked;

    /**
     * @var bool
     */
    protected $expired;

    /**
     * @var \DateTime
     */
    protected $expiresAt;

    /**
     * @var bool
     */
    protected $credentialsExpired;

    /**
     * @var \DateTime
     */
    protected $credentialsExpireAt;

Has someone the same problem?

rudirocha avatar Dec 03 '16 15:12 rudirocha

Hi, what error did you get? The expired and credentialsExpired field have been removed from beta1, see https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Changelog.md

damienalexandre avatar Dec 03 '16 15:12 damienalexandre

I got ReflectionException. After create the issue I've tried to update Symfony to v3.2 and that lead to update again FosUserBundle Updating friendsofsymfony/user-bundle dev-master (507ae09 => a38940d) Same error came out. One ReflectionException for each missing property until I added them to the file.

[ReflectionException]                                                    
    Property FOS\UserBundle\Model\User::$locked does not exist   

rudirocha avatar Dec 03 '16 16:12 rudirocha

Try removing the cache and run composer again.

XWB avatar Dec 03 '16 16:12 XWB

I've tried that. I manually removed the /var/cache folder and running composer update again

> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

                                                              
  [ReflectionException]                                       
  Property FOS\UserBundle\Model\User::$locked does not exist  
                                                              

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:  
                                                                             
    [ReflectionException]                                                    
    Property FOS\UserBundle\Model\User::$locked does not exist   

It could be some other dependency or something else?

rudirocha avatar Dec 03 '16 16:12 rudirocha

I have the same problem, some fields are deleted as locked for example.

Why ? And why there is not stable branch ? We use the master as reference for the symfony versions 2.7+

christophe-44-27 avatar Dec 03 '16 22:12 christophe-44-27

Why ? And why there is not stable branch ? We use the master as reference for the symfony versions 2.7+

There were several discussion why there is not stable branch. The team is working very hard on a stable version. Using the dev-master for production is always a bad idea. Don't do this, ever!

ChristianGripp avatar Dec 04 '16 08:12 ChristianGripp

I understand that the team is working hard on a stable version, but in the documentation we can see that they give us this step 1 :

Step 1: Download FOSUserBundle using composer¶ Require the bundle with composer:

$ composer require friendsofsymfony/user-bundle "~2.0@dev"

And they also said that " This version of the bundle requires Symfony 2.7+. If you are using an older Symfony version, please use the 1.3.x releases of the bundle. "

So, ok if you are in under 2.7 you can use the 1.3.x but if you are in 2.7+ you have to use the dev branch.

We are now in 3.0+ and there no stable branch, since many years. Does the team need help to do this quickly ? Why the V2 is always in development ? Well btw, there are some attributes left, and we don't have any other choice to use the v2 dev branch of this bundle.

christophe-44-27 avatar Dec 04 '16 09:12 christophe-44-27

@christophe-44-27 we have always chance to keep a stable version for our application. A composer update, in my opinion, should be done like a "test approach" and ensure that no errors exist before send to production like @core23 said.

Regarding this issue, I think FOS team can check if they have this error. If some information is need please ping :) And any help need as @christophe-44-27 suggested can be also provided!

rudirocha avatar Dec 04 '16 22:12 rudirocha

Well you can always use the latest beta release instead of relying on master.

https://github.com/FriendsOfSymfony/FOSUserBundle/releases/tag/v2.0.0-beta1

XWB avatar Dec 05 '16 11:12 XWB

If you use the APC cache for Doctrine mapping, you need to clear the APC cache, otherwise the cache will still be trying to reference the removed fields until you clear it.

stof avatar Dec 05 '16 11:12 stof

@rudirocha Did you try clearing the APC cache?

XWB avatar Dec 07 '16 09:12 XWB

I'm not able to try it now. But later i'll do it and post the result. I configured Redis to cache some doctrine and session stuff.

rudirocha avatar Dec 07 '16 11:12 rudirocha

And it seems to be cache problem. After flush all REDIS data related to application, composer update had no problem neither the application running. This can be closed! Thanks guys

rudirocha avatar Dec 08 '16 14:12 rudirocha

Got a similar problem using APCu. I've enabled APCu by:

  1. Adding few lines to production configs:
# app/config/config_prod.yml

framework:
    validation:
        cache: validator.mapping.cache.doctrine.apc

doctrine:
    orm:
        metadata_cache_driver: apcu
        result_cache_driver: apcu
        query_cache_driver: apcu
  1. Enabling ApcClassLoader in web/app.php:
// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);

After that I've got error in production logs:

[2016-12-08 14:41:11] request.CRITICAL: Uncaught PHP Exception ReflectionException: "Property ?FOS\UserBundle\Model\User::$locked does not exist" at /home/cdn/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 80 {"exception":"[object] (ReflectionException(code: 0): Property FOS\UserBundle\Model\User::$locked does not exist at /home/cdn/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:80)"} []

Had to comment out cache driver configs to get rid of this error. However I believe it's rather a hack than a fix.

Regular cache:clear command does not solve the issue for me. @XWB How do you suggest to clear APCu cache?

icamys avatar Dec 08 '16 14:12 icamys

you need to clear you doctrine mapping cache when upgrading the bundle to beta1.

And when using APCu, it has a separate cache per SAPI. So the command will not clear the cache used by php-fpm. You need to clear it as well. The easiest way to clear APCu for php-fpm is to restart php-fpm.

stof avatar Dec 08 '16 16:12 stof

@icamys I usually clear the APC cache by reloading Apache.

XWB avatar Dec 09 '16 15:12 XWB

yeah, which is the equivalent of restarting php-fpm when using mod_php rather than php-fpm

stof avatar Dec 09 '16 15:12 stof

Why those properties were removed anyway ?

Jurigag avatar Jan 04 '17 10:01 Jurigag

Because the bundle didn't use them.

mvrhov avatar Jan 04 '17 10:01 mvrhov

And because applications really wanting to use the features need to write some custom code anyway, so it is better if they implement the method in a way fitting their needs exactly instead of trying to fit their use case into the storage structure provided by FOSUserBundle arbitrarily.

stof avatar Jan 04 '17 10:01 stof