mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +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]));
|
||||
|
||||
}
|
||||
}
|
||||
|
46
app/Http/Requests/ImportUploadRequest.php
Normal file
46
app/Http/Requests/ImportUploadRequest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportUploadRequest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class ImportUploadRequest
|
||||
*
|
||||
*
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class ImportUploadRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$types = array_keys(config('firefly.import_formats'));
|
||||
|
||||
return [
|
||||
'import_file' => 'required|file',
|
||||
'import_file_type' => 'required|in:' . join(',', $types),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
@@ -223,8 +223,9 @@ Route::group(
|
||||
/**
|
||||
* IMPORT CONTROLLER
|
||||
*/
|
||||
Route::get('/import', ['uses' => 'ImportController@index', 'as' => 'import.index']);
|
||||
Route::post('/import/upload', ['uses' => 'ImportController@upload', 'as' => 'import.upload']);
|
||||
Route::get('/import', ['uses' => 'ImportController@index','as' => 'import.index']);
|
||||
Route::post('/import/upload', ['uses' => 'ImportController@upload','as' => 'import.upload']);
|
||||
Route::get('/import/configure/{importJob}', ['uses' => 'ImportController@configure','as' => 'import.configure']);
|
||||
|
||||
/**
|
||||
* Help Controller
|
||||
|
Reference in New Issue
Block a user