CakePHP 3.x到4.x升级工具:编写器错误“无法解析为可安装的软件包集”

jqjz2hbq  于 2023-04-21  发布在  PHP
关注(0)|答案(1)|浏览(117)

我有一个旧的CakePHP 3.8.13应用程序,我想升级到CakePHP 4。
目前这是在CakePHP 3 composer.json中。它部署在运行PHP 7.2的环境中。
我也在本地运行PHP 7.2,这是我试图执行升级的地方。

"require": {
        "php": ">=7.2",
        "cakephp/cakephp": "3.8.*",
        "cakephp/migrations": "^2.0.0",
        "cakephp/plugin-installer": "^1.0",
        "mobiledetect/mobiledetectlib": "2.*",
    },
    "require-dev": {
        "cakephp/bake": "^1.9.0",
        "cakephp/cakephp-codesniffer": "^3.0",
        "cakephp/debug_kit": "^3.17.0",
        "josegonzalez/dotenv": "3.*",
        "phpunit/phpunit": "^5|^6",
        "psy/psysh": "@stable"
    },

当我浏览Upgrade Guide时,它一直工作到最后一步。这是我到目前为止所做的。引用的部分来自上面链接的指南。
升级工具仅适用于运行在最新CakePHP 3.x上的应用程序。
改变了composer.json,所以它有这个,我相信这将得到最新的CakePHP 3.x

"require": {
    "cakephp/cakephp": "3.*",

然后是composer update。这可以正常工作,当检查vendor/cakephp/cakephp/VERSION.txt中的文件时,它确实从3.8.13转到了3.10.5
如果您运行的不是PHP 7.2或更高版本,则需要在更新CakePHP之前升级PHP。
我们正在运行PHP 7.2,所以这很好:

% php -v
PHP 7.2.34 (cli) (built: Jan 21 2023 06:18:05) ( NTS )

安装升级工具...
所有这些工作都没有错误:

git clone https://github.com/cakephp/upgrade
cd upgrade
git checkout 4.x
composer install --no-dev

使用升级工具。同样,这可以正常工作,并在我的应用程序目录中适当地更改文件位置:

# Rename locale files
bin/cake upgrade file_rename locales ../path/to/my/app

# Rename template files
bin/cake upgrade file_rename templates ../path/to/my/app

应用Rector重构...自动修复许多不推荐使用的CakePHP和PHPUnit方法调用。在升级依赖项之前应用rector很重要
这些命令工作正常:

bin/cake upgrade rector --rules phpunit80 ../path/to/my/app/tests
bin/cake upgrade rector --rules cakephp40 ../path/to/my/app/src

更新CakePHP依赖关系应用rector重构后,使用以下composer命令升级CakePHP和PHPUnit:
升级PHPUnit的第一个命令可以正常工作

composer require --dev --update-with-dependencies "phpunit/phpunit:^8.0"

失败:

AFAIK将CakePHP从3.x更新到4.x的下一个命令失败:

composer.phar require --update-with-dependencies "cakephp/cakephp:4.0.*"

输出为

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires cakephp/cakephp 4.0.*, found cakephp/cakephp[4.0.0, ..., 4.0.10] but these were not loaded, likely because it conflicts with another require.
  Problem 2
    - cakephp/bake is locked to version 1.12.0 and an update of this package was not requested.
    - cakephp/bake 1.12.0 requires cakephp/cakephp ^3.8.0 -> found cakephp/cakephp[3.8.0, ..., 3.10.5] but it conflicts with your root composer.json require (4.0.*).
  Problem 3
    - cakephp/debug_kit is locked to version 3.23.0 and an update of this package was not requested.
    - cakephp/debug_kit 3.23.0 requires cakephp/cakephp ^3.7.0 -> found cakephp/cakephp[3.7.0, ..., 3.10.5] but it conflicts with your root composer.json require (4.0.*).

我不明白这一点,因为最后一个命令的目的肯定是把它从3.x更新到4.x。如果它是用--update-with-dependencies标志运行的,那么它不应该也更新依赖项吗?
看起来错误消息告诉我它不能安装4.x *,因为 * 像cakephp/bakecakephp/debug_kit这样的依赖项。
为什么会发生这种情况,我该如何解决?
作为参考,composer.json在完成上述步骤后如下所示

"require": {
    "php": ">=7.2",
    "cakephp/cakephp": "3.*",
    "cakephp/migrations": "^2.0.0",
    "cakephp/plugin-installer": "^1.0",
    "mobiledetect/mobiledetectlib": "2.*",
},
"require-dev": {
    "cakephp/bake": "^1.9.0",
    "cakephp/cakephp-codesniffer": "^3.0",
    "cakephp/debug_kit": "^3.17.0",
    "josegonzalez/dotenv": "3.*",
    "phpunit/phpunit": "^8.0",
    "psy/psysh": "@stable"
},
tktrz96b

tktrz96b1#

--update-with-dependencies只更新您需要的包的依赖项(除非它们也是根依赖项),因此只有phpunit/phpunitcakephp/cakephp的依赖项会被更新。
您当前在根composer文件中需要的cakephp/bakecakephp/debug_kit版本与CakePHP 4.0.x不兼容,这就是composer所说的。您必须手动更新所有这些根依赖项以相应地要求兼容版本。
您可以参考要升级到的CakePHP版本的the corresponding app template(确保在每个升级步骤中都这样做,即使是次要版本,也要确保相应地调整config中的文件)。
从最新的4.0.x应用程序模板:
require

"cakephp/migrations": "^3.0@beta",
"cakephp/plugin-installer": "^1.2",
"mobiledetect/mobiledetectlib": "^2.8"

require-dev

"cakephp/bake": "^2.0.3",
"cakephp/cakephp-codesniffer": "~4.1.0",
"cakephp/debug_kit": "^4.0",
"josegonzalez/dotenv": "^3.2",
"phpunit/phpunit": "^8.5",
"psy/psysh": "@stable"

相关问题