From 2fb227714a528a7bda1bc1bf7b390bb8d93ac3e7 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 26 Jun 2017 23:44:55 +0300 Subject: [PATCH] Email error if import fails --- app/Jobs/ImportData.php | 38 ++++++++++++++++------------ app/Listeners/HandleUserLoggedIn.php | 2 +- resources/lang/en/texts.php | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/Jobs/ImportData.php b/app/Jobs/ImportData.php index b1427775f7ed..b9f199aa2d77 100644 --- a/app/Jobs/ImportData.php +++ b/app/Jobs/ImportData.php @@ -67,24 +67,30 @@ class ImportData extends Job implements ShouldQueue $this->user->account->loadLocalizationSettings(); } - if ($this->type === IMPORT_JSON) { - $includeData = $this->settings['include_data']; - $includeSettings = $this->settings['include_settings']; - $files = $this->settings['files']; - $results = $importService->importJSON($files[IMPORT_JSON], $includeData, $includeSettings); - } elseif ($this->type === IMPORT_CSV) { - $map = $this->settings['map']; - $headers = $this->settings['headers']; - $timestamp = $this->settings['timestamp']; - $results = $importService->importCSV($map, $headers, $timestamp); - } else { - $source = $this->settings['source']; - $files = $this->settings['files']; - $results = $importService->importFiles($source, $files); + try { + if ($this->type === IMPORT_JSON) { + $includeData = $this->settings['include_data']; + $includeSettings = $this->settings['include_settings']; + $files = $this->settings['files']; + $results = $importService->importJSON($files[IMPORT_JSON], $includeData, $includeSettings); + } elseif ($this->type === IMPORT_CSV) { + $map = $this->settings['map']; + $headers = $this->settings['headers']; + $timestamp = $this->settings['timestamp']; + $results = $importService->importCSV($map, $headers, $timestamp); + } else { + $source = $this->settings['source']; + $files = $this->settings['files']; + $results = $importService->importFiles($source, $files); + } + + $subject = trans('texts.import_complete'); + $message = $importService->presentResults($results, $includeSettings); + } catch (Exception $exception) { + $subject = trans('texts.import_failed'); + $message = $exception->getMessage(); } - $subject = trans('texts.import_complete'); - $message = $importService->presentResults($results, $includeSettings); $userMailer->sendMessage($this->user, $subject, $message); if (App::runningInConsole()) { diff --git a/app/Listeners/HandleUserLoggedIn.php b/app/Listeners/HandleUserLoggedIn.php index 9f330b5b1e2b..7f2d0453d4d0 100644 --- a/app/Listeners/HandleUserLoggedIn.php +++ b/app/Listeners/HandleUserLoggedIn.php @@ -43,7 +43,7 @@ class HandleUserLoggedIn { $account = Auth::user()->account; - if (empty($account->last_login)) { + if (! Utils::isNinja() && empty($account->last_login)) { event(new UserSignedUp()); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 8ad7014965da..ecf1e60b2373 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2289,7 +2289,7 @@ $LANG = array( 'deleted_recurring_expense' => 'Successfully deleted :count projects', 'view_recurring_expense' => 'View Recurring Expense', 'other' => 'Other', - + 'import_failed' => 'Import Failed', );