Symfony 3 FOSUSERBUNDLE UPDATE broke my app - php

I am using Symfony 3.0.9 with FosUserBundle to build my app. I recently did a composer update and now I cannot create users via UserManager or command line. The error is Integrity constraint violation: 1048 Column 'salt' cannot be null. This error occurs even when I explicitly call parent::__construct() in my constructor method as show below:
/**
* constructor.
*/
public function __construct()
{
parent::__construct();
}
And also fails if I called the setSalt method like $user->setSalt('87234hjjdwshjdsjkds')
All efforts to resolve this have failed so I started to pay close attention to my composer update command and this was some of the output:
Updating dependencies (including require-dev)
Removing twig/twig (v1.24.1)
Installing twig/twig (v1.28.2)
Loading from cache
Removing symfony/polyfill-util (v1.2.0)
Installing symfony/polyfill-util (v1.3.0)
Loading from cache
...
Removing symfony/polyfill-intl-icu (v1.2.0)
Installing symfony/polyfill-intl-icu (v1.3.0)
Loading from cache
Removing psr/log (1.0.0)
Installing psr/log (1.0.2)
Loading from cache
Removing doctrine/cache (v1.6.0)
Installing doctrine/cache (v1.6.1)
Loading from cache
...
Removing doctrine/orm (v2.5.4)
Installing doctrine/orm (v2.5.5)
Loading from cache
Removing sensiolabs/security-checker (v3.0.2)
Installing sensiolabs/security-checker (v4.0.0)
Loading from cache
Removing nikic/php-parser (v2.1.0)
Installing nikic/php-parser (v2.1.1)
Loading from cache
...
Removing doctrine/doctrine-migrations-bundle (1.1.1)
Installing doctrine/doctrine-migrations-bundle (v1.2.0)
Loading from cache
...
Removing phpspec/phpspec (2.5.1)
Installing phpspec/phpspec (2.5.5)
Loading from cache
Removing doctrine/data-fixtures (v1.2.1)
Installing doctrine/data-fixtures (v1.2.2)
Loading from cache
Updating friendsofsymfony/user-bundle dev-master (147ca68 => 7261f7a)
Checking out 7261f7aa143b4bfdb0b7ddc5df208067fa7be698
As you can see FOSUSERBUNDLE was updated.
Reverting the composer update, deleting my vendor directory and running composer install fixes it. This summed it down to the update. That was the problem.
If anyone knows how I can update and still have a working application I would be grateful for your comments and feedback.

1) If you want to use FOSUserBundle in version 2 there is no final/stable version - so you always have to expect breaking changes in a dev/master branch.
2) Since a couple of days there is a 2.0.0 Beta version at least which I heavily recommend to use in your case: Check it here.
3) There were a couple of changes regarding the User Database Schema, e.g a couple of unused fields were removed. And there is a change regarding the salt field - so in your case - as far as I can see probably the missing thing is to update your database schame (if you're working with Doctrine call bin/console doctrine:schema:update --force).
For details see e.g. the release notes for 2.0.0 beta:
[BC break] The salt field of the User class is now nullable.

If you want update everything but user-bundle
With composer you may pass package name(s) as parameter to composer update command, like this:
composer update vendor1/package1 vendor2/package2
So you can create long string of all packages except user-bundle.
List of all oudated packages you can get from
composer show -o --name-only
command output.
The option -o here is for only outdated packages which are available for update.
Option --name-only obviously shows only package name without version and description.
So, on unix-like OS you can run something like
composer show -o --name-only | grep -v 'friendsofsymfony/user-bundle' | xargs composer update
More about Composer CLI

Related

Required dependencies not updating

I'm updating some packages with composer. I'm using Laravel5.6 in my project.
The one that I'm trying is PHPStan to version 0.10.7. My current version is 0.9.2.
The problem
When I try to update, it shows a success message, but when checking the outdate packages output, it is still OUTDATED.
What I've tried
Using composer why-not phpstan/phpstan 0.10.7 gave me the following output:
laravel/laravel my-branch-test requires (for development) phpstan/phpstan (^0.9.2)
phpstan/phpstan 0.10.7 requires nikic/php-parser (^4.0.2)
laravel/laravel my-branch-test does not require nikic/php-parser (but v3.1.5 is installed)
phpstan/phpstan 0.10.7 requires phpstan/phpdoc-parser (^0.3)
laravel/laravel my-branch-test does not require phpstan/phpdoc-parser (but 0.2 is installed)
Then I tried to update nikic/php-parser and phpdoc-parser and re-run composer update phpstan/phpstan but it gave me the same result of before. (not updating)
UPDATE: running composer update phpstan/phpstan --with-dependencies gave me the following output:(but still didn't updated phpstan)
composer update phpstan/phpstan --with-dependencies
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 11 updates, 0 removals
- Updating ocramius/package-versions (1.2.0 => 1.3.0): Loading from cache
- Updating symfony/finder (v4.1.4 => v4.2.1): Loading from cache
- Updating symfony/polyfill-mbstring (v1.9.0 => v1.10.0): Loading from cache
- Updating jean85/pretty-package-versions (1.1 => 1.2): Loading from cache
- Updating nette/utils (v2.4.9 => v2.5.3): Loading from cache
- Updating nette/php-generator (v3.0.2 => v3.0.5): Loading from cache
- Updating nette/neon (v2.4.2 => v2.4.3): Loading from cache
- Updating nette/di (v2.4.10 => v2.4.14): Loading from cache
- Updating nette/bootstrap (v2.4.5 => v2.4.6): Loading from cache
- Updating nette/finder (v2.4.1 => v2.4.2): Loading from cache
- Updating nette/robot-loader (v3.0.3 => v3.1.0): Loading from cache
Package sebastian/git is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: caffeinated/modules
Discovered Package: fideloper/proxy
Discovered Package: jenssegers/agent
Discovered Package: laravel/tinker
Discovered Package: rap2hpoutre/laravel-log-viewer
Discovered Package: rcrowe/twigbridge
Package manifest generated successfully.
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Code
In my composer.json file, the package is listed as:
"require-dev": {
"phpstan/phpstan": "^0.9.2",
Any ideas?
The problem here was that others packages that I was using were using the nikic/php-parser package too, but considering only non-breaking changes (nikic/php-parser":"^3.0"), "blocking" the upgrade to > 4.0.
Because of composer can't install two versions of the same package, my solution was not updating phpstan for now.
I will wait for the libs that require nikic/php-parser to update their requirements to 4.0 and up or will change these packages in the future.

JmsSerializerBundle installation ends with error: Unrecognized option "xml" under "jms_serializer.visitors"

When I install a Symfony 4 skeleton project and add the JmsSerializerBundle, I get an error.
To reproduce:
composer create-project symfony/website-skeleton myproject
cd myproject
composer require jms/serializer-bundle
The installation ends with an error:
Using version ^3.0 for jms/serializer-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.1.*"
Package operations: 16 installs, 0 updates, 0 removals
- Installing hoa/exception (1.17.01.16): Loading from cache
- Installing hoa/event (1.17.01.13): Loading from cache
- Installing hoa/consistency (1.17.05.02): Loading from cache
- Installing hoa/visitor (2.17.01.16): Loading from cache
- Installing hoa/ustring (4.17.01.16): Loading from cache
- Installing hoa/protocol (1.17.01.14): Loading from cache
- Installing hoa/zformat (1.17.01.10): Loading from cache
- Installing hoa/iterator (2.17.01.10): Loading from cache
- Installing hoa/compiler (3.17.08.08): Loading from cache
- Installing hoa/regex (1.17.01.13): Loading from cache
- Installing hoa/math (1.17.05.16): Loading from cache
- Installing hoa/stream (1.17.02.21): Loading from cache
- Installing hoa/file (1.17.07.11): Loading from cache
- Installing jms/metadata (2.0.0): Loading from cache
- Installing jms/serializer (2.0.0): Loading from cache
- Installing jms/serializer-bundle (3.0.0): Loading from cache
Writing lock file
Generating autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (f702450e5b1b913f83ea887faacbdb83)
- WARNING jms/serializer-bundle (>=2.0): From github.com/symfony/recipes-contrib:master
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/jms/serializer-bundle/2.0
Do you want to execute this recipe?
[y] Yes
[n] No
[a] Yes for all packages, only for the current installation session
[p] Yes permanently, never ask again for this project
(defaults to n): y
- Configuring jms/serializer-bundle (>=2.0): From github.com/symfony/recipes-contrib:master
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In ArrayNode.php line 304:
!!
!! Unrecognized option "xml" under "jms_serializer.visitors"
Running composer etc on Windows 10 Powershell. I'm guessing the skeleton is too bare and it needs a dependency, but shouldn't that be solved automatically?
What could be the cause? How can I fix it? Thanks in advance for your help.
The current recipe is not compatible with JMSSerializerBundle 3 (there is a pending pull request, see https://github.com/symfony/recipes-contrib/pull/559). So for now, you need to adapt the configuration manually.

Symfony 2.8 to 3.0 migration

I want to upgrade symfony 2.8 project to 3.0, i changed the version in composer.json to 3.0.* but after composer update is done, i have these error in console:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
PHP Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in
/var/www/html/t/EcoPro/app/AppKernel.php on line 6
It sounds like your code can't find the Kernel class from Symfony. Since it should still be there, as you can see in the Symfony repository in the 3.0-branch I assume something went wrong during your update.
I suggest first running composer diagnose to see if composer itself is up to date and your composer.json is syntactically valid. As a next step you should verify the current version of your dependencies by running composer show. The output should look something like this:
$ composer show
doctrine/annotations v1.2.7 Docblock Annotations Parser
doctrine/cache v1.5.1 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.3.0 Collections Abstraction library
doctrine/common v2.5.1 Common Library for Doctrine projects
doctrine/dbal v2.5.2 Database Abstraction Layer
doctrine/doctrine-bundle 1.6.0 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.2.2 Symfony Bundle for Doctrine Cache
doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm v2.5.2 Object-Relational-Mapper for PHP
incenteev/composer-parameter-handler v2.1.2 Composer script handling your ignored parameter file
jdorn/sql-formatter v1.2.17 a PHP SQL highlighting library
monolog/monolog 1.17.2 Sends your logs to files, sockets, inboxes, databases and various web services
paragonie/random_compat 1.1.0 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
psr/log 1.0.0 Common interface for logging libraries
sensio/distribution-bundle v5.0.2 Base bundle for Symfony Distributions
sensio/framework-extra-bundle v3.0.11 This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle v3.0.0 This bundle generates code for you
sensiolabs/security-checker v3.0.2 A security checker for your composer.lock
swiftmailer/swiftmailer v5.4.1 Swiftmailer, free feature-rich PHP mailer
symfony/monolog-bundle v2.8.2 Symfony MonologBundle
symfony/phpunit-bridge v2.8.0 Symfony PHPUnit Bridge
symfony/polyfill-intl-icu v1.0.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.0.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.0.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.0.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util v1.0.0 Symfony utilities for portability of PHP codes
symfony/swiftmailer-bundle v2.3.9 Symfony SwiftmailerBundle
symfony/symfony v3.0.0 The Symfony PHP framework
twig/twig v1.23.1 Twig, the flexible, fast, and secure template language for PHP
This should help you see whether the update actually worked. If all looks fine, I would go the safe route and revert your code back to 2.8 and then do the update like explained below, instead of changing the composer.json!
First make sure you fixed all deprecations in your existing application. You can use the UPGRADE-document as reference, but also run your tests and check the logs for deprecated calls. This will become easier with 3.3+ as these versions have a separate deprecation-log that you can find in var/log alongside the other log files.
Once you are reasonably sure you code will run with a new major version, just use the following composer command:
composer require symfony/lts:"^3.0"
This is only to make sure that we don't accidentally install any Symfony component that is 4.0 during the process. Once you want to upgrade to Symfony 4 you can just remove this dependency using composer remove symfony/lts and then run update.
After the lts meta package is in place you can update Symfony itself:
composer require symfony/symfony:^3.0
to update to the newest 3.x that your dependencies support or use a stricter constraint if you really want to go step by step:
composer require symfony/symfony:3.0.*
You can also do both things in one step if you like:
$ composer require symfony/lts:^3.0 symfony/symfony:^3.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 2 updates, 0 removals
- Updating symfony/symfony (v2.8.32 => v3.4.2): Downloading (100%)
- Installing psr/simple-cache (1.0.0): Loading from cache
- Installing psr/link (1.0.0): Loading from cache
- Installing psr/container (1.0.0): Loading from cache
- Installing psr/cache (1.0.1): Loading from cache
- Installing fig/link-util (1.0.0): Loading from cache
Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug
// true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Trying to install assets as relative symbolic links.
[OK] No assets were provided by any bundle.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
This should already be enough to have Symfony on the newer version. You will likely have other dependencies such as Doctrine or some bundles that you have installed as well. There are a few useful commands for updating them.
First you can update only a single dependency at a time:
composer update doctrine/orm
When you add the option --with-dependencies it will also update doctrine/orm's dependencies.
You can always ask composer why or composer why-not with a dependency and optionally a version to check why a dependency is there and why it won't update. Just type composer help why-not to see how to use it. This is particularly helpful when you want to update a dependency like doctrine/orm, but composer throws an error that it can't do it.

Discover latest versions of Composer packages when dependencies are locked

Let's say I have a composer.json file with locked dependencies:
{
"require" : {
"zendframework/zendframework" : "2.4.2"
},
"require-dev": {
"phpunit/phpunit": "4.6.6"
}
}
I want to do that because would like to update dependencies manually, so I won't be in a situation where my build fails or other developers experience issues I don't have because Composer installed a different version of the package.
Is there a good way to use Composer to list all newer versions of the locked packages, perhaps something like composer discover, where I get output: zendframework/zendframework is locked at version 2.4.2 (or 2.4.* or whatever), but there are versions 2.5.0, 2.5.1, and 2.6.0 available*?
Is any existing command capable of providing that kind of information?
Basically, I'm more about the newer versions being shown to me, so I can know what dependency to update manually. Committing the composer.lock isn't really the solution because that won't show me what to update (and my composer.json is locked at specific versions, so composer.lock won't differ anyway).
In order to do what you want, commit the composer.lock file and make sure everyone runs composer install to install the deps. This way, everyone has exact the same version/commit of each package.
You can then run composer update to get newer versions. This will update the packages and the composer.lock file, which you can commit and push, so everyone has the same versions again (after they run composer install).
This is not exactly what you are suggesting. But you can run
composer update --dry-run
to see what happens when composer updates your dependencies. This only shows you the latest version a package could be updated to, but not the versions in between:
composer update --dry-run
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Updating symfony/translation (v2.5.5) to symfony/translation (v2.5.11)
- Updating symfony/security-core (v2.5.5) to symfony/security-core (v2.5.11)
- Updating symfony/routing (v2.5.5) to symfony/routing (v2.5.11)
- Updating symfony/process (v2.5.5) to symfony/process (v2.5.11)
- Updating symfony/http-foundation (v2.5.5) to symfony/http-foundation (v2.5.11)
The simplest way would probably just to run:
composer outdated
and get a list of the outdated dependencies. The output looks roughly like this:
As has been said by others, composer does what you tell it, and will only install the versions specified from the .lock file, or update to new versions (as specified within the range of the given version).
There are outside website services that will let you know that packages have been updated though - such as Versioneye.com. You can follow a number of packages, and it will let you know when any of them have been updated, so you can update the composer file as you wish.
To show the latest version of the packages, use show with -l/--latest parameter, e.g.
composer show -l
-l, --latest Show the latest version
To see the tree of dependencies, use -t/--tree parameter, e.g.
composer show -t
-t, --tree List the dependencies as a tree
To list all available version for the given package, run:
composer show -a zendframework/zendframework
Note: Change zendframework/zendframework with your package name.
Notes:
For global, add global right after composer.
For help, run: composer global help show.

Accidental removal of some laravel files with composer install/update, how to retrieve?

I was trying to move the packages from my require-dev to require in composer.json, and accidentally created a second require object when there was already one above the autoload object and called composer update. It then began deleting my laravel install and I quickly pressed ctrl+c.
But now I'm getting an error saying Fatal error: Interface 'Symfony\Component\HttpKernel\HttpKernelInterface' not found when I visit my website, or try running composer install/update again.
Is there any way to recover from this?
These are teh files that were deleted:
C:\xampp\htdocs\project>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing laravel/framework (v4.1.18)
- Removing classpreloader/classpreloader (1.0.1)
- Removing d11wtq/boris (v1.0.8)
- Removing ircmaxell/password-compat (1.0.3)
- Removing filp/whoops (1.0.10)
- Removing jeremeamia/superclosure (1.0.1)
- Removing nikic/php-parser (v0.9.4)
- Removing monolog/monolog (1.7.0)
- Removing nesbot/carbon (1.8.0)
- Removing patchwork/utf8 (v1.1.17)
- Removing phpseclib/phpseclib (0.3.5)
- Removing predis/predis (v0.8.5)
- Removing stack/builder (v1.0.1)
- Removing swiftmailer/swiftmailer (v5.0.3)
- Removing symfony/browser-kit (v2.4.1)
- Removing symfony/css-selector (v2.4.1)
- Removing symfony/dom-crawler (v2.4.1)
- Removing symfony/http-kernel (v2.4.1)
^CTerminate batch job (Y/N)? y
Don't worry, you shouldn't loose anything of your application. It was basically removing things in the vendor folder, which are pretty much removable at any time without prejudice for your application source files, but yes, without them your application will not work, so:
Just get your composer.json back in its feets:
"require": {
"laravel/framework": "4.1.*",
},
Completely remove your vendor folder:
del C:\xampp\htdocs\project\vendor\*.* /s
And then:
composer update
Again

Categories