1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TShellCronLogBehavior class file. |
4
|
|
|
* |
5
|
|
|
* @author Brad Anderson <[email protected]> |
6
|
|
|
* @link https://github.com/pradosoft/prado |
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Prado\Util\Cron; |
11
|
|
|
|
12
|
|
|
use Prado\Prado; |
13
|
|
|
use Prado\Shell\TShellAppAction; |
|
|
|
|
14
|
|
|
use Prado\Util\TBehavior; |
15
|
|
|
use Prado\Util\TCallChain; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* TShellCronLogBehavior class. |
19
|
|
|
* |
20
|
|
|
* Enables cron logging to the shell. It also encapsulates the TShellWriter |
21
|
|
|
* and basic dyWrite, dyWriteLine, and dyFlush functionality. |
22
|
|
|
* |
23
|
|
|
* @author Brad Anderson <[email protected]> |
24
|
|
|
* @since 4.2.0 |
25
|
|
|
*/ |
26
|
|
|
class TShellCronLogBehavior extends TBehavior |
27
|
|
|
{ |
28
|
|
|
private $_outWriter; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* creates the TShellCronLogBehavior with a writer |
32
|
|
|
* @param \Prado\IO\ITextWriter $writer where to write cron task info to |
33
|
|
|
*/ |
34
|
|
|
public function __construct($writer = null) |
35
|
|
|
{ |
36
|
|
|
$this->_outWriter = $writer; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \Prado\IO\ITextWriter the output writer from the shell |
41
|
|
|
*/ |
42
|
|
|
public function getOutputWriter() |
43
|
|
|
{ |
44
|
|
|
return $this->_outWriter; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Prado\IO\ITextWriter $writer the output writer from the shell |
49
|
|
|
*/ |
50
|
|
|
public function setOutputWriter($writer) |
51
|
|
|
{ |
52
|
|
|
$this->_outWriter = $writer; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* writes, with attributes, to the OutputWriter |
57
|
|
|
* @param string $str |
58
|
|
|
* @param array|int|\Prado\Util\TCallChain|string $p1 |
59
|
|
|
* @param null|\Prado\Util\TCallChain $p2 |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function dyWrite($str, $p1, $p2 = null) |
63
|
|
|
{ |
64
|
|
|
if ($p1 instanceof TCallChain) { |
65
|
|
|
$attr = null; |
66
|
|
|
$callchain = $p1; |
67
|
|
|
} else { |
68
|
|
|
$attr = $p1; |
69
|
|
|
$callchain = $p2; |
70
|
|
|
} |
71
|
|
|
$this->_outWriter->write($str, $attr); |
|
|
|
|
72
|
|
|
return $callchain->dyWrite($str, $p1, $p2); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* writes Line, with attributes, to the OutputWriter |
77
|
|
|
* @param string $str |
78
|
|
|
* @param array|int|\Prado\Util\TCallChain|string $p1 |
79
|
|
|
* @param null|\Prado\Util\TCallChain $p2 |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
|
|
public function dyWriteLine($str, $p1, $p2 = null) |
83
|
|
|
{ |
84
|
|
|
if ($p1 instanceof TCallChain) { |
85
|
|
|
$attr = null; |
86
|
|
|
$callchain = $p1; |
87
|
|
|
} else { |
88
|
|
|
$attr = $p1; |
89
|
|
|
$callchain = $p2; |
90
|
|
|
} |
91
|
|
|
$this->_outWriter->writeLine($str, $attr); |
|
|
|
|
92
|
|
|
return $callchain->dyWriteLine($str, $p1, $p2); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* flushes the OutputWriter |
98
|
|
|
* @param \Prado\Util\TCallChain $callchain |
99
|
|
|
* @return string the accumulated text in the buffer |
100
|
|
|
*/ |
101
|
|
|
public function dyFlush($callchain) |
102
|
|
|
{ |
103
|
|
|
$result = $this->_outWriter->flush(); |
104
|
|
|
return $result . $callchain->dyFlush(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Logs a when cron is run in the shell. |
109
|
|
|
* @param int $numtasks number of tasks to run |
110
|
|
|
* @param \Prado\Util\TCallChain $callchain the chain of methods |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
|
|
public function dyLogCron($numtasks, $callchain) |
114
|
|
|
{ |
115
|
|
|
$this->_outWriter->writeLine(" Running {$numtasks} Cron Tasks @ " . date('Y-m-d H:i:s') . " \n"); |
116
|
|
|
|
117
|
|
|
return $callchain->dyLogCron($numtasks); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Logs a single cron task when run in the shell. |
122
|
|
|
* @param \Prado\Util\Cron\TCronTask $task the task to log |
123
|
|
|
* @param string $username the user name running the task |
124
|
|
|
* @param \Prado\Util\TCallChain $callchain the chain of methods |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function dyLogCronTask($task, $username, $callchain) |
128
|
|
|
{ |
129
|
|
|
$this->_outWriter->writeLine("Running Task {$task->getName()} as {$username}"); |
130
|
|
|
$this->_outWriter->flush(); |
131
|
|
|
|
132
|
|
|
return $callchain->dyLogCronTask($task, $username); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Logs the end of a single cron task when run in the shell. |
137
|
|
|
* @param \Prado\Util\Cron\TCronTask $task the tasks that was run |
138
|
|
|
* @param \Prado\Util\TCallChain $callchain the chain of methods |
139
|
|
|
* @return mixed |
140
|
|
|
*/ |
141
|
|
|
public function dyLogCronTaskEnd($task, $callchain) |
142
|
|
|
{ |
143
|
|
|
$this->_outWriter->writeLine("Ending Task {$task->getName()}\n"); |
144
|
|
|
|
145
|
|
|
return $callchain->dyLogCronTaskEnd($task); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths