public function doImport()
{
$source = Input::get('source');
$files = [];
foreach (ImportService::$entityTypes as $entityType) {
if (Input::file("{$entityType}_file")) {
$files[$entityType] = Input::file("{$entityType}_file")->getRealPath();
if ($source === IMPORT_CSV) {
Session::forget("{$entityType}-data");
}
}
}
if (!count($files)) {
Session::flash('error', trans('texts.select_file'));
return Redirect::to('/settings/' . ACCOUNT_IMPORT_EXPORT);
}
try {
if ($source === IMPORT_CSV) {
$data = $this->importService->mapCSV($files);
return View::make('accounts.import_map', ['data' => $data]);
} elseif ($source === IMPORT_JSON) {
$results = $this->importService->importJSON($files[IMPORT_JSON]);
return $this->showResult($results);
} else {
$results = $this->importService->importFiles($source, $files);
return $this->showResult($results);
}
} catch (Exception $exception) {
Utils::logError($exception);
Session::flash('error', $exception->getMessage());
return Redirect::to('/settings/' . ACCOUNT_IMPORT_EXPORT);
}
}