Silverstripe Version 4.6.1:
How can I run a BuildTask task via the command line in SilverStripe 4?:
In the SilverStripe 4 documentation, it says I can extend the BuildTask class and call the task using cron in a unix commandline.
I’ve written a class called MyTask at app/src/Tasks/MyTask.php, like below:
use SilverStripe\Dev\BuildTask;
class MyTask extends BuildTask
{
private static $segment = 'MyTask';
protected $title = 'My Task';
protected $description = 'A task that I want to run via cron job';
protected $enabled = true;
public function run($request){
exit('Done run!');
}
}
After I dev/build?flush=1
I can run the task successfully via the URL at mysite.com/dev/tasks/MyTask
. But I can’t run it via the command line ./vendor/bin/sake dev/tasks/MyTask
Note: I can run ./vendor/bin/sake dev/tasks
via the command line, this shows me a list of Silverstripe’s build tasks, just not mine.
I’m clearly missing something, can anyone help with this?