Book Image

CakePHP 2 Application Cookbook

Book Image

CakePHP 2 Application Cookbook

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Running cron shells


Another typical scenario to use CakePHP console shells is to implement a data warehouse and a time-intensive and recurring task.

In this recipe, we'll create a recurring job to calculate our package ratings, based on some complex logic.

Getting ready

For this recipe, we'll assume that you have a packages table and the related model that we created in our previous recipe. However, we'll also add a new column to store our ratings per package with the following SQL statement:

ALTER TABLE packages ADD rating INT(20) UNSIGNED NOT NULL DEFAULT '0';

How to do it...

Perform the following steps:

  1. First, create a file named RatingShell.php in app/Console/Command/ with the following content:

    <?php
    App::uses('AppShell', 'Console/Command');
    
    class RatingShell extends AppShell {
    
      public function main() {
        $this->out($this->getOptionParser()->help());
      }
    
      public function getOptionParser() {
        $parser = parent::getOptionParser();
        return $parser->description('Rating...