Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using newQuery() is deprecated. Instead, use insertQuery(), deleteQuery(), selectQuery() or updateQuery() #651

Open
1 of 3 tasks
nook24 opened this issue Oct 25, 2023 · 7 comments
Labels

Comments

@nook24
Copy link
Contributor

nook24 commented Oct 25, 2023

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 4.5.0

  • Migrations plugin version: 3.9.0 @stable in composer.json

  • Bake plugin version (if relevant): EXACT RELEASE VERSION OR COMMIT HASH, HERE.

  • Database server mysql Ver 8.0.34-0ubuntu0.22.04.1

  • PHP Version: PHP 8.1.2-1ubuntu2.14

  • Platform / OS: Ubuntu and RHEL

What you did

When using CakePHP 4.5.0 with the migration plugin, I get the following deprecated messages


 == InstallSeed: seeding
2023-10-25 15:10:21 notice: 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.
/opt/openitc/frontend/vendor/cakephp/migrations/src/CakeAdapter.php, line: 83
You can disable all deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED`. Adding `vendor/cakephp/migrations/src/CakeAdapter.php` to `Error.ignoredDeprecationPaths` in your `config/app.php` config will mute deprecations from that file only.
Trace:
/opt/openitc/frontend/vendor/cakephp/cakephp/src/Core/functions.php /opt/openitc/frontend/vendor/cakephp/cakephp/src/Core/functions.php, line 300
/opt/openitc/frontend/vendor/cakephp/cakephp/src/Database/Connection.php /opt/openitc/frontend/vendor/cakephp/cakephp/src/Database/Connection.php, line 506
Cake\Database\Connection->newQuery() /opt/openitc/frontend/vendor/cakephp/migrations/src/CakeAdapter.php, line 83
Migrations\CakeAdapter->getQueryBuilder() /opt/openitc/frontend/config/Seeds/InstallSeed.php, line 153
InstallSeed->run() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php, line 146
Phinx\Migration\Manager\Environment->executeSeed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php, line 420
Phinx\Migration\Manager->executeSeed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php, line 612
Phinx\Migration\Manager->seed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Console/Command/SeedRun.php, line 106
Phinx\Console\Command\SeedRun->execute() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/Phinx/CommandTrait.php, line 37
Migrations\Command\Phinx\Seed->parentExecute() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/Phinx/Seed.php, line 76
Migrations\Command\Phinx\Seed->execute() /opt/openitc/frontend/vendor/symfony/console/Command/Command.php, line 326
Symfony\Component\Console\Command\Command->run() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 1063
Symfony\Component\Console\Application->doRunCommand() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 320
Symfony\Component\Console\Application->doRun() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 174
Symfony\Component\Console\Application->run() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/MigrationsCommand.php, line 126
Migrations\Command\MigrationsCommand->execute() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/BaseCommand.php, line 190
Cake\Console\BaseCommand->run() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/MigrationsCommand.php, line 198
Migrations\Command\MigrationsCommand->run() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 334
Cake\Console\CommandRunner->runCommand() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 172
Cake\Console\CommandRunner->run() /opt/openitc/frontend/bin/cake.php, line 12
[main]

deprecated: 16384 :: 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.
/opt/openitc/frontend/vendor/cakephp/migrations/src/CakeAdapter.php, line: 83
You can disable all deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED`. Adding `vendor/cakephp/migrations/src/CakeAdapter.php` to `Error.ignoredDeprecationPaths` in your `config/app.php` config will mute deprecations from that file only. on line 300 of /opt/openitc/frontend/vendor/cakephp/cakephp/src/Core/functions.php
Stack Trace:

/opt/openitc/frontend/vendor/cakephp/cakephp/src/Core/functions.php /opt/openitc/frontend/vendor/cakephp/cakephp/src/Core/functions.php, line 300
/opt/openitc/frontend/vendor/cakephp/cakephp/src/Database/Connection.php /opt/openitc/frontend/vendor/cakephp/cakephp/src/Database/Connection.php, line 506
Cake\Database\Connection->newQuery() /opt/openitc/frontend/vendor/cakephp/migrations/src/CakeAdapter.php, line 83
Migrations\CakeAdapter->getQueryBuilder() /opt/openitc/frontend/config/Seeds/InstallSeed.php, line 153
InstallSeed->run() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php, line 146
Phinx\Migration\Manager\Environment->executeSeed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php, line 420
Phinx\Migration\Manager->executeSeed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php, line 612
Phinx\Migration\Manager->seed() /opt/openitc/frontend/vendor/robmorgan/phinx/src/Phinx/Console/Command/SeedRun.php, line 106
Phinx\Console\Command\SeedRun->execute() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/Phinx/CommandTrait.php, line 37
Migrations\Command\Phinx\Seed->parentExecute() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/Phinx/Seed.php, line 76
Migrations\Command\Phinx\Seed->execute() /opt/openitc/frontend/vendor/symfony/console/Command/Command.php, line 326
Symfony\Component\Console\Command\Command->run() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 1063
Symfony\Component\Console\Application->doRunCommand() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 320
Symfony\Component\Console\Application->doRun() /opt/openitc/frontend/vendor/symfony/console/Application.php, line 174
Symfony\Component\Console\Application->run() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/MigrationsCommand.php, line 126
Migrations\Command\MigrationsCommand->execute() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/BaseCommand.php, line 190
Cake\Console\BaseCommand->run() /opt/openitc/frontend/vendor/cakephp/migrations/src/Command/MigrationsCommand.php, line 198
Migrations\Command\MigrationsCommand->run() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 334
Cake\Console\CommandRunner->runCommand() /opt/openitc/frontend/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 172
Cake\Console\CommandRunner->run() /opt/openitc/frontend/bin/cake.php, line 12
[main]
 == InstallSeed: seeded 0.7359s

This is /opt/openitc/frontend/config/Seeds/InstallSeed.php, line 153:

<?php

$QueryBuilder = $this->getAdapter()->getQueryBuilder();   // line 153

$stm = $QueryBuilder->select('*')
    ->from($table->getName())
    ->where([
        'plugin' => $record['plugin'],
        'task'   => $record['task']
    ])
    ->execute();
    $result = $stm->fetchAll();

    if (empty($result)) {
         $table->insert($record)->save();
    }

Expected Behavior

No deprecated messages

@mcube27
Copy link

mcube27 commented Jun 17, 2024

Hi,
Will this bug be corrected ?
It's not wasy to migrate to CakePhp5 for big applications, but we need to run tests that need migrations and that contain some queries ?

@markstory
Copy link
Member

@mcube27 No it won't. If you don't want to see deprecations you can turn them off. But you'll need to address the deprecations before you can upgrade.

Upgrading migrations may also help as currently migrations is not using newQuery() anywhere.

@mcube27
Copy link

mcube27 commented Jul 12, 2024

We use migration sometimes to make sql queries using $this->getQueryBuilder().

That is why I asked if it will be corrected ?

markstory added a commit that referenced this issue Jul 28, 2024
This aligns the interface we have in the 4.x branch, and also gives
a solution to #651 for applications that want to not have any
deprecations.
@markstory
Copy link
Member

After attempting to fix this with #731, I don't think there is a reasonable solution for this deprecation warning. Phinx providers the getQueryBuilder() method. All of phinx's branches have moved past compatibility with cakephp 4.x making releasing new patch builds more complicated.

If you want to get rid of the deprecations now you'd have to alter your usage of migrations to

$query = $this->adapter->getDecoratedConnection()->selectQuery();

markstory added a commit that referenced this issue Jul 28, 2024
Having this method will improve compatibility with historical
migrations.

Refs #651
@nook24
Copy link
Contributor Author

nook24 commented Jul 29, 2024

Thanks for the update. We have scheduled the migration to CakePHP 5 for the end of this year. I guess to replace the old getQueryBuilder() calls should not be to hard.

The changes from your PR are a good reference guess.
https://github.com/cakephp/migrations/pull/731/files

Is there any documentation about getDecoratedConnection() available?

@markstory
Copy link
Member

Is there any documentation about getDecoratedConnection() available?

No, but it will return a Cake\Database\Connection with the connection that migrations are being run on. That method will be available in both 4.x and 5.x compatible migrations once #732 is merged.

@nook24
Copy link
Contributor Author

nook24 commented Jul 29, 2024

Perfect, many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants