[FuelPHP]taskとして作ったバッチはサブディレクトリで管理可能?

FuelPHPでは、バッチ処理をtaskのしくみで実行することができます。
インストール直後では、robotsというサンプルスクリプトがおいてあり、下記のコマンドで実行可能です。

php oil refine robots



プログラムは、fuel/app/tasksの下で管理するのですが、タスクの数が多くなるとサブディレクトリを作って管理したくなります。
ですが、FuelPHP1.8以下のバージョンでは、taskをサブディレクトリに格納することはサポートされていないようです。

FuelPHPの掲示板でも以下のようなやり取りがあり、FuelPHPの2.0で改善予定だそうです。

We have quite a lot of app/tasks/ and want to organize them a bit,
 so we need to put oil refine tasks in subfolders,
But we didnt figure out how to call them. We put task class file in 
fuel/tasks/sub/task.php:
...




No, this is currently not supported. Tasks don't follow the rules of 
the autoloader, they are loaded hardcoded. This will be remedied in 2.0.


by http://fuelphp.com/forums/discussion/8297/subfolders-in-oil-refine-is-it-possible


ちなみに、oil refineの処理は下記場所で実装されています。あまり良い対応のしかたではありませんが、Find the taskのコメントがある箇所付近を修正すればカスタマイズできるかも…です。

/fuel/packages/oil/classes/refine.php

class Refine
{
	public static function run($task, $args = array())
	{
		...
 
		// Find the task
		if ( ! $file = \Finder::search('tasks', $task))
		{
			$files = \Finder::instance()->list_files('tasks');
			$possibilities = array();
			foreach($files as $file)
			{
				...





ちなみに、oil refineコマンドで実行可能なタスク(=FuelPHPに認識してされているタスク)は、以下のようにhelpコマンドで確認できます。

php oil refine help

Usage:
    php oil [r|refine] <taskname>
 
Description:
    Tasks are classes that can be run through the the command line or set up as a cron job.
 
Available tasks:
    php oil refine robots
    php oil refine robots:protect
    php oil refine fromdb
    php oil refine fromdb:help
    php oil refine fromdb:scaffold
    php oil refine fromdb:model
    php oil refine fromdb:migration
    php oil refine install
    php oil refine migrate:help
    php oil refine session
    php oil refine session:create
    php oil refine session:remove
    php oil refine session:clear
    php oil refine session:help
 
Documentation:
    http://docs.fuelphp.com/packages/oil/refine.html





はじめてのフレームワークとしてのFuelPHP 改訂版

関連記事

コメントを残す

メールアドレスが公開されることはありません。