Skip to content

Commit 1da1297

Browse files
committed
Merge branch 'release/0.3.0'
2 parents 0246857 + 3e529d4 commit 1da1297

126 files changed

Lines changed: 2769 additions & 1404 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,31 @@ ASSET_URL=
118118
#
119119
ENABLE_MAIL_REPORT=false
120120

121+
#
122+
# Force Firefly III URL to be secure?
123+
#
124+
#
125+
EXPECT_SECURE_URL=false
126+
121127
# If enabled, define which mailer you want to use.
122128
# Options include: smtp, mailgun, postmark, sendmail, log, array
123129
# Amazon SES is not supported.
124130
# log = drop mails in the logs instead of sending them
125131
# array = debug mailer that does nothing.
126-
MAIL_DESTINATION=YOUR_OWN_EMAIL@example.com
132+
MAIL_MAILER=
127133

128-
#
129-
# Force Firefly III URL to be secure?
130-
#
131-
#
132-
EXPECT_SECURE_URL=false
133134

134-
MAIL_MAILER=smtp
135-
MAIL_HOST=example.com
136-
MAIL_PORT=25
137-
MAIL_ENCRYPTION=tls
138-
MAIL_USERNAME=username
139-
MAIL_PASSWORD=secret
135+
# where to send the report?
136+
MAIL_DESTINATION=
137+
138+
# other mail settings
140139
MAIL_FROM_ADDRESS=noreply@example.com
140+
MAIL_DRIVER=smtp
141+
MAIL_HOST=smtp.mailtrap.io
142+
MAIL_PORT=2525
143+
MAIL_USERNAME=563136238357725d5
144+
MAIL_PASSWORD=0405093edbe475
145+
MAIL_ENCRYPTION=null
141146

142147
# Extra settings depending on your mail configuration above.
143148
MAILGUN_DOMAIN=
@@ -169,7 +174,7 @@ TRACKER_SITE_ID=
169174
TRACKER_URL=
170175

171176

172-
APP_NAME=CSVImporter
177+
APP_NAME=DataImporter
173178

174179
#
175180
# The APP_URL environment variable is NOT used anywhere.

app/Console/AutoImports.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
namespace App\Console;
2626

27+
use App\Events\ImportedTransactions;
2728
use App\Exceptions\ImporterErrorException;
28-
use App\Services\CSV\Configuration\Configuration;
2929
use App\Services\CSV\Conversion\RoutineManager as CSVRoutineManager;
3030
use App\Services\Nordigen\Conversion\RoutineManager as NordigenRoutineManager;
31+
use App\Services\Shared\Configuration\Configuration;
3132
use App\Services\Shared\Conversion\ConversionStatus;
3233
use App\Services\Shared\Conversion\RoutineStatusManager;
3334
use App\Services\Shared\Import\Routine\RoutineManager;
@@ -36,7 +37,6 @@
3637
use App\Services\Spectre\Conversion\RoutineManager as SpectreRoutineManager;
3738
use Illuminate\Contracts\Filesystem\FileNotFoundException;
3839
use JsonException;
39-
use Log;
4040
use Storage;
4141

4242
/**
@@ -173,6 +173,8 @@ private function importFile(string $directory, string $file): void
173173
return;
174174
}
175175
$configuration = Configuration::fromArray(json_decode(file_get_contents($jsonFile), true));
176+
$configuration->updateDateRange();
177+
176178

177179
$this->line(sprintf('Going to convert from file %s using configuration %s and flow "%s".', $csvFile, $jsonFile, $configuration->getFlow()));
178180

@@ -185,7 +187,12 @@ private function importFile(string $directory, string $file): void
185187
$this->reportImport();
186188

187189
$this->line('Done!');
188-
// TODO send mail using event handler:
190+
event(new ImportedTransactions(
191+
array_merge($this->conversionMessages, $this->importMessages),
192+
array_merge($this->conversionWarnings, $this->importWarnings),
193+
array_merge($this->conversionErrors, $this->importErrors)
194+
)
195+
);
189196

190197
}
191198

@@ -202,7 +209,7 @@ private function startConversion(Configuration $configuration, ?string $csvFile)
202209
$this->conversionWarnings = [];
203210
$this->conversionErrors = [];
204211

205-
Log::debug(sprintf('Now in %s', __METHOD__));
212+
app('log')->debug(sprintf('Now in %s', __METHOD__));
206213

207214
switch ($configuration->getFlow()) {
208215
default:
@@ -233,14 +240,14 @@ private function startConversion(Configuration $configuration, ?string $csvFile)
233240
try {
234241
$transactions = $manager->start();
235242
} catch (ImporterErrorException $e) {
236-
Log::error($e->getMessage());
243+
app('log')->error($e->getMessage());
237244
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
238245
$this->conversionMessages = $manager->getAllMessages();
239246
$this->conversionWarnings = $manager->getAllWarnings();
240247
$this->conversionErrors = $manager->getAllErrors();
241248
}
242249
if (0 === count($transactions)) {
243-
Log::error('Zero transactions!');
250+
app('log')->error('Zero transactions!');
244251
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
245252
$this->conversionMessages = $manager->getAllMessages();
246253
$this->conversionWarnings = $manager->getAllWarnings();
@@ -252,7 +259,7 @@ private function startConversion(Configuration $configuration, ?string $csvFile)
252259
try {
253260
$disk->put(sprintf('%s.json', $this->identifier), json_encode($transactions, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
254261
} catch (JsonException $e) {
255-
Log::error(sprintf('JSON exception: %s', $e->getMessage()));
262+
app('log')->error(sprintf('JSON exception: %s', $e->getMessage()));
256263
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
257264
$this->conversionMessages = $manager->getAllMessages();
258265
$this->conversionWarnings = $manager->getAllWarnings();
@@ -300,7 +307,7 @@ private function reportConversion(): void
300307
*/
301308
private function startImport(Configuration $configuration): void
302309
{
303-
Log::debug(sprintf('Now at %s', __METHOD__));
310+
app('log')->debug(sprintf('Now at %s', __METHOD__));
304311
$routine = new RoutineManager($this->identifier);
305312
SubmissionStatusManager::startOrFindSubmission($this->identifier);
306313
$disk = Storage::disk('jobs');
@@ -322,7 +329,7 @@ private function startImport(Configuration $configuration): void
322329
try {
323330
$json = $disk->get($fileName);
324331
$transactions = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
325-
Log::debug(sprintf('Found %d transactions on the drive.', count($transactions)));
332+
app('log')->debug(sprintf('Found %d transactions on the drive.', count($transactions)));
326333
} catch (FileNotFoundException | JsonException $e) {
327334
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
328335
$message = sprintf('File "%s" could not be decoded, cannot continue..', $fileName);
@@ -343,7 +350,7 @@ private function startImport(Configuration $configuration): void
343350
try {
344351
$routine->start();
345352
} catch (ImporterErrorException $e) {
346-
Log::error($e->getMessage());
353+
app('log')->error($e->getMessage());
347354
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
348355
SubmissionStatusManager::addError($this->identifier, 0, $e->getMessage());
349356
$this->importMessages = $routine->getAllMessages();
@@ -357,9 +364,6 @@ private function startImport(Configuration $configuration): void
357364
$this->importMessages = $routine->getAllMessages();
358365
$this->importWarnings = $routine->getAllWarnings();
359366
$this->importErrors = $routine->getAllErrors();
360-
361-
// TODO make event handler and send email message
362-
363367
}
364368

365369
/**

app/Console/Commands/AutoImport.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use App\Console\VerifyJSON;
3030
use App\Exceptions\ImporterErrorException;
3131
use Illuminate\Console\Command;
32-
use Log;
3332

3433
/**
3534
* Class AutoImport
@@ -81,7 +80,7 @@ public function handle(): int
8180
try {
8281
$this->importFiles($directory, $files);
8382
} catch (ImporterErrorException $e) {
84-
Log::error($e->getMessage());
83+
app('log')->error($e->getMessage());
8584
$this->error(sprintf('Import exception (see the logs): %s', $e->getMessage()));
8685
}
8786

app/Console/Commands/Import.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
use App\Console\AutoImports;
2828
use App\Console\HaveAccess;
2929
use App\Console\VerifyJSON;
30+
use App\Events\ImportedTransactions;
3031
use App\Exceptions\ImporterErrorException;
31-
use App\Services\CSV\Configuration\Configuration;
32+
use App\Services\Shared\Configuration\Configuration;
3233
use Illuminate\Console\Command;
33-
use Log;
3434

3535
/**
3636
* Class Import
@@ -71,14 +71,14 @@ public function handle(): int
7171
}
7272

7373
$this->info(sprintf('Welcome to the Firefly III data importer, v%s', config('importer.version')));
74-
Log::debug(sprintf('Now in %s', __METHOD__));
74+
app('log')->debug(sprintf('Now in %s', __METHOD__));
7575
$file = (string) $this->argument('file');
7676
$config = (string) $this->argument('config');
7777

7878
if (!file_exists($config) || (file_exists($config) && !is_file($config))) {
7979
$message = sprintf('The importer can\'t import: configuration file "%s" does not exist or could not be read.', $config);
8080
$this->error($message);
81-
Log::error($message);
81+
app('log')->error($message);
8282

8383
return 1;
8484
}
@@ -95,7 +95,7 @@ public function handle(): int
9595
if ('csv' === $configuration->getFlow() && (!file_exists($file) || (file_exists($file) && !is_file($file)))) {
9696
$message = sprintf('The importer can\'t import: CSV file "%s" does not exist or could not be read.', $file);
9797
$this->error($message);
98-
Log::error($message);
98+
app('log')->error($message);
9999

100100
return 1;
101101
}
@@ -115,7 +115,8 @@ public function handle(): int
115115
$this->reportImport();
116116

117117
$this->line('Done!');
118-
// TODO send mail using event handler:
118+
119+
event(new ImportedTransactions($this->importMessages, $this->importWarnings, $this->importErrors));
119120
return 0;
120121

121122
}

app/Console/VerifyJSON.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
use Exception;
2828
use JsonException;
29-
use Log;
3029

3130
/**
3231
* Trait VerifyJSON
@@ -46,7 +45,7 @@ private function verifyJSON(string $file): bool
4645
json_decode($json, true, 512, JSON_THROW_ON_ERROR);
4746
} catch (Exception | JsonException $e) {
4847
$message = sprintf('The importer can\'t import: could not decode the JSON in the config file: %s', $e->getMessage());
49-
Log::error($message);
48+
app('log')->error($message);
5049

5150
return false;
5251

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
declare(strict_types=1);
3+
/*
4+
* ImportedTransactions.php
5+
* Copyright (c) 2021 james@firefly-iii.org
6+
*
7+
* This file is part of the Firefly III Data Importer
8+
* (https://github.com/firefly-iii/data-importer).
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
namespace App\Events;
25+
26+
use Illuminate\Queue\SerializesModels;
27+
28+
29+
/**
30+
* Class ImportedTransactions
31+
*/
32+
class ImportedTransactions
33+
{
34+
use SerializesModels;
35+
36+
public array $messages;
37+
public array $warnings;
38+
public array $errors;
39+
40+
/**
41+
* @param array $messages
42+
* @param array $warnings
43+
* @param array $errors
44+
*/
45+
public function __construct(array $messages, array $warnings, array $errors)
46+
{
47+
app('log')->debug('Created event ImportedTransactions');
48+
$this->messages = $messages;
49+
$this->warnings = $warnings;
50+
$this->errors = $errors;
51+
52+
}
53+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
declare(strict_types=1);
3+
/*
4+
* ImportedTransactionsEventHandler.php
5+
* Copyright (c) 2021 james@firefly-iii.org
6+
*
7+
* This file is part of the Firefly III Data Importer
8+
* (https://github.com/firefly-iii/data-importer).
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
namespace App\Handlers\Events;
25+
26+
use App\Events\ImportedTransactions;
27+
use App\Mail\ImportReportMail;
28+
use Illuminate\Support\Facades\Mail;
29+
30+
class ImportedTransactionsEventHandler
31+
{
32+
/**
33+
* @param ImportedTransactions $event
34+
*/
35+
public function sendReportOverMail(ImportedTransactions $event): void
36+
{
37+
app('log')->debug('Now in sendReportOverMail');
38+
39+
$mailer = config('mail.default');
40+
$receiver = config('mail.destination');
41+
if('' === $mailer) {
42+
app('log')->info('No mailer configured, will not mail.');
43+
return;
44+
}
45+
if('' === $receiver) {
46+
app('log')->info('No mail receiver configured, will not mail.');
47+
return;
48+
}
49+
50+
$log =[
51+
'messages' => $event->messages,
52+
'warnings' => $event->warnings,
53+
'errors' => $event->errors,
54+
];
55+
app('log')->info('Will send report message.');
56+
app('log')->debug('If no error below this line, mail was sent!');
57+
Mail::to(config('mail.destination'))->send(new ImportReportMail($log));
58+
app('log')->debug('If no error above this line, mail was sent!');
59+
}
60+
61+
}

app/Http/Controllers/DebugController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
namespace App\Http\Controllers;
2727

28-
use Artisan;
2928
use Carbon\Carbon;
30-
use DB;
3129
use Exception;
3230
use Illuminate\Contracts\View\Factory;
3331
use Illuminate\Http\Request;
@@ -44,7 +42,6 @@ class DebugController extends Controller
4442
* @param Request $request
4543
*
4644
* @return Factory|View
47-
* @throws FireflyException
4845
*/
4946
public function index(Request $request)
5047
{

0 commit comments

Comments
 (0)