mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Initial code base for new CSV import.
This commit is contained in:
		| @@ -2,7 +2,14 @@ | ||||
|  | ||||
| namespace FireflyIII\Http\Controllers; | ||||
|  | ||||
| use Crypt; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\ImportUploadRequest; | ||||
| use FireflyIII\Import\Importer\ImporterInterface; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| use SplFileObject; | ||||
| use Storage; | ||||
| use View; | ||||
|  | ||||
| /** | ||||
| @@ -22,6 +29,26 @@ class ImportController extends Controller | ||||
|         View::share('title', trans('firefly.import_data')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param ImportJob $job | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function configure(ImportJob $job) | ||||
|     { | ||||
|         // create proper importer (depends on job) | ||||
|         $type = $job->file_type; | ||||
|         /** @var ImporterInterface $importer */ | ||||
|         $importer = app('FireflyIII\Import\Importer\\' . ucfirst($type) . 'Importer'); | ||||
|         $importer->setJob($job); | ||||
|         $importer->configure(); | ||||
|         $data = $importer->getConfigurationData(); | ||||
|  | ||||
|         return view('import.' . $type . '.configure', compact('data', 'job')); | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||||
|      */ | ||||
| @@ -38,4 +65,27 @@ class ImportController extends Controller | ||||
|  | ||||
|         return view('import.index', compact('subTitle', 'subTitleIcon', 'importFileTypes', 'defaultImportType')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param ImportUploadRequest          $request | ||||
|      * @param ImportJobRepositoryInterface $repository | ||||
|      * | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||||
|      */ | ||||
|     public function upload(ImportUploadRequest $request, ImportJobRepositoryInterface $repository) | ||||
|     { | ||||
|         // create import job: | ||||
|         $type             = $request->get('import_file_type'); | ||||
|         $job              = $repository->create($type); | ||||
|         $upload           = $request->files->get('import_file'); | ||||
|         $newName          = $job->key . '.upload'; | ||||
|         $uploaded         = new SplFileObject($upload->getRealPath()); | ||||
|         $content          = $uploaded->fread($uploaded->getSize()); | ||||
|         $contentEncrypted = Crypt::encrypt($content); | ||||
|         $disk             = Storage::disk('upload'); | ||||
|         $disk->put($newName, $contentEncrypted); | ||||
|  | ||||
|         return redirect(route('import.configure', [$job->key])); | ||||
|  | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user