diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index 1abd269387b8..30af4a6e02b4 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -34,7 +34,7 @@ class ImportController extends BaseController $fileName = $entityType; if ($request->hasFile($fileName)) { $file = $request->file($fileName); - $destinationPath = storage_path() . '/import'; + $destinationPath = env('FILE_IMPORT_PATH') ?: storage_path() . '/import'; $extension = $file->getClientOriginalExtension(); if ($source === IMPORT_CSV) { @@ -53,7 +53,7 @@ class ImportController extends BaseController $newFileName = sprintf('%s_%s_%s.%s', Auth::user()->account_id, $timestamp, $fileName, $extension); $file->move($destinationPath, $newFileName); - $files[$entityType] = $newFileName; + $files[$entityType] = $destinationPath . '/' . $newFileName; } } @@ -112,6 +112,7 @@ class ImportController extends BaseController $map = Input::get('map'); $headers = Input::get('headers'); $timestamp = Input::get('timestamp'); + if (config('queue.default') === 'sync') { $results = $this->importService->importCSV($map, $headers, $timestamp); $message = $this->importService->presentResults($results); diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 3d7c3d325c43..952b0865f5b2 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -24,6 +24,7 @@ use Auth; use Cache; use Excel; use Exception; +use File; use League\Fractal\Manager; use parsecsv; use Session; @@ -145,10 +146,9 @@ class ImportService * * @return array */ - public function importJSON($file, $includeData, $includeSettings) + public function importJSON($fileName, $includeData, $includeSettings) { $this->initMaps(); - $fileName = $this->getFullPath($file); $this->checkForFile($fileName); $file = file_get_contents($fileName); $json = json_decode($file, true); @@ -229,7 +229,7 @@ class ImportService } } - @unlink($fileName); + File::delete($fileName); return $this->results; } @@ -278,7 +278,7 @@ class ImportService * * @return array */ - private function execute($source, $entityType, $file) + private function execute($source, $entityType, $fileName) { $results = [ RESULT_SUCCESS => [], @@ -287,7 +287,6 @@ class ImportService // Convert the data $row_list = []; - $fileName = $this->getFullPath($file); $this->checkForFile($fileName); Excel::load($fileName, function ($reader) use ($source, $entityType, &$row_list, &$results) { @@ -321,7 +320,7 @@ class ImportService } } - @unlink($fileName); + File::delete($fileName); return $results; } @@ -590,7 +589,6 @@ class ImportService { require_once app_path().'/Includes/parsecsv.lib.php'; - $fileName = $this->getFullPath($fileName); $this->checkForFile($fileName); $csv = new parseCSV(); @@ -686,7 +684,8 @@ class ImportService ]; $source = IMPORT_CSV; - $fileName = sprintf('%s_%s_%s.csv', Auth::user()->account_id, $timestamp, $entityType); + $path = env('FILE_IMPORT_PATH') ?: storage_path() . '/import'; + $fileName = sprintf('%s/%s_%s_%s.csv', $path, Auth::user()->account_id, $timestamp, $entityType); $data = $this->getCsvData($fileName); $this->checkData($entityType, count($data)); $this->initMaps(); @@ -726,7 +725,7 @@ class ImportService } } - @unlink($this->getFullPath($fileName)); + File::delete($fileName); return $results; } @@ -956,9 +955,4 @@ class ImportService return true; } - - public function getFullPath($fileName) - { - return (env('FILE_IMPORT_PATH') ?: storage_path() . '/import') . '/' . $fileName; - } }