Rector to Upgrade Bootstrap

I read the upgrade cake5 guide. I upgraded from 4.5 → 5.0 and had this error when trying to bake a model

ubuntu@ip-172-31-5-93:/var/www/html/test1$ bin/cake bake model -v --no-test --no-fixture Areas
PHP Fatal error:  Uncaught Error: Call to undefined function env() in /var/www/html/test1/config/app.php:20
Stack trace:
#0 /var/www/html/test1/vendor/cakephp/cakephp/src/Core/Configure/Engine/PhpConfig.php(84): include()
#1 /var/www/html/test1/vendor/cakephp/cakephp/src/Core/Configure.php(346): Cake\Core\Configure\Engine\PhpConfig->read()
#2 /var/www/html/test1/config/bootstrap.php(83): Cake\Core\Configure::load()
#3 /var/www/html/test1/vendor/cakephp/cakephp/src/Http/BaseApplication.php(183): require_once('...')
#4 /var/www/html/test1/src/Application.php(69): Cake\Http\BaseApplication->bootstrap()
#5 /var/www/html/test1/vendor/cakephp/cakephp/src/Console/CommandRunner.php(190): App\Application->bootstrap()
#6 /var/www/html/test1/vendor/cakephp/cakephp/src/Console/CommandRunner.php(137): Cake\Console\CommandRunner->bootstrap()
#7 /var/www/html/test1/bin/cake.php(12): Cake\Console\CommandRunner->run()
#8 {main}
  thrown in /var/www/html/test1/config/app.php on line 20

After troubleshooting, I found that I needed to update the bootstrap.php file with this line

/**
 * Load global functions.
 */
require CAKE . 'functions.php';

Shouldn’t this be done using the upgrade tool ?

The upgrade guide explicitly says at the bottom that you have to compare your app template with the current state of the app template.

This is not something we can easily do with the rector tool.

1 Like

Yes, I saw that part. I wasn’t so sure what the template files were.

Are they all the files in the config folder (e.g. bootstrap.php, app.php) ?

There aren’t that many files in the app template, so I’d just recommend you invest the 15 minutes and compare each file from the app template with your own app and copy things over if they are missing.

I guess the fastest way is to copy the app-template files into phpstorm, and compare (control+D) them. 15 minutes would not be enough for all the files in here: GitHub - cakephp/app: CakePHP application template

I think this part needs improvement, especially when cakephp files on my server and needs to be updated 1-by-1.

if you know when you created your cakephp app you can also open the compare tool in github and just apply these changes

this is just how it works because this is an app template which gets created at the spot when you execute composer create-project --prefer-dist cakephp/app

If you can think of a better way to get an (automated) update process working for such file changes please feel free to create a github issue.