Silverstripe function execution via cronjob

Hi, I want to execute a function via cronjob to start importing csv. Currently, import is started by accessing the controller in the tld.de/Update browser

The controller has this code http://pastie.org/8351266

How can I execute the init () function via cronjob?

thanks!

+4
source share
5 answers

In SilverStripe, you can access any route that is accessible via HTTP by also running cli- script.php on the command line

Also exists sake, which is just a bash shell around cli- script.php (but you need to install sake)

, ( dev/build):

php framework/cli-script.php dev/build
sake dev/build

. ussage of silverstripe: http://doc.silverstripe.org/framework/en/topics/commandline


( ) silverstripe , (cronjob)

, Page_Controller ( SiteTree Model), ( URL- CMS). , URLSegment about:

class Page_Controller extends ContentController {
    private static $allowed_actions = array('something');
    public function init() {
        // the init method will run before every action
        // this means this code will run, no matter if you visit /about or /about/something
    }
    public function index() {
        // this is the default action (this code is optional and can be removed), 
        // and will be called if you visit website.com/about
        return $this;
    }
    public function something() {
        // this is the somethingaction, 
        // and will be called if you visit website.com/about/something
        // do something here
        return $this;
    }
}

run index():

php framework/cli-script.php about

something():

php framework/cli-script.php about/something

: init URL-, "", | : , index(), $allowed_actions ( , $allowed_actions = flush = 1, )

: , :

, , $Action , something()

+5

Silverstripe. curl URL- cronjob, :

0 0 * * * curl --silent http://tld.de/Update

- Silverstripe . , :

class YourTask extends BuildTask {
    public $description = "...";
    //...
    public function run($request) {
        YourController::init();
    }
}

:

0 0 * * * /path/to/framework/sake dev/tasks/YourTask
+5

? ( , )

<?php
    class ArticleCsvUpdateTask extends BuildTask {

    protected $title = 'Article Csv Update';

    protected $description = 'Build task for article Csv update';

    public function run($request) {
        $loader = new ArticleCsvBulkLoader('Color');
        if($loader->load('import-new.csv')) {
            $loader->load('import-new.csv');
        } 
    }
}

, " yoursite/dev/tasks/ArticleCsvUpdateTask", , " php framework/cli- script.php dev/tasks/ArticleCsvUpdateTask" " //ArticleCsvUpdateTask" ( ).

, , , cron silverstripe.

+2

. Zauberfisch

Silverstripe, , init HTTP-.

silverstripe docs, URL :

php framework/cli-script.php Update/init

sake .

+1

, php , :

#!/usr/bin/env php
<?php

require_once "/path/to/your/class/Update.php";
$class = new Update();
$class->init();

chmod 755 consolefile

, , script cronjob

0

All Articles