When CakePHP release a new version, you just need to update your cake dir with the new files, and, most of the times, everything works properly. However, sometimes your testing cases will miss some bugs and they will get to production. So, we must go back to the previous cake’s version until the bug is solved. This rollback process could be a problem because replacing the cake core dir could take a couple of minutes and the bugs are still there.

First solution attempt

We can have several folders with the framework, one called cake with the current version (the one that will be used by our app) and some other folders with the previous versions, i.e. cake-1.2.5, cake-1.3.2, etc. So, each time you need to go back to a previous version, you just have to rename the folders.

This solution has its downsides

  • To rename the directories is a manual task done outside the automated deployment process.
  • The cake core is not a piece of code maintained by us and it’s usually left out of the app’s repository. Therefore, each time you modify the cake folder you have to let know the rest of the team so everybody work at the same conditions.
  • We have to keep an eye on the .gitignore file in order to keep new versions of cake out of the version control repository.
  • If someone makes a checkout of our app, he/she won’t find any information about the cake’s version needed to run the code.

Solution

We create the following folder structure

  • app
  • cakeversions
    • 1.2.5
      • cake
    • 1.3.2
      • cake

The cakeversion folder will contain every version of CakePHP that our app had needed at some time and it should be ignored by Git. The folders named cake inside each version folder are necessary because the framework requires that the core lays inside a directory called exactly cake.

The next step would be to edit the file app/webroot/index.php, so the app uses the new location. This line:

define('CAKE_CORE_INCLUDE_PATH', ROOT);

Sould be replaced by this one:

define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'cakeversions' . DS . '1.3.6');

Now, whenever we need to change the version of cake, we only have to edit the number on this line. The file app/webroot/index.php is part of the Git repository, so the change of version will be implemented in production in the next deploy. Also, the rest of the team will have it updated in the next fetch or pull they perform.