Upgrade Tool

Upgrading to CakePHP 3 from CakePHP 2.x requires a number of transformationsthat can be automated, such as adding namespaces. To assist in makingthese mechanical changes easier, CakePHP provides a CLI based upgrade tool.

Installation

The upgrade tool is installed as a standalone application. You’ll need to clonethe upgrade tool with git, and install the dependencies with composer:

  1. git clone https://github.com/cakephp/upgrade.git
  2. cd upgrade
  3. php ../composer.phar install

At this point you should be able to get the help for the upgrade tool:

  1. cd upgrade
  2. bin/cake upgrade --help

The above should output something like the following:

  1. Welcome to CakePHP v3.0.8 Console

App : src

Path: /Users/markstory/Sites/cake_plugins/upgrade/src/

A shell to help automate upgrading from CakePHP 2.x to 3.x. Be sure to
have a backup of your application before running these commands.

Usage:
cake upgrade [subcommand] [-h] [-v] [-q]

Subcommands:

locations Move files/directories around. Run this before
adding namespaces with the namespaces command.
namespaces Add namespaces to files based on their file path.
Only run this after you have moved files.
app_uses Replace App::uses() with use statements
rename_classes Rename classes that have been moved/renamed. Run
after replacing App::uses() with use statements.
rename_collections Rename HelperCollection, ComponentCollection, and
TaskCollection. Will also rename component
constructor arguments and _Collection properties on
all objects.
method_names Update many of the methods that were renamed during
2.x -> 3.0
method_signatures Update many of the method signatures that were
changed during 2.x -> 3.0
fixtures Update fixtures to use new index/constraint
features. This is necessary before running tests.
tests Update test cases regarding fixtures.
i18n Update translation functions regarding placeholders.
skeleton Add basic skeleton files and folders from the "app"
repository.
prefixed_templates Move view templates for prefixed actions.
all Run all tasks except for skeleton. That task should
only be run manually, and only for apps (not
plugins).

To see help on a subcommand use cake upgrade [subcommand] --help

Options:

—help, -h Display this help.
—verbose, -v Enable verbose output.
—quiet, -q Enable quiet output.

Usage

Once you have correctly installed the upgrade tool, you are ready to start usingit on a 2.x application.

Warning

Make sure you have backups/version control for your application’s code.

It is also a good idea to make a backup/commits after each sub-command.

To start off run the locations command:

  1. # View the options for the command
  2. bin/cake upgrade locations --help
  3.  
  4. # Run the command in dry run mode.
  5. bin/cake upgrade locations --dry-run /path/to/app

The above will give a dry run output of what would happen. When you are ready torun the command for real, remove the —dry-run flag. By using the —gitflag the upgrade tool can automate moving files in git.

Once file locations have been updated, you can add namespaces to your code usingthe namespaces command:

  1. # View the options for the command
  2. bin/cake upgrade namespaces --help
  3.  
  4. # Run the command in dry run mode
  5. bin/cake upgrade namespaces --dry-run /path/to/app
  6.  
  7. # Run the command for real
  8. bin/cake upgrade namespaces /path/to/app

After these two commands, you can run the remaining subcommands in any order.