Example #1
0
 /**
  * Run all tasks
  *
  * @return bool
  */
 private function runTasks()
 {
     $this->tasksCount = 0;
     // Get how many task should be mailed
     foreach ($this->tasks as $task => $properties) {
         if (isset($properties['mail']) && $properties['mail']) {
             $this->tasksMailable++;
         }
         if (!empty($properties['commands'])) {
             $this->tasksCount++;
         }
     }
     $t = 1;
     $self = $this;
     $allTasksResponse = [];
     $tasksCompleted = 0;
     foreach ($this->tasks as $task => $properties) {
         # Skip tasks that have no commands
         if (empty($properties['commands'])) {
             continue;
         }
         # Empty task response
         $taskResponse = [];
         # Add command to task to change working directory
         array_unshift($properties['commands'], 'cd ' . $this->basePath);
         # Define the commands for this task
         $this->remoteConnection->define($task, $properties['commands']);
         try {
             # Run the commands for this task
             $this->remoteConnection->task($task, function ($line) use($self, &$taskResponse) {
                 $taskResponse[] = $self->parseResponse($line);
             });
             # Check if we need to e-mail the output of the task
             if ($this->isMailEnabled() && isset($properties['mail']) && $properties['mail']) {
                 $this->mailTaskSuccess($task, $t, $taskResponse);
             }
             $tasksCompleted++;
         } catch (RuntimeException $e) {
             $this->setErrorMessage($e->getMessage());
             # Add error message to response
             $taskResponse[] = $self->parseResponse($e->getMessage());
             # Check if we need to e-mail the output
             if ($this->isMailEnabled()) {
                 $this->mailTaskFailed($task, $t);
             }
         }
         # Save this tasks response
         $allTasksResponse = array_merge($allTasksResponse, $taskResponse);
         $t++;
     }
     # Mail response when all tasks have been completed
     if ($tasksCompleted > 0 && $this->isMailEnabled() && $this->tasksMailOnCompletion) {
         $this->mailSuccess($allTasksResponse);
     }
     return $tasksCompleted > 0;
 }