Ask your Symfony questions! Pay money and get answers fast! (more info)

[pakeException] Task is not defined. Symfony

  • SOLVED

I'm working on an old site that runs Symfony 1.0

2 weeks ago I wrote a script to import some data from one database to another database. The script worked, and the data was imported. Now I want to run it again, but the script won't work. If I do this:

symfony batch/import_data.php

I get:

[pakeException] Task "batch/import_data.php" is not defined.

I also tried this:

symfony import_data.php

But I got the same error.

I ran "symfony cc" and tried again, but I got the same error.

The other programmers who are working on this project have been making a lot of changes to the configuration, so I am thinking possibly they made a change that is causing this to fail? Does anyone have any ideas where I should start to look?

Answers (3)

2010-04-16

Arturo Linares answers:

If it is a task, it should live in lib/task/YourTask.class.php (for sf1.1 and above) but for 1.0 you can execute it like:

php batch/import_data.php

Check your script has the front controller information in the header, something like:

define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
define('SF_APP', 'frontend');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

2010-04-16

Martin Palacio answers:

is your import_data.php a symfony task or just a plain php script?
If the latter is correct, try:


cd [/your/script/folder]
php import_data.php


Martin Palacio comments:

EDIT: Sorry, Arturo already say that...

2010-04-17

Jakub Zalas answers:

You tried to pass a script path as an argument to symfony command. You should've used name of the task intead. Run 'symfony' in your project directory to list all available tasks.

Also, if you edit your script you'll notice that tasks are really simple functions. Before each one there should be two pake calls: pake_task() and pake_desc(). First defines task name which you can use if you want to run it through symfony.

Example task:


pake_task('import-data');
pake_desc('Imports data');

function run_import_data($task, $args)
{
echo 'hello!';
}


You can run it with:


symfony import-data


I'm not sure if your scripts are built this way but this is how it was done in symfony 1.0. It looks like you have simple php scripts there which can be run by php command. Tasks need to be put into plugins in symfony 1.0 (i.e. plugins/myTaskPlugin/data/tasks/myPakeMyTask.php). Otherwise symfony won't find them.