1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Executor; |
9
|
|
|
|
10
|
|
|
use Deployer\Console\Output\OutputWatcher; |
11
|
|
|
use Deployer\Deployer; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class Informer |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Deployer\Console\Output\OutputWatcher |
18
|
|
|
*/ |
19
|
|
|
private $output; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int|double |
23
|
|
|
*/ |
24
|
|
|
private $startTime; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Deployer\Console\Output\OutputWatcher $output |
28
|
|
|
*/ |
29
|
16 |
|
public function __construct(OutputWatcher $output) |
30
|
|
|
{ |
31
|
16 |
|
$this->output = $output; |
32
|
16 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $taskName |
36
|
|
|
*/ |
37
|
13 |
|
public function startTask($taskName) |
38
|
|
|
{ |
39
|
13 |
|
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) { |
40
|
12 |
|
$this->output->writeln("➤ Executing task <info>$taskName</info>"); |
41
|
12 |
|
$this->output->setWasWritten(false); |
42
|
12 |
|
$this->startTime = round(microtime(true) * 1000); |
43
|
12 |
|
} |
44
|
13 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Print task was ok. |
48
|
|
|
*/ |
49
|
14 |
|
public function endTask() |
50
|
|
|
{ |
51
|
|
|
$shouldReplaceTaskMark = |
52
|
14 |
|
$this->output->isDecorated() && |
53
|
14 |
|
$this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL && |
54
|
14 |
|
!$this->output->getWasWritten(); |
55
|
|
|
|
56
|
14 |
|
if ($shouldReplaceTaskMark) { |
57
|
|
|
$this->output->writeln("\r\033[K\033[1A\r<info>✔</info>"); |
58
|
|
|
} else { |
59
|
14 |
|
if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { |
60
|
12 |
|
$this->output->writeln("<info>✔</info> Ok"); |
61
|
12 |
|
} else { |
62
|
2 |
|
$endTime = round(microtime(true) * 1000); |
63
|
2 |
|
$millis = $endTime - $this->startTime; |
64
|
2 |
|
$seconds = floor($millis / 1000); |
65
|
2 |
|
$millis = $millis - $seconds * 1000; |
66
|
2 |
|
$taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms"; |
67
|
2 |
|
$this->output->writeln("<info>✔</info> Ok [$taskTime]"); |
68
|
|
|
} |
69
|
|
|
} |
70
|
14 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $serverName |
74
|
|
|
*/ |
75
|
10 |
|
public function endOnServer($serverName) |
76
|
|
|
{ |
77
|
10 |
|
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
78
|
|
|
$this->output->writeln("<info>•</info> done on [$serverName]"); |
79
|
|
|
} |
80
|
10 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Print error. |
84
|
|
|
* |
85
|
|
|
* @param bool $nonFatal |
86
|
|
|
*/ |
87
|
2 |
|
public function taskError($nonFatal = true) |
88
|
|
|
{ |
89
|
2 |
|
if ($nonFatal) { |
90
|
1 |
|
$this->output->writeln("<fg=yellow>✘</fg=yellow> Some errors occurred!"); |
91
|
1 |
|
} else { |
92
|
1 |
|
$this->output->writeln("<fg=red>✘</fg=red> <options=underscore>Some errors occurred!</options=underscore>"); |
93
|
|
|
} |
94
|
2 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $serverName |
98
|
|
|
* @param string $exceptionClass |
99
|
|
|
* @param string $message |
100
|
|
|
*/ |
101
|
|
|
public function taskException($serverName, $exceptionClass, $message) |
102
|
|
|
{ |
103
|
|
|
$formatter = Deployer::get()->getHelper('formatter'); |
104
|
|
|
$messages = explode("\n", $message); |
105
|
|
|
array_unshift($messages, "Exception [$exceptionClass] on [$serverName] server:"); |
106
|
|
|
|
107
|
|
|
$this->output->writeln($formatter->formatBlock($messages, 'error', true)); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|