Exemplo n.º 1
0
 /**
  * Parses a Text to represent Colors in the Terminal/Console.
  *
  * @param string $string
  * @param Config $config
  * @return string
  */
 public static function color($string, Config $config)
 {
     $disabled = $config->getParameter('no-color', !$config->general('colors', true));
     if ($disabled) {
         $string = strip_tags($string);
         return $string;
     }
     foreach (self::$foregroundColors as $key => $code) {
         $replaceFrom = array('<' . $key . '>', '</' . $key . '>');
         $replaceTo = array("[" . $code . 'm', "");
         $string = str_replace($replaceFrom, $replaceTo, $string);
     }
     return $string;
 }
Exemplo n.º 2
0
 /**
  * Gets an instance of a Task.
  *
  * @param string|array $taskData
  * @param \Mage\Config $taskConfig
  * @param boolean $inRollback
  * @param string $stage
  * @return \Mage\Task\AbstractTask
  * @throws \Exception
  */
 public static function get($taskData, Config $taskConfig, $inRollback = false, $stage = null)
 {
     if (is_array($taskData)) {
         $taskName = $taskData['name'];
         $taskParameters = $taskData['parameters'];
     } else {
         $taskName = $taskData;
         $taskParameters = array();
     }
     $instance = null;
     $taskName = ucwords(str_replace('-', ' ', $taskName));
     $taskName = str_replace(' ', '', $taskName);
     $patterns = [];
     if (is_array($taskConfig->general('taskPatterns'))) {
         $patterns = $taskConfig->general('taskPatterns');
     }
     $patterns[] = 'Task\\%s';
     $patterns[] = 'Mage\\Task\\BuiltIn\\%sTask';
     $className = null;
     $taskClass = trim($taskName, '/\\');
     $taskClass = str_replace(' ', '\\', ucwords(str_replace('/', ' ', $taskClass)));
     $taskClass = str_replace(' ', '', ucwords(str_replace('-', ' ', $taskClass)));
     foreach ($patterns as $pattern) {
         $possibleClass = sprintf($pattern, $taskClass);
         if (class_exists($possibleClass)) {
             $className = $possibleClass;
             break;
         }
     }
     if (!$className) {
         throw new Exception('Task "' . $taskName . '" not found.');
     }
     $instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
     if (!$instance instanceof AbstractTask) {
         throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\\Task\\AbstractTask.');
     }
     return $instance;
 }
Exemplo n.º 3
0
 /**
  * Check Logs
  * @param \Mage\Config $config
  */
 private static function checkLogs(Config $config)
 {
     if (self::$logEnabled) {
         $maxLogs = $config->general('maxlogs', 30);
         $logs = array();
         foreach (new RecursiveDirectoryIterator(getcwd() . '/.mage/logs', RecursiveDirectoryIterator::SKIP_DOTS) as $log) {
             /* @var $log SplFileInfo */
             if (strpos($log->getFilename(), 'log-') === 0) {
                 $logs[] = $log->getFilename();
             }
         }
         sort($logs);
         if (count($logs) > $maxLogs) {
             $logsToDelete = array_slice($logs, 0, count($logs) - $maxLogs);
             foreach ($logsToDelete as $logToDeelte) {
                 unlink(getcwd() . '/.mage/logs/' . $logToDeelte);
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Execute Pre and Post Deployment Tasks
  *
  * @param string $stage
  * @param Config $config
  * @param string $title
  */
 protected function runNonDeploymentTasks($stage, Config $config, $title)
 {
     $tasksToRun = $config->getTasks($stage);
     self::$failedTasks = 0;
     // PreDeployment Hook
     if ($stage == AbstractTask::STAGE_PRE_DEPLOY) {
         // Look for Remote Source
         if (is_array($config->deployment('source', null))) {
             array_unshift($tasksToRun, 'scm/clone');
         }
         // Change Branch
         if ($config->deployment('scm', false)) {
             array_unshift($tasksToRun, 'scm/change-branch');
         }
     }
     // PostDeployment Hook
     if ($stage == AbstractTask::STAGE_POST_DEPLOY) {
         // If Deploy failed, clear post deploy tasks
         if (self::$deployStatus == self::FAILED) {
             $tasksToRun = array();
         }
         // Change Branch Back
         if ($config->deployment('scm', false)) {
             array_unshift($tasksToRun, 'scm/change-branch');
             $config->addParameter('_changeBranchRevert');
         }
         // Remove Remote Source
         if (is_array($config->deployment('source', null))) {
             array_push($tasksToRun, 'scm/remove-clone');
         }
     }
     if (count($tasksToRun) == 0) {
         Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
     } else {
         Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
         $tasks = 0;
         $completedTasks = 0;
         foreach ($tasksToRun as $taskData) {
             $tasks++;
             $task = Factory::get($taskData, $config, false, $stage);
             if ($this->runTask($task)) {
                 $completedTasks++;
             } else {
                 self::$failedTasks++;
             }
         }
         if ($completedTasks == $tasks) {
             $tasksColor = 'green';
         } else {
             $tasksColor = 'red';
         }
         Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
     }
 }
Exemplo n.º 5
0
 /**
  * Check if verbose logging is enabled
  *
  * @return boolean
  */
 protected static function isVerboseLoggingEnabled()
 {
     return self::$config->getParameter('verbose', false) || self::$config->general('verbose_logging') || self::$config->environmentConfig('verbose_logging', false);
 }