2424
2525namespace App \Console ;
2626
27+ use App \Events \ImportedTransactions ;
2728use App \Exceptions \ImporterErrorException ;
28- use App \Services \CSV \Configuration \Configuration ;
2929use App \Services \CSV \Conversion \RoutineManager as CSVRoutineManager ;
3030use App \Services \Nordigen \Conversion \RoutineManager as NordigenRoutineManager ;
31+ use App \Services \Shared \Configuration \Configuration ;
3132use App \Services \Shared \Conversion \ConversionStatus ;
3233use App \Services \Shared \Conversion \RoutineStatusManager ;
3334use App \Services \Shared \Import \Routine \RoutineManager ;
3637use App \Services \Spectre \Conversion \RoutineManager as SpectreRoutineManager ;
3738use Illuminate \Contracts \Filesystem \FileNotFoundException ;
3839use JsonException ;
39- use Log ;
4040use 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 /**
0 commit comments