mult1mate\crontab\TaskManager::editTask PHP Method

editTask() public static method

Edit and save TaskInterface object
public static editTask ( mult1mate\crontab\TaskInterface $task, string $time, string $command, string $status = TaskInterface::TASK_STATUS_ACTIVE, string $comment = null ) : mult1mate\crontab\TaskInterface
$task mult1mate\crontab\TaskInterface
$time string
$command string
$status string
$comment string
return mult1mate\crontab\TaskInterface
    public static function editTask($task, $time, $command, $status = TaskInterface::TASK_STATUS_ACTIVE, $comment = null)
    {
        if (!($validated_command = self::validateCommand($command))) {
            return $task;
        }
        $task->setStatus($status);
        $task->setCommand($validated_command);
        $task->setTime($time);
        if (isset($comment)) {
            $task->setComment($comment);
        }
        $task->setTsUpdated(date('Y-m-d H:i:s'));
        $task->taskSave();
        return $task;
    }

Usage Example

 public function testEditTask()
 {
     $task = TaskMock::createNew();
     $command = 'ActionMock::method()';
     $task = TaskManager::editTask($task, '* * * * *', $command, TaskInterface::TASK_STATUS_ACTIVE, 'comment');
     $this->assertEquals($command, $task->getCommand());
     $command = 'wrong_command';
     $task = TaskManager::editTask($task, '* * * * *', $command, TaskInterface::TASK_STATUS_ACTIVE, 'comment');
     $this->assertNotEquals($command, $task->getCommand());
 }
All Usage Examples Of mult1mate\crontab\TaskManager::editTask