Dave Perrett

Cake Actions From the Terminal

linux, php, programming, quickie, web

Edit app/webroot/index.php and change the lines that read like :

1
2
3
4
5
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
} else {
    $Dispatcher=new Dispatcher();
    $Dispatcher->dispatch($url);
}

to something like :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// if this is a favicon request, do nothing
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') :

// if this is a command line call, dispatch it with the argument
elseif (php_sapi_name() === "cli") :
    define('CRON_DISPATCHER',true);
    $Dispatcher=new Dispatcher();
    $Dispatcher->dispatch($argv[2]);

// dispatch normally
else :
    $Dispatcher=new Dispatcher();
    $Dispatcher->dispatch($url);
endif;

You can then call the action from the command line using something like :

1
$ php ./app/webroot/index.php /mailer/processIncomingMail

Check if the ‘CRON_DISPATCHER’ constant is set in your controllers if you need to know the origin of a request.

(courtesy of the bakery))