2017-08-04 15:56:14 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BankController.php
|
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2017-08-04 15:56:14 +02:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Import;
|
|
|
|
|
2017-12-09 12:08:24 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2017-08-04 15:56:14 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2017-12-09 19:13:00 +01:00
|
|
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
2017-08-11 05:21:00 +02:00
|
|
|
use FireflyIII\Support\Import\Prerequisites\PrerequisitesInterface;
|
2017-08-04 15:56:14 +02:00
|
|
|
|
|
|
|
class BankController extends Controller
|
|
|
|
{
|
2017-08-27 08:54:58 +02:00
|
|
|
|
|
|
|
/**
|
2017-12-09 19:13:00 +01:00
|
|
|
* Once there are no prerequisites, this method will create an importjob object and
|
|
|
|
* redirect the user to a view where this object can be used by a bank specific
|
|
|
|
* class to process.
|
2017-08-27 08:54:58 +02:00
|
|
|
*
|
2017-12-09 19:13:00 +01:00
|
|
|
* @param ImportJobRepositoryInterface $repository
|
|
|
|
* @param string $bank
|
2017-08-27 08:54:58 +02:00
|
|
|
*
|
2017-09-09 06:28:21 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|null
|
2017-12-09 19:13:00 +01:00
|
|
|
* @throws FireflyException
|
2017-08-27 08:54:58 +02:00
|
|
|
*/
|
2017-12-09 19:13:00 +01:00
|
|
|
public function createJob(ImportJobRepositoryInterface $repository, string $bank)
|
2017-08-27 08:54:58 +02:00
|
|
|
{
|
|
|
|
$class = config(sprintf('firefly.import_pre.%s', $bank));
|
2017-12-09 19:13:00 +01:00
|
|
|
if (!class_exists($class)) {
|
2017-12-09 12:08:24 +01:00
|
|
|
throw new FireflyException(sprintf('Cannot find class %s', $class));
|
|
|
|
}
|
2017-12-16 08:03:35 +01:00
|
|
|
$importJob = $repository->create($bank);
|
|
|
|
$config = $importJob->configuration;
|
|
|
|
$config['has-config-file'] = false;
|
|
|
|
$config['auto-start'] = true;
|
|
|
|
$importJob->configuration = $config;
|
|
|
|
$importJob->save();
|
2017-08-27 08:54:58 +02:00
|
|
|
|
2017-12-09 20:02:26 +01:00
|
|
|
return redirect(route('import.file.configure', [$importJob->key]));
|
2017-08-12 07:47:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 21:09:22 +02:00
|
|
|
|
2017-08-12 07:48:39 +02:00
|
|
|
}
|