|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* StartDownload.php |
|
4
|
|
|
* Copyright (c) 2020 [email protected]. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Firefly III bunq importer |
|
7
|
|
|
* (https://github.com/firefly-iii/bunq-importer). |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
declare(strict_types=1); |
|
24
|
|
|
|
|
25
|
|
|
namespace App\Console; |
|
26
|
|
|
|
|
27
|
|
|
use App\Bunq\Download\RoutineManager as DownloadRoutineMananger; |
|
28
|
|
|
use App\Exceptions\ImportException; |
|
29
|
|
|
use App\Services\Configuration\Configuration; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Trait StartDownload. |
|
33
|
|
|
*/ |
|
34
|
|
|
trait StartDownload |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $configuration |
|
38
|
|
|
* |
|
39
|
|
|
* @return int |
|
40
|
|
|
*/ |
|
41
|
|
|
private function startDownload(array $configuration): int |
|
42
|
|
|
{ |
|
43
|
|
|
app('log')->debug(sprintf('Now in %s', __METHOD__)); |
|
44
|
|
|
$configObject = Configuration::fromFile($configuration); |
|
45
|
|
|
|
|
46
|
|
|
// first download from bunq |
|
47
|
|
|
$manager = new DownloadRoutineMananger; |
|
48
|
|
|
try { |
|
49
|
|
|
$manager->setConfiguration($configObject); |
|
50
|
|
|
} catch (ImportException $e) { |
|
51
|
|
|
$this->error($e->getMessage()); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
return 1; |
|
54
|
|
|
} |
|
55
|
|
|
try { |
|
56
|
|
|
$manager->start(); |
|
57
|
|
|
} catch (ImportException $e) { |
|
58
|
|
|
$this->error($e->getMessage()); |
|
59
|
|
|
|
|
60
|
|
|
return 1; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$messages = $manager->getAllMessages(); |
|
64
|
|
|
$warnings = $manager->getAllWarnings(); |
|
65
|
|
|
$errors = $manager->getAllErrors(); |
|
66
|
|
|
|
|
67
|
|
|
if (count($errors) > 0) { |
|
68
|
|
|
/** |
|
69
|
|
|
* @var int $index |
|
70
|
|
|
* @var array $error |
|
71
|
|
|
*/ |
|
72
|
|
|
foreach ($errors as $index => $error) { |
|
73
|
|
|
/** @var string $line */ |
|
74
|
|
|
foreach ($error as $line) { |
|
75
|
|
|
$this->error(sprintf('ERROR in line #%d: %s', $index + 1, $line)); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (count($warnings) > 0) { |
|
81
|
|
|
/** |
|
82
|
|
|
* @var int $index |
|
83
|
|
|
* @var array $warning |
|
84
|
|
|
*/ |
|
85
|
|
|
foreach ($warnings as $index => $warning) { |
|
86
|
|
|
/** @var string $line */ |
|
87
|
|
|
foreach ($warning as $line) { |
|
88
|
|
|
$this->warn(sprintf('Warning from line #%d: %s', $index + 1, $line)); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (count($messages) > 0) { |
|
94
|
|
|
/** |
|
95
|
|
|
* @var int $index |
|
96
|
|
|
* @var array $message |
|
97
|
|
|
*/ |
|
98
|
|
|
foreach ($messages as $index => $message) { |
|
99
|
|
|
/** @var string $line */ |
|
100
|
|
|
foreach ($message as $line) { |
|
101
|
|
|
$this->info(sprintf('Message from line #%d: %s', $index + 1, strip_tags($line))); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
$this->downloadIdentifier = $manager->getDownloadIdentifier(); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return 0; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|