7
7
8
8
class Step extends Logging
9
9
{
10
- // /**
11
- // * Add a new step to the log
12
- // */
13
- // public function new(string $name, string $title)
14
- // {
15
- // $content = $this->getContent();
16
-
17
- // $content['steps'][$name] = [
18
- // 'title' => $title,
19
- // 'status' => 'running',
20
- // 'error-message' => '',
21
- // 'start' => microtime(true),
22
- // 'end' => '',
23
- // 'duration' => '',
24
- // 'substeps' => []
25
- // ];
26
-
27
- // if (!file_put_contents($this->logFile, json_encode($content), LOCK_EX)) {
28
- // $this->logController->log('error', 'Task logging', 'Could not add new step "' . $name . '" to task log file ' . $this->logFile);
29
- // }
30
-
31
- // unset($content);
32
- // }
33
-
34
- // /**
35
- // * Set the latest step as completed
36
- // */
37
- // public function completed(string|null $message = null)
38
- // {
39
- // $content = $this->getContent();
40
-
41
- // // Get latest step key name
42
- // $name = array_key_last($content['steps']);
43
-
44
- // // Set status to completed
45
- // $content['steps'][$name]['status'] = 'completed';
46
-
47
- // // Set end date
48
- // $content['steps'][$name]['end'] = microtime(true);
49
-
50
- // // Set duration
51
- // $content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];
52
-
53
- // // Set message if any
54
- // if (!empty($message)) {
55
- // $content['steps'][$name]['message'] = $message;
56
- // }
57
-
58
- // if (!file_put_contents($this->logFile, json_encode($content), LOCK_EX)) {
59
- // $this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as completed in task log file ' . $this->logFile);
60
- // }
61
-
62
- // unset($content);
63
- // }
64
-
65
- // /**
66
- // * Set the latest step as error
67
- // */
68
- // public function error(string $message)
69
- // {
70
- // $content = $this->getContent();
71
-
72
- // // Get latest step key name
73
- // $name = array_key_last($content['steps']);
74
-
75
- // // Set status to completed
76
- // $content['steps'][$name]['status'] = 'error';
77
-
78
- // // Set end date
79
- // $content['steps'][$name]['end'] = microtime(true);
80
-
81
- // // Set duration
82
- // $content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];
83
-
84
- // // Set error-message
85
- // $content['steps'][$name]['error-message'] = 'Failed';
86
-
87
- // // Also set latest sub step on error
88
- // $subStepName = array_key_last($content['steps'][$name]['substeps']);
89
-
90
- // if (isset($content['steps'][$name]['substeps'][$subStepName]['status'])) {
91
- // $content['steps'][$name]['substeps'][$subStepName]['status'] = 'error';
92
- // $content['steps'][$name]['substeps'][$subStepName]['output'][] = [
93
- // 'time' => microtime(true),
94
- // 'type' => 'error',
95
- // 'message' => $message
96
- // ];
97
- // }
98
-
99
- // if (!file_put_contents($this->logFile, json_encode($content), LOCK_EX)) {
100
- // $this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as error in task log file ' . $this->logFile);
101
- // }
102
-
103
- // unset($content);
104
- // }
105
-
106
- // /**
107
- // * Set the latest step as stopped
108
- // */
109
- // public function stopped()
110
- // {
111
- // $content = $this->getContent();
112
-
113
- // // Get latest step key name
114
- // $name = array_key_last($content['steps']);
115
-
116
- // // Set status to completed
117
- // $content['steps'][$name]['status'] = 'stopped';
118
-
119
- // // Set end date
120
- // $content['steps'][$name]['end'] = microtime(true);
121
-
122
- // // Set duration
123
- // $content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];
124
-
125
- // if (!file_put_contents($this->logFile, json_encode($content), LOCK_EX)) {
126
- // $this->logController->log('error', 'Task logging', 'Could not set step "' . $name . '" as stopped in task log file ' . $this->logFile);
127
- // }
128
-
129
- // unset($content);
130
- // }
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
10
public function __construct (int $ taskId )
139
11
{
140
12
parent ::__construct ($ taskId );
141
13
142
- // Override parent model by the SubStep model
14
+ // Override parent model with the SubStep model
143
15
$ this ->model = new \Models \Logging \Step ($ taskId );
144
16
}
145
17
@@ -154,43 +26,55 @@ public function new(string $identifier, string $title) : void
154
26
/**
155
27
* Set the latest step as completed
156
28
*/
157
- public function completed (string |null $ message = null )
29
+ public function completed (string |null $ message = null ) : void
158
30
{
159
- // Get latest step Id from database
31
+ /**
32
+ * Get latest step Id from database
33
+ */
160
34
$ stepId = $ this ->getLatestStepId ($ this ->taskId );
161
35
162
- // Mark step as completed in database
36
+ /**
37
+ * Mark step as completed in database
38
+ */
163
39
$ this ->model ->status ($ stepId , 'completed ' , $ message );
164
40
}
165
41
166
42
/**
167
43
* Set the latest step as error
168
44
*/
169
- public function error (string $ message )
45
+ public function error (string $ message ) : void
170
46
{
171
- // Get latest step Id from database
47
+ /**
48
+ * Get latest step Id from database
49
+ */
172
50
$ stepId = $ this ->getLatestStepId ($ this ->taskId );
173
51
174
- // Mark step as error in database
52
+ /**
53
+ * Mark step as error in database
54
+ */
175
55
$ this ->model ->status ($ stepId , 'error ' , $ message );
176
56
}
177
57
178
58
/**
179
59
* Set the latest step as stopped
180
60
*/
181
- public function stopped ()
61
+ public function stopped () : void
182
62
{
183
- // Get latest step Id from database
63
+ /**
64
+ * Get latest step Id from database
65
+ */
184
66
$ stepId = $ this ->getLatestStepId ($ this ->taskId );
185
67
186
- // Mark step as stopped in database
68
+ /**
69
+ * Mark step as stopped in database
70
+ */
187
71
$ this ->model ->status ($ stepId , 'stopped ' );
188
72
}
189
73
190
74
/**
191
75
* Get steps for the provided task ID
192
76
*/
193
- public function get (int $ taskId )
77
+ public function get (int $ taskId ) : array
194
78
{
195
79
return $ this ->model ->get ($ taskId );
196
80
}
0 commit comments