Last week I wrote about the new command line features of CakePHP 1.2. And this week it is already outdated what I wrote then ;-) The command line scripts are now called “Shells” instead of “CakeScripts”, so I adapted the previous article to those changes.

With the recent changes a new concept has been introduced: Tasks. Well, tasks are not entirely new as tasks were already used by bake2 (which no longer exists). But now tasks are for shells what components are for controllers.

Tasks are placed in app/vendors/shells/tasks if they are application-specific resp. in vendors/shells/tasks if they are general-purpose tasks. Like shell scripts, task classes have to extend the “Shell” class, but the class name has to end with “Task”. Here a simple example of a task:

// vendors/shells/tasks/test.php
class TestTask extends Shell {

    function execute() {
        // do something
    }
}

In the core tasks (and in this test task) the main function is called “execute”, but you are free to use any name you want.

The test task can now be used in the shell script in the following way:

// vendors/shells/demo.php
class DemoShell extends Shell {
    var $tasks = array('Test');

    function initialize() {
        // empty
    }

    function main() {
        $this->Test->execute();
    }
}

Happy baking :)