cakephp / upgrade

Upgrade tools for CakePHP meant to facilitate migrating from one version of the framework to another
MIT License
110 stars 60 forks source link

Upgrade from cakephp 4.4.x to 4.5.0 on Windows #260

Closed phpcss-ankue closed 11 months ago

phpcss-ankue commented 11 months ago

I wanted to upgrade my cakephp project (currently 4.4.18, I have updated dependencies to cakephp 4.5.0) using rector (0.16.0) on Windows cmd. When running bin\cake upgrade rector --rules cakephp45 "<path\to\app> I receive the error: 'The command "C:\Program" is either misspelled or could not be found.'. Nevertheless, 'Rector applied successfully' is displayed but no changes are made to the src code. I am running current php v8.2.11. I have installed upgrade tool as described under 4.0 Upgrade Guide - 4.x

ndm2 commented 11 months ago

Sounds like you're using a non-quoted path that contains spaces, eg

C:\Program Files\...

instead of

"C:\Program Files\..."

garas commented 11 months ago

While Upgrade tool can be fixed to escape $cmdPath here, Rector will fail to load --autoload-file or --config files anyway.

Both your project and Upgrade tool must in paths without whitespace.

https://github.com/cakephp/upgrade/blob/b17922a405380dcab3656601b376d9cf3c59b194/src/Command/RectorCommand.php#L84-L92

phpcss-ankue commented 11 months ago

Thank you for the fast replies. I have thought about this, the paths I am using are: cake upgrade rector --rules cakephp45 "C:\users\myusername\source\repos\pld\src" The upgrade tool lies in: C:\users\myusername\source\repos\upgrade. There is no whitespace. I assume that some file is called that is supposed to lie in one of the paths but is absent and cmd is searching at C:\Program Files (which is not escaped). I could not find which one, though.

garas commented 11 months ago

You can run bin/cake upgrade rector with --verbose to see what command is used to run Rector. Then run that vendor/bin/rector process with --debug to see what Rector does when it fails.

phpcss-ankue commented 11 months ago

I have just run rector process --autoload-file="C:\Users\myusername\source\repos\pld/vendor/autoload.php" --config="C:\Users\myusername\source\repos\upgrade/config/rector/cakephp45.php" "C:\Users\myusername\source\repos\pld\src" --debug in C:\Users\myusername\source\repos\upgrade\vendor\bin>. Still only the notification: 'The command "C:\Program" is either misspelled or could not be found.' Add: also running the rector process explicitly as C:\Users\myusername\source\repos\upgrade/vendor/bin/rector process ... does not help.

garas commented 11 months ago

Rector uses composer/xdebug-handler to restart process without XDebug. But xdebug-handler fails to escape command. Your php.exe is likely in C:\Program Files.

To disable restart, either run Rector with --xdebug or add environment variable RECTOR_ALLOW_XDEBUG:

phpcss-ankue commented 11 months ago

Thank you! That solved the issue. Ran smoothly setting the environment variable.