public function testGetTaskCrontabLine()
 {
     $task = TaskMock::createNew();
     $task->setStatus(TaskInterface::TASK_STATUS_INACTIVE);
     $task->setCommand('Class::method()');
     $task->setComment('comment');
     $task->setTime('* * * * *');
     $export = TaskManager::getTaskCrontabLine($task, 'path', 'php', 'index.php');
     $this->assertEquals("#comment\n#* * * * * cd path; php index.php Class method  2>&1 > /dev/null\n", $export);
 }
 public function taskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::find($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     if (!empty($_POST)) {
         $task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
     }
     $this->renderView('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder)));
 }
示例#3
0
 /**
  * Parses given command, creates new class object and calls its method via call_user_func_array
  * @param string $command
  * @return mixed
  */
 public static function parseAndRunCommand($command)
 {
     try {
         list($class, $method, $args) = TaskManager::parseCommand($command);
         if (!class_exists($class)) {
             TaskLoader::loadController($class);
         }
         $obj = new $class();
         if (!method_exists($obj, $method)) {
             throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
         }
         return call_user_func_array(array($obj, $method), $args);
     } catch (\Exception $e) {
         echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
         return false;
     }
 }
 public function taskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findByPk($_GET['task_id']);
     } else {
         $task = Task::createNew();
     }
     /**
      * @var Task $task
      */
     if (!empty($_POST)) {
         $task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
     }
     $this->load->view('tasks/task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods($this->controller_folder)));
 }
 public function actionTaskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findOne($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     $post = \Yii::$app->request->post();
     if ($task->load($post) && $task->validate()) {
         $task = TaskManager::editTask($task, $post['Task']['time'], $post['Task']['command'], $post['Task']['status'], $post['Task']['comment']);
         \Yii::$app->response->redirect('/?r=tasks/task-edit&task_id=' . $task->task_id);
     }
     return $this->render('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder, self::$tasks_namespace)));
 }