Skip to content

Commit 51a33fc

Browse files
committed
patch
1 parent c87c665 commit 51a33fc

File tree

13 files changed

+158
-472
lines changed

13 files changed

+158
-472
lines changed

www/controllers/Layout/Container/vars/tasks/log.vars.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
/**
127127
* Include steps
128128
*/
129-
foreach ($content['steps'] as $stepName => $step) {
129+
foreach ($content['steps'] as $stepIdentifier => $step) {
130130
ob_start();
131131
include(ROOT . '/views/includes/containers/tasks/log/step.inc.php');
132132
include(ROOT . '/views/includes/containers/tasks/log/step-content.inc.php');

www/controllers/Logging/Logging.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,11 @@ class Logging
99
{
1010
protected $model;
1111
protected $taskId;
12-
// protected $logFile;
13-
protected $logController;
14-
protected $stepModel;
15-
protected $substepModel;
16-
17-
// public function __construct(int $taskId)
18-
// {
19-
// $this->logController = new \Controllers\Log\Log();
20-
// $this->logFile = MAIN_LOGS_DIR . '/' . $taskId . '.json';
21-
22-
// $this->generate();
23-
// }
24-
25-
// /**
26-
// * Generate log file
27-
// */
28-
// public function generate() : void
29-
// {
30-
// if (file_exists($this->logFile)) {
31-
// return;
32-
// }
33-
34-
// if (!file_put_contents($this->logFile, json_encode(array('steps' => [])))) {
35-
// $this->logController->log('error', 'Task logging', 'Could not create task log file ' . $this->logFile);
36-
// }
37-
// }
38-
39-
// /**
40-
// * Get log content
41-
// */
42-
// protected function getContent()
43-
// {
44-
// if (!file_exists($this->logFile)) {
45-
// $this->logController->log('error', 'Task logging', 'Task log file not found ' . $this->logFile);
46-
// return [];
47-
// }
48-
49-
// return json_decode(file_get_contents($this->logFile), true);
50-
// }
5112

5213
public function __construct(int $taskId)
5314
{
5415
$this->taskId = $taskId;
5516
$this->model = new \Models\Logging\Logging($taskId);
56-
$this->logController = new \Controllers\Log\Log();
5717
}
5818

5919
/**
@@ -114,20 +74,4 @@ public function getContent() : array
11474

11575
return $content;
11676
}
117-
118-
/**
119-
* Write log content to database
120-
*/
121-
// protected function write(int $taskId, array $content) : void
122-
// {
123-
// // First, encode content to JSON
124-
// try {
125-
// $content = json_encode($content, JSON_THROW_ON_ERROR);
126-
// } catch (JsonException $e) {
127-
// $this->logController->log('error', 'Task logging', 'Could not encode task #' . $taskId . ' log to a JSON string: ' . $e->getMessage());
128-
// }
129-
130-
// // Write content to database
131-
// $this->model->write($taskId, $content);
132-
// }
13377
}

www/controllers/Logging/Step.php

Lines changed: 23 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -7,139 +7,11 @@
77

88
class Step extends Logging
99
{
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-
13810
public function __construct(int $taskId)
13911
{
14012
parent::__construct($taskId);
14113

142-
// Override parent model by the SubStep model
14+
// Override parent model with the SubStep model
14315
$this->model = new \Models\Logging\Step($taskId);
14416
}
14517

@@ -154,43 +26,55 @@ public function new(string $identifier, string $title) : void
15426
/**
15527
* Set the latest step as completed
15628
*/
157-
public function completed(string|null $message = null)
29+
public function completed(string|null $message = null) : void
15830
{
159-
// Get latest step Id from database
31+
/**
32+
* Get latest step Id from database
33+
*/
16034
$stepId = $this->getLatestStepId($this->taskId);
16135

162-
// Mark step as completed in database
36+
/**
37+
* Mark step as completed in database
38+
*/
16339
$this->model->status($stepId, 'completed', $message);
16440
}
16541

16642
/**
16743
* Set the latest step as error
16844
*/
169-
public function error(string $message)
45+
public function error(string $message) : void
17046
{
171-
// Get latest step Id from database
47+
/**
48+
* Get latest step Id from database
49+
*/
17250
$stepId = $this->getLatestStepId($this->taskId);
17351

174-
// Mark step as error in database
52+
/**
53+
* Mark step as error in database
54+
*/
17555
$this->model->status($stepId, 'error', $message);
17656
}
17757

17858
/**
17959
* Set the latest step as stopped
18060
*/
181-
public function stopped()
61+
public function stopped() : void
18262
{
183-
// Get latest step Id from database
63+
/**
64+
* Get latest step Id from database
65+
*/
18466
$stepId = $this->getLatestStepId($this->taskId);
18567

186-
// Mark step as stopped in database
68+
/**
69+
* Mark step as stopped in database
70+
*/
18771
$this->model->status($stepId, 'stopped');
18872
}
18973

19074
/**
19175
* Get steps for the provided task ID
19276
*/
193-
public function get(int $taskId)
77+
public function get(int $taskId) : array
19478
{
19579
return $this->model->get($taskId);
19680
}

0 commit comments

Comments
 (0)