protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input); $environment = $this->getSelectedEnvironment(); $startsAt = null; if ($input->getOption('start') && !($startsAt = strtotime($input->getOption('start')))) { $this->stdErr->writeln('Invalid date: <error>' . $input->getOption('start') . '</error>'); return 1; } $limit = (int) $input->getOption('limit'); $activities = $environment->getActivities($limit, $input->getOption('type'), $startsAt); if (!$activities) { $this->stdErr->writeln('No activities found'); return 1; } $table = new Table($input, $output); $rows = []; foreach ($activities as $activity) { $description = $activity->getDescription(); if (!$table->formatIsMachineReadable()) { $description = wordwrap($description, 40); } $rows[] = [$activity->id, date('Y-m-d H:i:s', strtotime($activity['created_at'])), $description, $activity->getCompletionPercent(), ActivityUtil::formatState($activity->state)]; } if (!$table->formatIsMachineReadable()) { $this->stdErr->writeln("Activities for the environment <info>" . $environment->id . "</info>"); } $headers = ['ID', 'Created', 'Description', '% Complete', 'State']; $table->render($rows, $headers); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input, $input->getOption('all')); $project = $this->getSelectedProject(); $startsAt = null; if ($input->getOption('start') && !($startsAt = strtotime($input->getOption('start')))) { $this->stdErr->writeln('Invalid date: <error>' . $input->getOption('start') . '</error>'); return 1; } $limit = (int) $input->getOption('limit'); if ($this->hasSelectedEnvironment() && !$input->getOption('all')) { $environmentSpecific = true; $environment = $this->getSelectedEnvironment(); $activities = $environment->getActivities($limit, $input->getOption('type'), $startsAt); } else { $environmentSpecific = false; $activities = $project->getActivities($limit, $input->getOption('type'), $startsAt); } if (!$activities) { $this->stdErr->writeln('No activities found'); return 1; } $table = new Table($input, $output); $rows = []; foreach ($activities as $activity) { $row = [new AdaptiveTableCell($activity->id, ['wrap' => false]), date('Y-m-d H:i:s', strtotime($activity['created_at'])), $activity->getDescription(), $activity->getCompletionPercent(), ActivityUtil::formatState($activity->state)]; if (!$environmentSpecific) { $row[] = implode(', ', $activity->environments); } $rows[] = $row; } $headers = ['ID', 'Created', 'Description', '% Complete', 'State']; if (!$environmentSpecific) { $headers[] = 'Environment(s)'; } if (!$table->formatIsMachineReadable()) { if ($environmentSpecific && isset($environment)) { $this->stdErr->writeln("Activities for the environment <info>" . $environment->id . "</info>"); } elseif (!$environmentSpecific) { $this->stdErr->writeln("Activities for the project <info>" . $project->id . "</info>"); } } $table->render($rows, $headers); return 0; }