Over the past year and a bit I have been working with Monash University to develop a web based learning tool for their School of Pharmacy. The project is called “MyDispense” and after some initial twists and turns working out which tools we were going to use to deliver the job, our team eventually settled on the CakePHP Framework (version 1.3) 😀

Eventually the project hit a third development cycle and this coincided with the CakePHP team’s stable release of version 2.0. We were planning some much needed refactoring and D.R.Ying up anyway and naturally wondered if we should move the app to the new version of the framework while we were at it? There were of course some nice new things in CakePHP 2.0 that looked good, not to mention it was considered faster due to the lazy loading of models and removal of php4 support. So we thought what the hell and made the choice to move to CakePHP 2.0. A couple of small gotcha road bumps did crop up due to some differences in Cake 2.0 and 1.3 but they were quite easy to solve as you will see.

Okay so we made the decision but where do we start? Of course we started with some google searches 😛 We looked for tutorials on the web. Some advice from brave peepz that have gone before us and might save us some time and headaches. There wasn’t much out there saying people had trouble so that was a good sign.

Our first port of call was the CakePHP 2.0 Migration Guide, for obvious reasons 😛

I read this page and of course got to the “file names” section and my first thought was … “f#@k we were going to have to modify quite a few folders and file names for this migration”. My second thought.. “erm.. wait a tick… doh! Why don’t we just use the ‘bake’ tool from the Cake Console and bake it all out?” So my colleagues and I stripped the database of unwanted tables and redundant stuff and set to the task of baking out the models, views, admin views and the controllers using the console in Cake 2.0.

One little “gotcha” for me using the bake command in 2.0 was “which directory I should execute the “cake bake” command from?”. After a little bit of head scratching I realised you should do this from the “app” directory as your working directory. I would ssh to my “app” directory on my development setup and type “Console/cake bake”. This produced the familiar interface for selecting what I wanted to “bake” without throwing any errors and of course would put the new files in the correct Model, View and Controller directories in my application.

The next “gotcha” was in regards to the way MyDispense’s dynamic PNG images were displayed in the browser. Some changes to the way that the CakeResponse api works required us to add the “$this->response->send();” call after after setting the PNG image header. In version 1.3 of Cake this wasn’t a requirement.

<?php
 $response->header(array('Content-type: image/png'));
 $this->response->send();
?>

Another issue that came from the move (which we should have checked earlier really) was that some of the older components we relied on in the version 2 of MyDispense was build for the old CakePHP architecture and had not been brought up to date. The first of these was the CAS Auth component we found here. If we had time I would have modified the existing component into one that 2.0 can use but unfortunately this was not possible. Instead I came up with what I think is a more flexible solution using phpCAS directly. I will blog about this process soon.

So in the end quite a painless process and moving a cake app for 1.3 to 2.0 was worth. If you have the time I recommend doing it. Our application is measureably faster and happier for it 😀