phinx
phinx copied to clipboard
PHP Deprecated: As of 4.5.0, using newQuery() is deprecated
Running a migration with Phinx v 0.13.4 I get this error message:
== 20221014105116 ModifyPermissionForGlobalStyling: migrating
PHP Deprecated: As of 4.5.0, using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`. The query objects returned by these methods will emit deprecations that will become fatal errors in 5.0.See https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html for more information.
/xyz/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php, line: 214
You can disable all deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED`. Adding `xyz/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php` to `Error.ignoredDeprecationPaths` in your `config/app.php` config will mute deprecations from that file only. in /xyz/vendor/cakephp/core/functions.php on line 318
(the paths above have been sanitized a bit)
I believe the triggering migration code (sanitized a bit) is this:
$builder = $this->getQueryBuilder();
$builder
->update('xxxxxx')
->set('yyyy', 'zzzzzzz')
->where(['yyyy' => 'aaaaaaaaaaa'])
->execute();
I also noticed the same error was submitted as an issue in the CakePHP repo: https://github.com/cakephp/migrations/issues/651
Is there anything I can do to prevent this deprecation error message from appearing?
Might also be related to https://github.com/cakephp/phinx/pull/2242 Which is now in v0.15 version release.
You can backport this to v0.14 one if needed. v0.13 might be EOL now.
To address https://github.com/cakephp/migrations/issues/651 and this issue, we'd need to backport #2242 to v0.13. There is also the changes to getQueryBuilder from 37307f8189b1ed307c4bd00235190b1a984c49e2 that might be useful (though make it optional to pass argument and if no argument, default to current behavior of using newQuery vs throwing exception).
Granted, given that newQuery in favor of using the specific methods was deprecated in cakephp and the type problems with getQueryBuilder that motivated #2242, I wonder if we shouldn't also deprecate getQueryBuilder to be removed in 0.16 as well. Thoughts on that @dereuromark?
Why not backport to 0.14 only? Shouldn't be any need to still use 0.13 afaik See wiki
Biggest reason would be to help cakephp/migrations@v3 users, but if you don't think you'd want those methods in phinx proper for that (or fine with just having those users be stuck with the deprecation warnings), then yeah, less of a reason to backport that far unless @malle-pietje provides a compelling reason on why they might be stuck on 0.13.
Thanks for all the feedback!
I'm stuck with 0.13 because a large number of deployments of our application are still on PHP 7.4, we could move to 0.14.
I checked and the reason we had to pin to version 0.13 has been fixed so we should be able to move to 0.14. That means a backport would be welcome for us and any other projects that need to support PHP 7.4.
I know, PHP 7.4 is EOL but you don't want to know how many servers are still running it... Forcing them to upgrade is going to put extra load on our team 😉
0.14 backport is fine, even supporting 7.4 here totally OK, no worries. Thats still the min version for the Cake4 series. A backport PR would be welcome here.
I'll see whether I can find the time to look into the backport in the short term. If someone who's more familiar with the package is willing to look into this, that's obviously more than welcome! 🤞
Same for me. At the moment we have to support PHP 7.4 because it is part of Ubuntu 20.04 which is still in support until Apr 2025. Even if PHP 7.4 itself is EOL.
My solution is to install the dependent version in advance .
Define the following content in the require field of your composer.json
"cakephp/core": "~4.3.0",
"cakephp/utility": "~4.3.0",
"cakephp/datasource": "~4.3.0",
"cakephp/database": "~4.3.0",
"robmorgan/phinx": "~0.13.0",
run composer update
It can work normally until your project can be migrated to the latest phinx
If you are unsure of the dependencies, you can use the following instructions to view them
composer show cakephp/database -t