Ejemplo n.º 1
0
 /**
  * Add a task to the collection
  *
  * @param Task   $task        The task to be added
  * @param string $description A short description explaining what the task does.
  */
 public function add(Task $task, $description)
 {
     // Descriptions must be provided!
     $description = trim($description);
     if (empty($description)) {
         throw new \InvalidArgumentException('No description provided for ' . $task->getName());
     }
     // Add the task to the internal array
     $this->_tasks[$task->getName()] = array($description, $task);
 }
Ejemplo n.º 2
0
 public function testTask()
 {
     $mock = $this->getMock('stdClass', ['callback']);
     $mock->expects($this->exactly(1))->method('callback');
     $task = new Task('task_name', function () use($mock) {
         $mock->callback();
     });
     $context = $this->getMockBuilder('Deployer\\Task\\Context')->disableOriginalConstructor()->getMock();
     $task->run($context);
     $this->assertEquals('task_name', $task->getName());
     $task->desc('Task description.');
     $this->assertEquals('Task description.', $task->getDescription());
     $task->once();
     $this->assertTrue($task->isOnce());
     $task->onlyOn(['server']);
     $this->assertEquals(['server' => 0], $task->getOnlyOn());
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn([]);
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn('server');
     $this->assertEquals(['server' => 0], $task->getOnlyOn());
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn();
     $this->assertTrue($task->runOnServer('server'));
     $task->setPrivate();
     $this->assertTrue($task->isPrivate());
 }
Ejemplo n.º 3
0
 /**
  * @param mixed $task
  */
 public function addTask(Task $task)
 {
     if ($this->freePlaceForTasks) {
         $this->tasks[] = $task;
         $this->setFreePlaceForTasks();
         echo $task->getName() . ' is added to tasks', PHP_EOL;
     } else {
         echo 'You can\'t add more task';
     }
 }
Ejemplo n.º 4
0
 public function addTask(Task $task)
 {
     if ($this->freePlacesForTask > 0) {
         $this->tasks[] = $task;
         $this->freePlacesForTask--;
         echo $task->getName(), " has been added!", PHP_EOL;
     } else {
         echo "You can not add new task!", PHP_EOL;
     }
 }
 /**
  * Reopen specific object
  *
  * @param void
  * @return null
  */
 function open()
 {
     if ($this->active_task->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_task->canChangeCompleteStatus($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $action = $this->active_task->open($this->logged_user);
         if ($action && !is_error($action)) {
             db_commit();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 if ($this->request->get('async')) {
                     $this->smarty->assign(array('_object_task' => $this->active_task));
                     print tpl_fetch(get_template_path('_task_opened_row', $this->controller_name, RESOURCES_MODULE));
                     die;
                 } else {
                     //flash_success('Task ":name" has been opened', array('name' => str_excerpt($this->active_task->getName(), 80, '...')));
                     //bof:mod
                     flash_success('Task ":name" has been opened', array('name' => str_excerpt(strip_tags($this->active_task->getName()), 80, '...')));
                     //eof:mod
                     $this->redirectToReferer($this->active_task->getViewUrl());
                 }
                 // if
             } else {
                 $this->serveData($this->active_task);
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 if ($this->request->get('async')) {
                     $this->serveData($action);
                 } else {
                     flash_error('Failed to open task ":name"', array('name' => str_excerpt($this->active_task->getName(), 80, '...')));
                     $this->redirectToReferer($this->active_task->getViewUrl());
                 }
                 // if
             } else {
                 $this->httpError(HTTP_ERR_OPERATION_FAILED);
             }
             // if
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
Ejemplo n.º 6
0
    if (!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'))) {
        echo 'Access denied';
        exit;
    } else {
        header('Content-Type: application/json');
        echo $task->getBebrasJson();
        exit;
    }
}
?>
<!doctype html>
<html>
   <head>
      <meta charset="utf-8">
      <title><?php 
echo $task->getName();
?>
</title>
      <?php 
echo $task->getStaticResourcesImportHtml(Task::MODULES | Task::CONTENT | Task::SOLUTION);
?>
   </head>
   <body <?php 
echo $task->getBodyParametersHtml();
?>
>
      <?php 
echo $task->getContent(Task::CONTENT | Task::SOLUTION);
?>
   </body>
</html>
Ejemplo n.º 7
0
 /**
  * @param Task $currentTask
  */
 public function setCurrentTask($currentTask)
 {
     $this->currentTask = $currentTask;
     echo 'Assigning task ' . $this->currentTask->getName() . ' to ' . $this->name . PHP_EOL;
 }
Ejemplo n.º 8
0
 private function setFormat($items)
 {
     $result = array();
     /** @var Item $item */
     foreach ($items as $item) {
         $task = new Task($item->task_id);
         $result[] = array("id" => $item->getId(), "day" => strtolower(date("D", $item->getStart())), "startHour" => date("H", $item->getStart()), "startMinute" => date("i", $item->getStart()), "endHour" => date("H", $item->getEnd()), "endMinute" => date("i", $item->getEnd()), "state" => $item->getStateString(), "feedback" => $item->getFeedback(), "title" => $task->getName(), "color" => $task->getColor());
     }
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Save or update task
  * @param Task $task
  * @return Task
  */
 public function saveTask(Task $task)
 {
     if (is_null($task->getId())) {
         $query = $this->db->prepare("INSERT INTO tasks (name, parameters, status) VALUES (?, ?, ?)");
         $query->execute([$task->getName(), $task->getParameters(), $task->getStatus()]);
         $task->setId($this->db->lastInsertId());
     } else {
         $query = $this->db->prepare("UPDATE tasks SET name = ?, parameters = ?, status = ? WHERE id = ?");
         $query->execute([$task->getName(), $task->getParameters(), $task->getStatus(), $task->getId()]);
     }
     return $task;
 }