Codebase Upgrades

Any time there is a major change in any of my codebases, I will be reporting the changes and best migration path.

1) Upgrading AjaxHandler v1.6 to v2

The AjaxHandlerComponent has upgraded major versions from 1.6 (CakePHP 1.3) to 2.0 (CakePHP 2). Since this is not a backwards compatible change, the 2.0 version can only be used in CakePHP 2. During the conversion process, many other features were refactored or removed, here is a quick round-up.

No more automatic data gathering

In the older versions, any request data was gathered and merged into the Controller::$data property within AjaxHandler::startup(). This is no longer the case as I highly suggest using the new CakeRequest class to manipulate data in your AJAX action. This class can be accessed at Controller::$request.

No more content type restrictions

Previously you could only respond() an action using JSON, HTML, XML or text. Now you can respond using any content type defined in CakeResponse. Automatic JSON/XML formatting is still enabled.

Removed the valid() method

The valid() method was a very abstract and useless method that simply checked that strings or integers were not empty. The AjaxHandler should not be dealing with any validation (low level ones even more so), so it was removed. Please integrate your own data validation.

Besides the major changes listed above, any private class properties were converted to protected visibility, to allow class extension and the RequestHandler was replaced with CakeRequest in most situations, ala is('ajax') compared to isAjax().

If you have any questions, let me know!

2) Upgrading AutoLogin v2.2 to v3

The AutoLogin component has upgraded major versions from 2.2 (CakePHP 1.3) to 3.0 (CakePHP 2), now 3.1. Since this is not a backwards compatible change, the 2.0 version can only be used in CakePHP 2. During the conversion process, many things had to change to support the new AuthComponent.

No more automatic username/password field detection

Previously AutoLogin would detect the custom name of your username and password fields by accessing Auth::$fields. Since that property has been removed in favor of Auth::$authenticate, the AutoLogin component received a new property called $fields which mimicked what the Auth's version did. I didn't want to magically guess what the username and password is from Auth::$authenticate and be wrong, so I made it an optional property (you should only need to change it if you are using custom fields).

$this->AutoLogin->fields = array('username' => 'user', 'password' => 'pass');

Seeing as how that was the only major change that may require backwards support, the following minor changes have also occurred: CakeRequest has been implemented anywhere $params were being referenced, the user model is detected via Auth::$authenticate (all first, then Form) in place of the deprecated Auth::$userModel and cookie support has been implemented for localhost environments (may not work in all environments).

If you have any questions, or run into any problems, let me know!

3) Upgrading Uploader v2.8 to v3

The Uploader plugin has upgraded major versions from 2.8 (CakePHP 1.3) to 3.0 (CakePHP 2). Since this is not a backwards compatible change, the 3.0 version can only be used in CakePHP 2.

No more UploaderComponent

During the conversion process, the primary change is that the UploaderComponent was removed and turned into a stand-alone vendor class. This was done to further encourage the use of the AttachmentBehavior. Because of this change, you will need to manually initialize the Uploader in your Controller::beforeFilter() (only if you were using the component). The property settings are now passed as an array through the constructor.

// Before
public function beforeFilter() {
	$this->Uploader->tempDir = TMP;
}

// After
public function beforeFilter() {
	$this->Uploader = new Uploader(array('tempDir' => TMP));
}

By instantiating the class to $this->Uploader, all of the old code should still work as normal. This change also allows the possibility to use the Uploader anywhere in the application.

No more S3TransferComponent

The S3TransferComponent was trying to do something it shouldn't have. The component was removed in favor of the Vendor/S3 class that provides far more functionality. The AttachmentBehavior has also been updated to use the S3 class instead of the component.

Certain methods are now static

The bytes(), addMimeType(), checkMimeType(), mimeType() and ext() methods are now static.

Those should be the only changes you would need to make to support the new version. There are quite a few other changes, so be sure to check out the changelog and to also check out the updated documentation.

4) Upgrading Forum v2.x to v2.2

In the newest 2.2 version of the Forum plugin, a subscription system was added. This system allows for users to subscribe to topics and forums and then receive email notifications at specific intervals. This feature required minor database changes so a new upgrade shell was added to handle this. You will only need to run the upgrade shell if you are upgrading from 2.0 or 2.1. If you are doing a fresh install, you can ignore this post and the upgrade shell.

Begin by downloading the latest 2.2 tag and uploading and overwriting the older version. Your forum will be broken until you run the upgrade shell and the following command. Once the command is executed, simply follow the on-screen instructions.

cake -app /path/to/app upgrade
Setting up the subscription notification cron

For the subscription emails to be sent out, the subscription shell will need to be triggered. The best way to accomplish this is to setup a cron job to be triggered every 24 hours (or another time of your liking). If you are unable to setup a cron job, you will need to disable the subscription system via the forum admin settings.

0 0 * * * /path/to/cake/console/cake -app /path/to/app subscription

By default the shell will find all new activity within the past 24 hours via the database timestamp (which is separate from the cron interval time). You can change this using the timeframe parameter. For example, if you want to send emails every hour instead of every 24 hours (quotes are required).

0 * * * * /path/to/cake/console/cake -app /path/to/app subscription -timeframe "1 hour" 

Hopefully this small guide helps you upgrade to 2.2, enjoy!