1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* ProgressInformation.php |
6
|
|
|
* Copyright (c) 2020 [email protected]. |
7
|
|
|
* |
8
|
|
|
* This file is part of the Firefly III bunq importer |
9
|
|
|
* (https://github.com/firefly-iii/bunq-importer). |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace App\Services\Sync\JobStatus; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Trait ProgressInformation. |
29
|
|
|
*/ |
30
|
|
|
trait ProgressInformation |
31
|
|
|
{ |
32
|
|
|
/** @var array */ |
33
|
|
|
protected $errors; |
34
|
|
|
/** @var string */ |
35
|
|
|
protected $identifier; |
36
|
|
|
/** @var array */ |
37
|
|
|
protected $messages; |
38
|
|
|
/** @var array */ |
39
|
|
|
protected $warnings; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getErrors(): array |
45
|
|
|
{ |
46
|
|
|
return $this->errors ?? []; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getMessages(): array |
53
|
|
|
{ |
54
|
|
|
return $this->messages ?? []; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function getWarnings(): array |
61
|
|
|
{ |
62
|
|
|
return $this->warnings ?? []; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $identifier |
67
|
|
|
*/ |
68
|
|
|
public function setIdentifier(string $identifier): void |
69
|
|
|
{ |
70
|
|
|
$this->identifier = $identifier; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param int $index |
75
|
|
|
* @param string $error |
76
|
|
|
*/ |
77
|
|
|
protected function addError(int $index, string $error): void |
78
|
|
|
{ |
79
|
|
|
$this->errors = $this->errors ?? []; |
80
|
|
|
$this->errors[$index] = $this->errors[$index] ?? []; |
81
|
|
|
$this->errors[$index][] = $error; |
82
|
|
|
|
83
|
|
|
// write errors |
84
|
|
|
app('log')->error(sprintf('Error: %s %d: %s', $this->identifier, $index, $error)); |
85
|
|
|
JobStatusManager::addError($this->identifier, $index, $error); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param int $index |
90
|
|
|
* @param string $message |
91
|
|
|
*/ |
92
|
|
|
protected function addMessage(int $index, string $message): void |
93
|
|
|
{ |
94
|
|
|
$this->messages = $this->messages ?? []; |
95
|
|
|
$this->messages[$index] = $this->messages[$index] ?? []; |
96
|
|
|
$this->messages[$index][] = $message; |
97
|
|
|
|
98
|
|
|
// write message |
99
|
|
|
app('log')->info(sprintf('Message: %s %d: %s', $this->identifier, $index, $message)); |
100
|
|
|
JobStatusManager::addMessage($this->identifier, $index, $message); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param int $index |
105
|
|
|
* @param string $warning |
106
|
|
|
*/ |
107
|
|
|
protected function addWarning(int $index, string $warning): void |
108
|
|
|
{ |
109
|
|
|
$this->warnings = $this->warnings ?? []; |
110
|
|
|
$this->warnings[$index] = $this->warnings[$index] ?? []; |
111
|
|
|
$this->warnings[$index][] = $warning; |
112
|
|
|
|
113
|
|
|
// write warning |
114
|
|
|
app('log')->warning(sprintf('Warning: %s %d: %s', $this->identifier, $index, $warning)); |
115
|
|
|
JobStatusManager::addWarning($this->identifier, $index, $warning); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|