Skip to content
This is the documentation for pieceofcake2/upgrade, a CakePHP 2.x plugin for pieceofcake2/cakephp. About this fork.

Upgrade Documentation ​

The Upgrade plugin provides the upgrade console shell, which automates most of the mechanical changes needed to upgrade a CakePHP 1.3 application to CakePHP 2. It runs on pieceofcake2/cakephp. It also moves an application or a plugin to the CakePHP 5 layout of pieceofcake2/app and to namespaced classes, and updates code for the changes of pieceofcake2/cakephp with Rector.

IMPORTANT

The shell moves and rewrites your files. Back up your application, or commit it to Git, before you run it, and try --dry-run first.

Installation ​

Install the plugin with Composer as a development dependency:

bash
composer require --dev pieceofcake2/upgrade

The plugin has the cakephp-plugin type, so it is installed into your plugins directory by composer/installers. Set installer-paths in your application's composer.json so it is installed into the right place:

Layoutinstaller-paths
Modern (config/, src/, templates/, plugins/)"plugins/{$name}/": ["type:cakephp-plugin"]
Legacy (app/Config/, app/Plugin/)"app/Plugin/{$name}/": ["type:cakephp-plugin"]

Load the plugin in config/bootstrap.php (legacy layout: app/Config/bootstrap.php). If you already use CakePlugin::loadAll(), this is not necessary:

php
CakePlugin::load('Upgrade');

Running the Shell ​

Run the shell with bin/cake (legacy layout: app/Console/cake):

bash
# Run all upgrade commands
bin/cake upgrade all

# See what would be changed without changing anything
bin/cake upgrade all --dry-run

# Run a single command
bin/cake upgrade locations

Run it from the directory of the application you upgrade, with that application as the console's application (APP): locations moves folders relative to the current directory, and the other commands rewrite the PHP files of the application, or of the plugin given with --plugin.

Commands ​

CommandDescription
allRun all the other commands.
testsRename test classes from FooTestCase to FooTest.
locationsMove files and folders to their CakePHP 2 locations (config to Config, models to Model, views to View, tests/cases to Test/Case, and so on), including the plugins in plugins/.
i18nUpdate the calls of the translation functions: __('text', true) becomes __('text'), and calls that printed directly get an echo.
helpersUpdate the calls to helpers in views to $this->Helper.
basicsReplace removed functions of basics.php with native PHP functions.
requestReplace the removed request properties ($this->data, $this->params, ...) with $this->request.
configureReplace Configure::read() with Configure::read('debug').
constantsReplace obsolete constants such as CONFIGS and CONTROLLERS with paths built from APP.
controller_redirectsAdd return to $this->redirect() calls in controllers.
componentsMake components extend the Component class.
exceptionsReplace cakeError() calls with exceptions.
rectorRun a set of Rector rules for a change of pieceofcake2/cakephp. Not part of all: see Rector Rules.
layoutMove an application from the CakePHP 2 layout (app/Config/, app/Controller/, ..., or Config/, Controller/, ... in the root) to the layout of pieceofcake2/app (config/, src/, templates/, ...), or the configuration, templates, translations and tests of a plugin. Not part of all: see Layout and Namespace.
namespaceMove the classes of an application or a plugin into a namespace (App\, or the name of the plugin), with App.namespace and PSR-4. Not part of all: see Layout and Namespace.

Options ​

OptionDescription
--plugin, -pUpdate only the given plugin.
--ext, -eExtensions of the files to update: a pipe-delimited list or a preg_match() compatible subpattern (default: php|ctp|thtml|inc|tpl).
--git, -gMove files with git mv, so that Git keeps their history. The current directory must be a Git repository.
--dry-run, -dShow the changes without modifying any file.

Rector Rules ​

The rector command runs a set of Rector rules on the directories or files that you give, for a change of pieceofcake2/cakephp that your code must follow. It is not part of all, which upgrades from CakePHP 1.3.

bash
# See the changes
bin/cake upgrade rector --rules variadic-arguments src tests --dry-run

# Apply them
bin/cake upgrade rector --rules variadic-arguments src tests
OptionDescription
--rules, -rThe set of rules, a file of config/rector/ of the plugin (default: variadic-arguments).
--dry-run, -dShow the changes without modifying any file.
--no-short-namesclass-name-strings: keep the short names, see class-name-strings.

The rules list the places that they leave for a review after the changes, under Review these places:.

variadic-arguments ​

pieceofcake2/cakephp declares the variable arguments of some methods as variadic parameters instead of reading them with func_get_args(), e.g. Model::query($sql, ...$params) (see the UPGRADE of pieceofcake2/cakephp for the list). PHP refuses a method that overrides one of them with fewer parameters, so the rules add the same variadic parameter to the methods of your classes that override them:

php
// Before
class AppModel extends Model
{
    public function query($sql)
    {
        return parent::query(...func_get_args());
    }
}

// After
class AppModel extends Model
{
    public function query($sql, ...$params)
    {
        return parent::query($sql, ...$params);
    }
}
  • func_get_args() becomes the list of the parameters when they are all required. With an optional parameter, it stays: it leaves out the optional parameters that are not passed, so a list would pass their defaults instead. It returns the same values with the variadic parameter.
  • The variadic parameter takes the name of CakePHP, or another one when the method already has a parameter or a variable of that name.
  • The changed code also works with the versions of pieceofcake2/cakephp before the change, so you can run the rules before you update.

namespaced-classes ​

Since CakePHP 2.13, the classes of pieceofcake2/cakephp are in the Cake namespace, e.g. Cake\Controller\Controller, and their global names are aliases of the same classes. The global names keep working, so these rules are optional: they replace the global names in your code by the namespaced names, with use statements, and fix the comparisons of class names that get_class() breaks:

php
// Before
class PostsController extends AppController
{
    public function beforeFilter()
    {
        if (get_class($this->request) === 'CakeRequest') {
            $email = new CakeEmail('default');
        }
        if (get_class($this->response) === 'CakeResponse') {
            $this->set('plain', true);
        }
    }
}

// After
use Cake\Network\CakeRequest;
use Cake\Network\CakeResponse;
use Cake\Network\Email\CakeEmail;

class PostsController extends AppController
{
    public function beforeFilter()
    {
        if ($this->request instanceof CakeRequest) {
            $email = new CakeEmail('default');
        }
        // CakeResponse has subclasses in CakePHP
        if (get_class($this->response) === CakeResponse::class) {
            $this->set('plain', true);
        }
    }
}
  • The classes of CakePHP in code (extends, new, type declarations, static calls, instanceof, catch) and in docblocks get a use statement, e.g. @param Controller with use Cake\Controller\Controller;. A name stays fully qualified when its short name already names another class in the file. The result is the same whichever version of pieceofcake2/cakephp is installed.
  • A string with the global name of a class of CakePHP that is compared with the class of an object changes: get_class(), get_parent_class(), get_called_class(), $object::class or static::class, with ===, ==, !==, !=, in_array(), switch or match.
    • get_class($x) === 'CakeRequest' (also !==, ==, !=, $x::class and in_array(get_class($x), [...])) becomes $x instanceof CakeRequest when no class of CakePHP and no class of the processed code extends CakeRequest: instanceof then matches the same objects. The classes of other packages (vendor/) are not checked: if one of them extends the class, change the instanceof back to a comparison.
    • Otherwise, e.g. for Model, Component or CakeResponse, which other classes extend, it stays a comparison with ::class, get_class($x) === CakeResponse::class, which compares the same class as before; the command lists these places for a review. get_parent_class(), get_called_class(), static::class, switch and match always keep ::class.
  • Other strings (App::uses('Controller', 'Controller'), 'CakeRequest' passed to a method) and the classes of your application and of plugins (AppController, AppModel) are left as they are.
  • The changed code needs pieceofcake2/cakephp 2.13 or later. Run your code style fixer afterwards to sort the use statements.

class-name-strings ​

The settings of CakePHP 2 name their classes in strings: public $components = ['Auth']. These rules replace the class names by ::class, with use statements, so that the code names the classes that it uses:

php
// Before
public $components = ['Session', 'Auth' => ['authenticate' => ['Form']]];
public $uses = ['Post'];

Configure::write('Exception.renderer', 'AppExceptionRenderer');

// After
use App\Error\AppExceptionRenderer;
use App\Model\Post;
use Cake\Controller\Component\Auth\FormAuthenticate;
use Cake\Controller\Component\AuthComponent;
use Cake\Controller\Component\SessionComponent;

public $components = [SessionComponent::class, AuthComponent::class => ['authenticate' => [FormAuthenticate::class]]];
public $uses = [Post::class];

Configure::write('Exception.renderer', AppExceptionRenderer::class);
bash
bin/cake upgrade rector --rules class-name-strings src tests config
  • Only the places that take a class name change: $components, $helpers, $actsAs, $uses, $tasks, the associations of models (their keys, className and with, also of bindModel()), $viewClass, the Auth objects (authenticate, authorize, passwordHasher), the engine of Cache::config(), CakeLog::config(), the Session handler and the Text, Number and Time helpers, the datasource of DATABASE_CONFIG and ConnectionManager::create(), the transport of EmailConfig and CakeEmail::transport(), Exception.renderer, Error.handler and Exception.handler ('ErrorHandler::handleError' becomes [ErrorHandler::class, 'handleError'], also for the consoleHandler), Dispatcher.filters, Acl.classname, routeClass and Router::defaultRouteClass(), the viewClassMap of RequestHandlerComponent (its setting and viewClassMap()), Components->load(), Helpers->load(), Behaviors->load() (and attach()), loadModel() and ClassRegistry::init(). Other strings stay, e.g. $this->Paginator->paginate('Post').
  • A name becomes the class that CakePHP finds for it: the class of the application in App.namespace, the class of the plugin for 'Plugin.Name', or the class of CakePHP, in this order. Only namespaced classes are used, as CakePHP reads a class name without a backslash as a short name; names of global classes, and names that the processed code and CakePHP do not have, stay as they are. The rector command passes the App.namespace of the application.
  • A key with a className is an alias and stays: 'Mailer' => ['className' => 'Greeting'] becomes 'Mailer' => ['className' => GreetingComponent::class]. A class name as a key gets the short name as its alias, as before: AuthComponent::class is $this->Auth.
  • Full class names ('AppExceptionRenderer', 'DbAcl', the models 'Post') always change. Short names, to which CakePHP adds a suffix or a plugin ('Auth' for AuthComponent, 'DebugKit.Toolbar', 'Database/Mysql'), change too, unless you pass --no-short-names (or set $shortNames to false in a copy of config/rector/class-name-strings.php). CakePHP looks a short name up when the application runs, so an application or a plugin could replace the class of CakePHP by a class of the same name; ::class names one class for good.
  • The changed code needs pieceofcake2/cakephp 2.13 or later.

Layout and Namespace ​

The layout and namespace commands move an application or a plugin on pieceofcake2/cakephp to the CakePHP 5 layout of pieceofcake2/app, then its classes into a namespace. They are not part of all. Run them in this order, and check and commit the result of each one:

bash
# 1. The CakePHP 2 layout (app/Config/, app/Controller/, app/View/, ...) to config/, src/, templates/, ...
#    (without app/: Console/cake upgrade layout -root "$PWD" -app "$PWD", see below)
app/Console/cake upgrade layout --dry-run
app/Console/cake upgrade layout
composer dump-autoload

# 2. The classes into the App namespace
bin/cake upgrade namespace --dry-run
bin/cake upgrade namespace
composer dump-autoload

Run them from the root of the project, the directory that holds app/ or config/ (or Config/ and Controller/ for an application without app/). In a Git repository, the files move with git mv, so that Git keeps their history; elsewhere they move with rename(), and the command says so. A file is never overwritten: a move to an existing file is skipped and listed. --dry-run lists the moves and, for namespace, prints the changes as a diff, without changing anything.

OptionDescription
--plugin, -pChange the given plugin instead of the application.
--namespace, -nnamespace of an application: the namespace (default: App), e.g. --namespace Acme. A plugin always gets the namespace of its name.
--no-short-namesnamespace: keep the short names of the settings, see class-name-strings.
--dry-run, -dShow the moves and the changes without making them.

layout ​

An application moves from the CakePHP 2 layout to the layout of pieceofcake2/app:

FromTo
app/Config/config/
app/Controller/, app/Model/, app/Lib/, app/Console/Command/, app/Console/Templates/src/Controller/, src/Model/, src/Lib/, src/Console/Command/, src/Console/Templates/
app/View/Helper/ and the view classes of app/View/ (AppView.php)src/View/Helper/, src/View/
The templates of app/View/templates/
app/Locale/resources/locales/
app/Test/Case/, app/Test/Fixture/tests/TestCase/, tests/Fixture/
app/Plugin/<Name>/plugins/<Name>/
app/Vendor/vendors/, where App::import('Vendor', ...) finds the hand-copied libraries and which Composer does not manage
app/webroot/ (but index.php and test.php), app/tmp/logs/, app/tmp/webroot/, logs/, tmp/

The entry files of the CakePHP 2 layout define its paths, so the entry files of pieceofcake2/app replace them: config/define.php, bin/cake, webroot/index.php, webroot/test.php and webroot/.htaccess, and the directories of tmp/ and logs/, are created when they are missing, also in an application already in the new layout. The plugin ships copies of these files of pieceofcake2/app in resources/skeleton/, so the files do not depend on the version of pieceofcake2/app. An existing file is never overwritten. The files use the global names of the classes of CakePHP (ShellDispatcher, Dispatcher), which work in a global application; namespace imports them with use statements.

  • The constants of your own that the old entry files define (app/webroot/index.php, app/webroot/test.php, app/Console/cake.php), e.g. define('SITE_NAME', 'Blog'), are added to the new config/define.php, which all the entry files load. The constants of CakePHP 2 (ROOT, APP_DIR, WEBROOT_DIR, WWW_ROOT, CAKE_CORE_INCLUDE_PATH, ...) are not: the new files define them for the new layout, and Composer loads the core. A constant built on the path of the old file (__FILE__, __DIR__) or on the paths of the old layout (APP, APP_DIR, CAKE_CORE_INCLUDE_PATH), or defined under a condition other than if (!defined(...)), is listed for you to define by hand.
  • In a Git repository, the old entry files (app/webroot/index.php, app/webroot/test.php, app/Console/cake, cake.php and cake.bat) are removed with git rm; Git keeps them in its history, and refuses to remove a file with changes that are not committed, which then stays. Outside Git they stay, to be compared and deleted.
  • The entry files that the application already has are kept, and listed for you to review.

An application without app/, whose root is the directory app/ of CakePHP 2 (Config/, Controller/, View/, webroot/, ... next to composer.json), moves the same way from the root: Config/ to config/, Controller/ to src/Controller/, the templates of View/ to templates/, Locale/ to resources/locales/, Test/ to tests/, Plugin/ to plugins/, Vendor/ to vendors/ and tmp/logs/ to logs/. webroot/ and tmp/ stay.

  • The command tells the layouts apart by the names of the files, with their case. app/Config/ is the CakePHP 2 layout. Config/core.php or config/core.php with Controller/ and webroot/index.php is an application without app/. A directory whose composer.json has "type": "cakephp-plugin", or with Config/, Controller/, View/, ... but no core.php, is a plugin: run the command with --plugin from the application. config/ otherwise is the new layout.
  • Directories that are lowercase already (config/) stay. A rename of the case only (Config/ to config/) also works on a case-insensitive file system, such as the one of macOS, and Git records it. The lowercase vendor/ is the one of Composer and stays; Vendor/ moves to vendors/, unless it is the vendor-dir of composer.json.
  • Plugin/ moves to plugins/ with the plugins that Composer installed in it. Plugin/ is the default path of composer/installers for the plugins of CakePHP 2, so composer.json gets "installer-paths": {"plugins/{$name}/": ["type:cakephp-plugin"]} as in pieceofcake2/app, unless it sets a path for type:cakephp-plugin (then Plugin/{$name}/ becomes plugins/{$name}/). Run composer install afterwards.
  • The old webroot/index.php and webroot/test.php (they define APP_DIR or CAKE_CORE_INCLUDE_PATH and load no define.php) are at the place of the new ones: they are replaced when Git has their contents (tracked and committed), else they stay and are listed. Console/cake, cake.php and cake.bat are removed as above.
  • A Config/define.php in the old form (it defines CAKE_CORE_INCLUDE_PATH, or ROOT and APP_DIR for the old layout) is replaced by the config/define.php of pieceofcake2/app the same way, when Git has its contents. Its own constants are added to the new file, with those of the old entry files, and the ones built on the paths of the old layout or defined under a condition are listed. When it stays, it is listed with what to compare: the new entry files need ROOT (the root of the project), APP_DIR ('src'), WEBROOT_DIR, WWW_ROOT and VENDORS.
  • The entry files that the application already has in the style of pieceofcake2/app (a bin/cake or webroot/index.php that loads a define.php, a config/define.php like the one of pieceofcake2/app) keep their code, e.g. settings for AWS Lambda: only the paths of the moved directories in their strings change, e.g. dirname(__DIR__) . DS . 'Config' . DS . 'define.php' becomes dirname(__DIR__) . DS . 'config' . DS . 'define.php'.
  • The constants of the old entry files that are built on ROOT, which was the parent directory of the application, are listed too.
  • index.php and .htaccess in the root lead to webroot/ and stay: set the document root of the web server to webroot/, then delete them.

Run layout of such an application with -root and -app, from its root:

bash
Console/cake upgrade layout -root "$PWD" -app "$PWD"

The console of pieceofcake2/cakephp takes the directory of composer.json for the root of the project and looks for the application in its app/; -app "$PWD" tells it that the application is the directory itself. Without them, layout changes nothing and prints this command. You run the old console only once, for the move: afterwards, the bin/cake of the new layout works without options.

A plugin keeps its classes where they are, as the src/ of a plugin holds namespaced classes only (they move into src/ with namespace): Config/ moves to config/, the templates of View/ to templates/, Locale/ to resources/locales/ and Test/ to tests/.

The templates get the names that pieceofcake2/cakephp 2.13 reads in templates/, also in the directories of themes (Themed/<Theme>/) and of plugins (Plugin/<Plugin>/), and in a templates/ that already exists:

  • .ctp and .thtml become .php. The scaffold templates (Scaffolds/) keep .ctp, as ScaffoldView reads only .ctp.
  • Layouts/, Elements/, Emails/ and Errors/ become layout/, element/, email/ and Error/; the email layouts move from Layouts/Emails/ to layout/email/.

The paths of composer.json in moved directories follow them: the classmap, files, psr-0 and psr-4 paths of autoload and autoload-dev (app/Controller/ becomes src/Controller/), and extra.installer-paths (app/Plugin/{$name}/ becomes plugins/{$name}/). A path whose files moved to different places, such as app/ or app/View/, is listed for you to change.

What you do by hand, as the command lists it:

  • Compare the old entry files with the new ones for code of your own other than constants, and move it.

  • Delete the cache files in tmp/cache/, which hold the paths of the old layout. Run composer install when Plugin/ moved to plugins/.

  • Set the document root of the web server to webroot/: an index.php or .htaccess in the root of the project that leads to app/webroot/ is listed.

  • The files that do not move: app/index.php, app/.htaccess and the other files of app/. Install the libraries of vendors/ with Composer when they have a package.

  • Remove $ext = '.thtml' from your controllers and views when .thtml templates became .php.

  • Paths in your code (APP . 'Config' . DS, App::build()), in your web server configuration, in .gitignore (app/tmp/) and in your deployment are not changed. The lines of .gitignore that name moved paths are listed.

  • The texts and comments that name the old templates are not changed, as only you can tell what they mean: after the moves, the lines of templates/, config/ and src/ that name .ctp or .thtml files or the directories Layouts/, Elements/, Emails/ and Errors/ are listed as <file>:<line> for a review (a dry run lists them at the places of the files after the moves), e.g.

    text
    config/routes.php:29: * to use (in this case, templates/Pages/home.ctp)...
    templates/Pages/home.php:322: <li><?php echo __d('cake_dev', 'To change its layout, edit: %s.', '<code>templates/Layouts/default.ctp</code>'); ?></li>

    The templates of bake in src/Console/Templates/ keep .ctp and are not listed.

namespace ​

namespace needs the layout of pieceofcake2/app: it stops on the CakePHP 2 layout (app/Config/, Config/ or Controller/ in the root, or the Config/, Locale/, Test/ or templates of View/ of a plugin) and asks you to run layout first. The changed code needs pieceofcake2/cakephp 2.13 or later.

The command moves the files:

  • The class folders of a plugin (Controller/, Model/, View/, Console/, Lib/) move into src/.
  • src/Lib/<Type>/ moves to src/<Type>/ for the types of CakePHP (Cache, Configure, Console, Controller, Core, Error, Event, I18n, Log, Model, Network, Routing, TestSuite, Utility, View): namespaced code has no Lib, so src/Lib/Error/AppExceptionRenderer.php becomes App\Error\AppExceptionRenderer in src/Error/. A file directly in src/Lib/ stays, e.g. App\Lib\MyTool.
  • src/Lib/ is then removed when it holds nothing but placeholder files (empty, .gitkeep), with git rm in a Git repository, as in the skeleton of pieceofcake2/app. It stays with any other file.
  • A copy of a class of CakePHP in an application (a core class override, e.g. src/Lib/Routing/Dispatcher.php) moves to src/Cake/<path> (src/Cake/Routing/Dispatcher.php), keeps the namespace of CakePHP (Cake\Routing) and gets its class_alias(), as the files of CakePHP have. Compare it with the current file of CakePHP, as it may be a copy of an older version.

Then it changes the code with Rector:

  • The namespace of a class comes from the path of its file: App\Controller for src/Controller/, App\Test\TestCase\Controller for tests/TestCase/Controller/, App\Test\Fixture for tests/Fixture/, and <Plugin>\... in a plugin, as CakePHP looks plugin classes up as <Plugin>\<Type>\<Class>.

  • App::uses() is removed: Composer loads the classes.

  • The uses of the classes of the application and of CakePHP, in the code and in docblocks, get the namespaced names, with use statements; the global classes that the code and the docblocks use (PHP, other packages, AppController in a plugin) are imported too (use Exception;, use ArrayObject; for @param ArrayObject). A name stays fully qualified when its short name names another class, e.g. a class of the namespace of the file.

  • The strings that PHP reads as class names become ::class: class_exists(), is_a(), is_subclass_of(), method_exists(), new ReflectionClass(), the callables ['Class', 'method'] and 'Class::method' of call_user_func(), array_map() and the other functions, and the mocks and assertions of PHPUnit (getMock(), getMockBuilder(), assertInstanceOf(), expectException(), ...).

  • The comparisons with the class of an object, as namespaced-classes does them, for the classes of the application too.

  • The class names of the settings, as class-name-strings does them. Short names that App::className() resolves keep working when you pass --no-short-names.

  • config/, the entry files (bin/cake, the PHP files of webroot/) and the templates stay without a namespace, and get use statements for the classes of CakePHP and of the application that they name, e.g. use Cake\Core\Configure; for Configure::write(). The code does not change otherwise: only the names, with the class names of the settings. The use statements go after the docblock of the file, between blank lines.

  • The default files of config/ (email.php.default, database.php.default), which you copy to email.php and database.php, get the same changes as the files of config/, e.g. 'transport' => MailTransport::class, so that a new copy matches the changed configuration.

  • A template gets the use statements at the top, as in the templates of pieceofcake2/app, also for the classes of its docblocks (use Cake\View\View; for @var View $this): in its first block of PHP when it starts with one (after the docblock), else in a new block:

    php
    <?php
    use Cake\Core\Configure;
    ?>
    <h2><?php echo h($message); ?></h2>
    <?php if (Configure::read('debug') > 0) : ?>
        <?php echo $this->element('exception_stack_trace'); ?>
    <?php endif; ?>

    A template that names no class does not change. A class whose short name the template already uses for another class stays fully qualified.

  • In every file that the command changes, the use statements are sorted as the CakePHP coding standard expects (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses), with the use statements that the file had: by name, part by part and without case, the classes before the functions and the constants.

And the configuration:

  • config/core.php gets Configure::write('App.namespace', 'App'); with a short docblock, just before the docblock of App.encoding, as CakePHP 5 sets the namespace before the encoding. It must come before Cache::config('_cake_core_'), which runs while config/core.php loads and finds its engine with App::className(). Without an App.encoding line it goes before the first Cache::config(); without either, the command asks you to add it. When App.namespace is already set, nothing is added, and the command tells you when the value differs. The rest of config/core.php stays as it is.
  • composer.json autoloads App\ from src/ and App\Test\ from tests/ with PSR-4 (autoload and autoload-dev), instead of the classmap of these directories; a core class override adds src/Cake/ to the classmap and the file of CakePHP to exclude-from-classmap. The other entries and the formatting of the file stay. A plugin gets PSR-4 in its own composer.json, or in the one of the application when it has none.

Namespace the plugins of your application before the application: the class names of the settings of the application ('Blog.Comment') can then name the namespaced classes of the plugins.

What namespace does not change, as the command lists it or as you check it:

  • A file that also declares functions (a namespace would rename them), that has HTML outside the PHP tags or a declare block, or that is not valid PHP, stays global. So do the classes declared in more than one file: their uses in other files are not renamed.

  • Code outside the application or plugin that names its classes by their global names, e.g. an application that uses the classes of a plugin namespaced after it, and strings that are not listed above ('Post' in paginate(), which CakePHP reads as a model alias).

  • Data with the old class names: serialized objects in caches and sessions. Clear the caches.

  • The comments of config/ that name the classmap of Composer, composer dump-autoload or the paths of src/Lib/ that moved (src/Lib/Error, and src/Lib/ itself once it is removed) are listed as <file>:<line> for a review, e.g.

    text
    config/core.php:61: *   A custom handler class in src/ is autoloaded by the Composer classmap (run `composer dump-autoload`
    config/core.php:90: *   should place the file for that class in src/Lib/Error. This class needs to implement a render method.

Run composer dump-autoload and your tests afterwards, and review the changes with git diff.

After the Upgrade ​

The shell creates the CakePHP 2 directory layout that uses app/Config/, app/Controller/, app/View/ and so on. Review the changes, run your tests, and fix what the shell cannot convert automatically.

pieceofcake2/cakephp also supports a CakePHP 5-style layout (config/, src/, templates/). To move the upgraded application to it, run layout, and namespace for namespaced classes: see Layout and Namespace.

Origin ​

This package is based on the upgrade console shell of cakephp/cakephp (cakephp/cakephp on Packagist, last upstream version 2.10.24), originally by the CakePHP community (Cake Software Foundation, Inc.). It was extracted into a separate package and is maintained for CakePHP 2 on modern PHP by pieceofcake2. Changes from the original are listed in the commit history.

See LICENSE for copyright and license information. Not affiliated with the Cake Software Foundation.