1

How am I able to get or set additional properties on a Task model inside a plugin. Eventually I would like to influence the Totalsteps of a task.

$task = craft()->tasks->createTask('Reroute', 'Importing routes', array(
    'files' => $files,
    'steps' => count($files)
));

class RerouteTask extends BaseTask
{
    public function getTotalSteps()
    {
        return $this->getSettings()->steps;
    }

Is resulting in Craft\TaskModel.steps is not defined. What am I missing here?

1 Answer 1

2

Have you defined the settings and their type in your Task file?

I've had success using the array of things passed to the task to set the total steps like so:

class RerouteTask extends BaseTask
{

  protected function defineSettings()
  {
    // Files passed from controller
      return array(
        'files' => AttributeType::Mixed,
      );
  }

  public function getTotalSteps()
  {
    return count( $this->getSettings()->files );
  }

Then inside a controller you create the task.

$task = craft()->tasks->createTask('Reroute', 'Importing routes', array(
  'files' => $files
));
1
  • Thanks that did the trick. However i find it strange why it didn't work with public properties and trying to set them like $task->property = "test" i am pretty new to this but that seems like normal OOP if you would like can you explain this behavior?
    – Jacob
    Commented May 24, 2016 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.