mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Remove import code.
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Api\TransactionFilter;
|
||||
use FireflyIII\Transformers\ImportJobTransformer;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
|
||||
/**
|
||||
* Class ImportController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ImportController extends Controller
|
||||
{
|
||||
use TransactionFilter;
|
||||
/** @var ImportJobRepositoryInterface Import job repository. */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ImportController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($user);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function listAll(): JsonResponse
|
||||
{
|
||||
// create some objects:
|
||||
$manager = $this->getManager();
|
||||
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||
|
||||
// get list of accounts. Count it and split it.
|
||||
$collection = $this->repository->get();
|
||||
$count = $collection->count();
|
||||
$importJobs = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||
|
||||
// make paginator:
|
||||
$paginator = new LengthAwarePaginator($importJobs, $count, $pageSize, $this->parameters->get('page'));
|
||||
$paginator->setPath(route('api.v1.import.list') . $this->buildParams());
|
||||
|
||||
/** @var ImportJobTransformer $transformer */
|
||||
$transformer = app(ImportJobTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
$resource = new FractalCollection($importJobs, $transformer, 'import_jobs');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
/** @var ImportJobTransformer $transformer */
|
||||
$transformer = app(ImportJobTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
$resource = new Item($importJob, $transformer, 'import_jobs');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all transactions
|
||||
*
|
||||
* @param Request $request
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, ImportJob $importJob): JsonResponse
|
||||
{
|
||||
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||
$type = $request->get('type') ?? 'default';
|
||||
$this->parameters->set('type', $type);
|
||||
|
||||
$types = $this->mapTransactionTypes($this->parameters->get('type'));
|
||||
$manager = $this->getManager();
|
||||
|
||||
$tag = $importJob->tag;
|
||||
$transactions = new Collection();
|
||||
$paginator = new LengthAwarePaginator($transactions, 0, $pageSize);
|
||||
$paginator->setPath(route('api.v1.import.transactions', [$importJob->key]) . $this->buildParams());
|
||||
|
||||
if (null !== $tag) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
// use new group collector:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector
|
||||
->setUser($admin)
|
||||
// filter on tag.
|
||||
->setTag($tag)
|
||||
// all info needed for the API:
|
||||
->withAPIInformation()
|
||||
// set page size:
|
||||
->setLimit($pageSize)
|
||||
// set page to retrieve
|
||||
->setPage($this->parameters->get('page'))
|
||||
// set types of transactions to return.
|
||||
->setTypes($types);
|
||||
|
||||
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
|
||||
$transactions = $paginator->getCollection();
|
||||
}
|
||||
|
||||
/** @var TransactionGroupTransformer $transformer */
|
||||
$transformer = app(TransactionGroupTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
$resource = new FractalCollection($transactions, $transformer, 'transactions');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateCSVImport.php
|
||||
* Copyright (c) 2020 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @noinspection MultipleReturnStatementsInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Import;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Console\Commands\VerifiesAccessToken;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\Routine\RoutineInterface;
|
||||
use FireflyIII\Import\Storage\ImportArrayStorage;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class CreateCSVImport.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CreateCSVImport extends Command
|
||||
{
|
||||
use VerifiesAccessToken;
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Use this command to create a new CSV file import.';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature
|
||||
= 'firefly-iii:csv-import
|
||||
{file? : The CSV file to import.}
|
||||
{configuration? : The configuration file to use for the import.}
|
||||
{--user=1 : The user ID that the import should import for.}
|
||||
{--token= : The user\'s access token.}';
|
||||
/**
|
||||
* Run the command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->error('This command is disabled.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -60,7 +60,7 @@ class ApplyRules extends Command
|
||||
*/
|
||||
protected $signature
|
||||
= 'firefly-iii:apply-rules
|
||||
{--user=1 : The user ID that the import should import for.}
|
||||
{--user=1 : The user ID.}
|
||||
{--token= : The user\'s access token.}
|
||||
{--accounts= : A comma-separated list of asset accounts or liabilities to apply your rules to.}
|
||||
{--rule_groups= : A comma-separated list of rule groups to apply. Take the ID\'s of these rule groups from the Firefly III interface.}
|
||||
|
@@ -224,15 +224,14 @@ class DebugController extends Controller
|
||||
{
|
||||
$set = RouteFacade::getRoutes();
|
||||
$ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.', 'attachments.download', 'attachments.preview',
|
||||
'bills.rescan', 'budgets.income', 'currencies.def', 'error', 'flush', 'help.show', 'import.file',
|
||||
'bills.rescan', 'budgets.income', 'currencies.def', 'error', 'flush', 'help.show',
|
||||
'login', 'logout', 'password.reset', 'profile.confirm-email-change', 'profile.undo-email-change',
|
||||
'register', 'report.options', 'routes', 'rule-groups.down', 'rule-groups.up', 'rules.up', 'rules.down',
|
||||
'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
|
||||
'two-factor.lost', 'reports.options', 'debug', 'import.create-job', 'import.download', 'import.start', 'import.status.json',
|
||||
'two-factor.lost', 'reports.options', 'debug',
|
||||
'preferences.delete-code', 'rules.test-triggers', 'piggy-banks.remove-money', 'piggy-banks.add-money',
|
||||
'accounts.reconcile.transactions', 'accounts.reconcile.overview',
|
||||
'transactions.clone', 'two-factor.index', 'api.v1', 'installer.', 'attachments.view', 'import.create',
|
||||
'import.job.download', 'import.job.start', 'import.job.status.json', 'import.job.store', 'recurring.events',
|
||||
'transactions.clone', 'two-factor.index', 'api.v1', 'installer.', 'attachments.view', 'recurring.events',
|
||||
'recurring.suggest',
|
||||
];
|
||||
$return = ' ';
|
||||
|
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CallbackController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class CallbackController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CallbackController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Callback specifically for YNAB logins.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @param ImportJobRepositoryInterface $repository
|
||||
*
|
||||
* @return Factory|RedirectResponse|Redirector|View
|
||||
*/
|
||||
public function ynab(Request $request, ImportJobRepositoryInterface $repository)
|
||||
{
|
||||
$code = (string) $request->get('code');
|
||||
$jobKey = (string) $request->get('state');
|
||||
|
||||
if ('' === $code) {
|
||||
return view('error')->with('message', 'You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.');
|
||||
}
|
||||
|
||||
$importJob = $repository->findByKey($jobKey);
|
||||
|
||||
if ('' === $jobKey || null === $importJob) {
|
||||
return view('error')->with('message', 'You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.');
|
||||
}
|
||||
Log::debug(sprintf('Got a code from YNAB: %s', $code));
|
||||
|
||||
// we have a code. Make the job ready for the next step, and then redirect the user.
|
||||
$configuration = $repository->getConfiguration($importJob);
|
||||
$configuration['auth_code'] = $code;
|
||||
$repository->setConfiguration($importJob, $configuration);
|
||||
|
||||
// set stage to make the import routine take the correct action:
|
||||
$repository->setStatus($importJob, 'ready_to_run');
|
||||
$repository->setStage($importJob, 'get_access_token');
|
||||
|
||||
return redirect(route('import.job.status.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
}
|
@@ -1,198 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Support\Binder\ImportProvider;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response as LaravelResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class IndexController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class IndexController extends Controller
|
||||
{
|
||||
/** @var array All available providers */
|
||||
public $providers;
|
||||
/** @var ImportJobRepositoryInterface The import job repository */
|
||||
public $repository;
|
||||
/** @var UserRepositoryInterface The user repository */
|
||||
public $userRepository;
|
||||
|
||||
/**
|
||||
* IndexController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', (string) trans('firefly.import_index_title'));
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->providers = ImportProvider::getProviders();
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new import job for $importProvider.
|
||||
*
|
||||
* @param string $importProvider
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
*
|
||||
*/
|
||||
public function create(string $importProvider)
|
||||
{
|
||||
$hasPreReq = (bool) config(sprintf('import.has_prereq.%s', $importProvider));
|
||||
$hasConfig = (bool) config(sprintf('import.has_job_config.%s', $importProvider));
|
||||
$allowedForDemo = (bool) config(sprintf('import.allowed_for_demo.%s', $importProvider));
|
||||
$isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo');
|
||||
|
||||
Log::debug(sprintf('Will create job for provider "%s"', $importProvider));
|
||||
Log::debug(sprintf('Is demo user? %s', var_export($isDemoUser, true)));
|
||||
Log::debug(sprintf('Is allowed for user? %s', var_export($allowedForDemo, true)));
|
||||
Log::debug(sprintf('Has prerequisites? %s', var_export($hasPreReq, true)));
|
||||
Log::debug(sprintf('Has config? %s', var_export($hasConfig, true)));
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($isDemoUser && !$allowedForDemo) {
|
||||
Log::debug('User is demo and this provider doesnt work for demo users.');
|
||||
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$importJob = $this->repository->create($importProvider);
|
||||
|
||||
Log::debug(sprintf('Created job #%d for provider %s', $importJob->id, $importProvider));
|
||||
|
||||
// no prerequisites but job has config:
|
||||
if (false === $hasPreReq && false !== $hasConfig) {
|
||||
Log::debug('Provider has no prerequisites. Continue.');
|
||||
$this->repository->setStatus($importJob, 'has_prereq');
|
||||
Log::debug('Redirect to configuration.');
|
||||
|
||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
// job has prerequisites:
|
||||
Log::debug('Job provider has prerequisites.');
|
||||
/** @var PrerequisitesInterface $providerPre */
|
||||
$providerPre = app((string) config(sprintf('import.prerequisites.%s', $importProvider)));
|
||||
$providerPre->setUser($importJob->user);
|
||||
|
||||
// and are not filled in:
|
||||
if (!$providerPre->isComplete()) {
|
||||
Log::debug('Job provider prerequisites are not yet filled in. Redirect to prerequisites-page.');
|
||||
|
||||
// redirect to global prerequisites
|
||||
return redirect(route('import.prerequisites.index', [$importProvider, $importJob->key]));
|
||||
}
|
||||
Log::debug('Prerequisites are complete.');
|
||||
|
||||
// but are filled in:
|
||||
$this->repository->setStatus($importJob, 'has_prereq');
|
||||
|
||||
// and has no config:
|
||||
if (false === $hasConfig) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug('Provider has no configuration. Job is ready to start.');
|
||||
$this->repository->setStatus($importJob, 'ready_to_run');
|
||||
Log::debug('Redirect to status-page.');
|
||||
|
||||
return redirect(route('import.job.status.index', [$importJob->key]));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// but also needs config:
|
||||
Log::debug('Job has configuration. Redirect to job-config.');
|
||||
|
||||
// Otherwise just redirect to job configuration.
|
||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a JSON file of the job's configuration and send it to the user.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return LaravelResponse
|
||||
*/
|
||||
public function download(ImportJob $job): LaravelResponse
|
||||
{
|
||||
Log::debug('Now in download()', ['job' => $job->key]);
|
||||
$config = $this->repository->getConfiguration($job);
|
||||
// This is CSV import specific:
|
||||
$config['delimiter'] = $config['delimiter'] ?? ',';
|
||||
$config['delimiter'] = "\t" === $config['delimiter'] ? 'tab' : $config['delimiter'];
|
||||
|
||||
$result = json_encode($config, JSON_PRETTY_PRINT);
|
||||
$name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
|
||||
/** @var LaravelResponse $response */
|
||||
$response = response($result);
|
||||
$response->header('Content-disposition', 'attachment; filename=' . $name)
|
||||
->header('Content-Type', 'application/json')
|
||||
->header('Content-Description', 'File Transfer')
|
||||
->header('Connection', 'Keep-Alive')
|
||||
->header('Expires', '0')
|
||||
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
||||
->header('Pragma', 'public')
|
||||
->header('Content-Length', strlen($result));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* General import index.
|
||||
*
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$providers = $this->providers;
|
||||
$subTitle = (string) trans('import.index_breadcrumb');
|
||||
$subTitleIcon = 'fa-home';
|
||||
$isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo');
|
||||
|
||||
return view('import.index', compact('subTitle', 'subTitleIcon', 'providers', 'isDemoUser'));
|
||||
}
|
||||
}
|
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* JobConfigurationController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class JobConfigurationController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class JobConfigurationController extends Controller
|
||||
{
|
||||
use CreateStuff;
|
||||
/** @var ImportJobRepositoryInterface The import job repository */
|
||||
public $repository;
|
||||
|
||||
/**
|
||||
* JobConfigurationController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', (string) trans('firefly.import_index_title'));
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the job. This method is returned to until job is deemed "configured".
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return Factory|RedirectResponse|Redirector|View
|
||||
*
|
||||
*/
|
||||
public function index(ImportJob $importJob)
|
||||
{
|
||||
Log::debug('Now in JobConfigurationController::index()');
|
||||
$allowed = ['has_prereq', 'need_job_config'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job has state "%s", but we only accept %s', $importJob->status, json_encode($allowed)));
|
||||
session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)]));
|
||||
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
Log::debug(sprintf('Now in JobConfigurationController::index() with job "%s" and status "%s"', $importJob->key, $importJob->status));
|
||||
|
||||
// if provider has no config, just push it through:
|
||||
$importProvider = $importJob->provider;
|
||||
if (!(bool) config(sprintf('import.has_job_config.%s', $importProvider))) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug('Job needs no config, is ready to run!');
|
||||
$this->repository->setStatus($importJob, 'ready_to_run');
|
||||
|
||||
return redirect(route('import.job.status.index', [$importJob->key]));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$configurator = $this->makeConfigurator($importJob);
|
||||
if ($configurator->configurationComplete()) {
|
||||
Log::debug('Config is complete, set status to ready_to_run.');
|
||||
$this->repository->setStatus($importJob, 'ready_to_run');
|
||||
|
||||
return redirect(route('import.job.status.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
$view = $configurator->getNextView();
|
||||
$data = $configurator->getNextData();
|
||||
$subTitle = (string) trans('import.job_configuration_breadcrumb', ['key' => $importJob->key]);
|
||||
$subTitleIcon = 'fa-wrench';
|
||||
|
||||
return view($view, compact('data', 'importJob', 'subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the configuration. Returns to "configure" method until job is configured.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return RedirectResponse|Redirector
|
||||
*
|
||||
*/
|
||||
public function post(Request $request, ImportJob $importJob)
|
||||
{
|
||||
// catch impossible status:
|
||||
$allowed = ['has_prereq', 'need_job_config'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)]));
|
||||
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
|
||||
Log::debug('Now in postConfigure()', ['job' => $importJob->key]);
|
||||
$configurator = $this->makeConfigurator($importJob);
|
||||
|
||||
// is the job already configured?
|
||||
if ($configurator->configurationComplete()) {
|
||||
$this->repository->setStatus($importJob, 'ready_to_run');
|
||||
|
||||
return redirect(route('import.job.status.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
// uploaded files are attached to the job.
|
||||
// the configurator can then handle them.
|
||||
$result = new MessageBag;
|
||||
|
||||
/** @var UploadedFile $upload */
|
||||
foreach ($request->allFiles() as $name => $upload) {
|
||||
$result = $this->repository->storeFileUpload($importJob, $name, $upload);
|
||||
}
|
||||
$data = $request->all();
|
||||
$messages = $configurator->configureJob($data);
|
||||
$result->merge($messages);
|
||||
|
||||
if ($messages->count() > 0) {
|
||||
$request->session()->flash('warning', $messages->first());
|
||||
}
|
||||
|
||||
// return to configure
|
||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,240 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* JobStatusController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Import\Routine\RoutineInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class JobStatusController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class JobStatusController extends Controller
|
||||
{
|
||||
use CreateStuff;
|
||||
/** @var ImportJobRepositoryInterface The import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* JobStatusController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// set time limit to zero to prevent timeouts.
|
||||
set_time_limit(0);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', (string) trans('firefly.import_index_title'));
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index for job status.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(ImportJob $importJob)
|
||||
{
|
||||
$subTitleIcon = 'fa-gear';
|
||||
$subTitle = (string) trans('import.job_status_breadcrumb', ['key' => $importJob->key]);
|
||||
|
||||
return view('import.status', compact('importJob', 'subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON overview of job status.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function json(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
$count = $this->repository->countTransactions($importJob);
|
||||
$json = [
|
||||
'status' => $importJob->status,
|
||||
'errors' => $importJob->errors,
|
||||
'count' => $count,
|
||||
'tag_id' => $importJob->tag_id,
|
||||
'tag_name' => null === $importJob->tag_id ? null : $importJob->tag->tag,
|
||||
'report_txt' => (string) trans('import.unknown_import_result'),
|
||||
'download_config' => false,
|
||||
'download_config_text' => '',
|
||||
];
|
||||
|
||||
if ('file' === $importJob->provider) {
|
||||
$json['download_config'] = true;
|
||||
$json['download_config_text']
|
||||
= trans('import.should_download_config', ['route' => route('import.job.download', [$importJob->key])]) . ' '
|
||||
. trans('import.share_config_file');
|
||||
}
|
||||
|
||||
// if count is zero:
|
||||
if (null !== $importJob->tag_id) {
|
||||
$count = $this->repository->countByTag($importJob);
|
||||
}
|
||||
if (0 === $count) {
|
||||
$json['report_txt'] = (string) trans('import.result_no_transactions');
|
||||
}
|
||||
if (1 === $count && null !== $importJob->tag_id) {
|
||||
$json['report_txt'] = trans(
|
||||
'import.result_one_transaction',
|
||||
['route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag]
|
||||
);
|
||||
}
|
||||
if ($count > 1 && null !== $importJob->tag_id) {
|
||||
$json['report_txt'] = trans(
|
||||
'import.result_many_transactions',
|
||||
['count' => $count, 'route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag]
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json($json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls to start the job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function start(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
Log::info('Now in JobStatusController::start');
|
||||
// catch impossible status:
|
||||
$allowed = ['ready_to_run', 'need_job_config'];
|
||||
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job is not ready. Status should be in array, but is %s', $importJob->status), $allowed);
|
||||
$this->repository->setStatus($importJob, 'error');
|
||||
|
||||
return response()->json(
|
||||
['status' => 'NOK', 'message' => sprintf('JobStatusController::start expects status "ready_to_run" instead of "%s".', $importJob->status)]
|
||||
);
|
||||
}
|
||||
$importProvider = $importJob->provider;
|
||||
$key = sprintf('import.routine.%s', $importProvider);
|
||||
$className = config($key);
|
||||
if (null === $className || !class_exists($className)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$message = sprintf('Cannot find import routine class for job of type "%s".', $importProvider);
|
||||
Log::error($message);
|
||||
|
||||
return response()->json(
|
||||
['status' => 'NOK', 'message' => $message]
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/** @var RoutineInterface $routine */
|
||||
$routine = app($className);
|
||||
$routine->setImportJob($importJob);
|
||||
|
||||
Log::debug(sprintf('Created class of type %s', $className));
|
||||
|
||||
try {
|
||||
Log::debug(sprintf('Try to call %s:run()', $className));
|
||||
$routine->run();
|
||||
} catch (FireflyException|Exception $e) {
|
||||
$message = 'The import routine crashed: ' . $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
// set job errored out:
|
||||
$this->repository->setStatus($importJob, 'error');
|
||||
|
||||
return response()->json(['status' => 'NOK', 'message' => $message]);
|
||||
}
|
||||
|
||||
// expect nothing from routine, just return OK to user.
|
||||
Log::info('Now finished with JobStatusController::start');
|
||||
|
||||
return response()->json(['status' => 'OK', 'message' => 'stage_finished']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store does three things:
|
||||
*
|
||||
* - Store the transactions.
|
||||
* - Add them to a tag.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
Log::info('Now in JobStatusController::store');
|
||||
// catch impossible status:
|
||||
$allowed = ['provider_finished', 'storing_data'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job is not ready. Status should be in array, but is %s', $importJob->status), $allowed);
|
||||
|
||||
return response()->json(
|
||||
['status' => 'NOK', 'message' => sprintf('JobStatusController::start expects status "provider_finished" instead of "%s".', $importJob->status)]
|
||||
);
|
||||
}
|
||||
|
||||
// set job to be storing data:
|
||||
$this->repository->setStatus($importJob, 'storing_data');
|
||||
|
||||
try {
|
||||
$this->storeTransactions($importJob);
|
||||
} catch (FireflyException $e) {
|
||||
$message = 'The import storage routine crashed: ' . $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
// set job errored out:
|
||||
$this->repository->setStatus($importJob, 'error');
|
||||
|
||||
return response()->json(['status' => 'NOK', 'message' => $message]);
|
||||
}
|
||||
// set storage to be finished:
|
||||
$this->repository->setStatus($importJob, 'storage_finished');
|
||||
|
||||
Log::info('Now finished with JobStatusController::start');
|
||||
|
||||
// expect nothing from routine, just return OK to user.
|
||||
return response()->json(['status' => 'OK', 'message' => 'storage_finished']);
|
||||
}
|
||||
}
|
@@ -1,177 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PrerequisitesController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class PrerequisitesController
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class PrerequisitesController extends Controller
|
||||
{
|
||||
|
||||
/** @var ImportJobRepositoryInterface The import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* PrerequisitesController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', (string) trans('firefly.import_index_title'));
|
||||
app('view')->share('subTitleIcon', 'fa-check');
|
||||
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will process and store import provider global prerequisites
|
||||
* such as API keys.
|
||||
*
|
||||
* @param string $importProvider
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return Factory|RedirectResponse|Redirector|View
|
||||
*/
|
||||
public function index(string $importProvider, ImportJob $importJob = null)
|
||||
{
|
||||
// catch impossible status:
|
||||
$allowed = ['new'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job has state "%s" but this Prerequisites::index() only accepts %s', $importJob->status, json_encode($allowed)));
|
||||
session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)]));
|
||||
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
|
||||
app('view')->share('subTitle', (string) trans('import.prerequisites_breadcrumb_' . $importProvider));
|
||||
$class = (string) config(sprintf('import.prerequisites.%s', $importProvider));
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser($user);
|
||||
|
||||
if (null !== $importJob && $object->isComplete()) {
|
||||
// update job:
|
||||
$this->repository->setStatus($importJob, 'has_prereq');
|
||||
|
||||
// redirect to job config:
|
||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||
}
|
||||
|
||||
|
||||
$view = $object->getView();
|
||||
$parameters = ['title' => (string) trans('firefly.import_index_title'), 'mainTitleIcon' => 'fa-archive', 'importJob' => $importJob];
|
||||
$parameters = array_merge($object->getViewParameters(), $parameters);
|
||||
|
||||
return view($view, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method processes the prerequisites the user has entered in the previous step.
|
||||
*
|
||||
* Whatever storePrerequisites does, it should make sure that the system is ready to continue immediately. So
|
||||
* no extra calls or stuff, except maybe to open a session
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $importProvider
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
* @see PrerequisitesInterface::storePrerequisites
|
||||
*
|
||||
*/
|
||||
public function post(Request $request, string $importProvider, ImportJob $importJob = null)
|
||||
{
|
||||
Log::debug(sprintf('Now in postPrerequisites for %s', $importProvider));
|
||||
|
||||
// catch impossible status:
|
||||
$allowed = ['new'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job has state "%s" but this Prerequisites::post() only accepts %s', $importJob->status, json_encode($allowed)));
|
||||
session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)]));
|
||||
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
|
||||
|
||||
$class = (string) config(sprintf('import.prerequisites.%s', $importProvider));
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser($user);
|
||||
Log::debug('Going to store entered prerequisites.');
|
||||
// store post data
|
||||
$data = $request->all();
|
||||
$result = $object->storePrerequisites($data);
|
||||
Log::debug(sprintf('Result of storePrerequisites has message count: %d', $result->count()));
|
||||
|
||||
if ($result->count() > 0) {
|
||||
$request->session()->flash('error', e($result->first()));
|
||||
|
||||
// redirect back to job, if has job:
|
||||
return redirect(route('import.prerequisites.index', [$importProvider, $importJob->key ?? '']))->withInput();
|
||||
}
|
||||
|
||||
// session flash!
|
||||
$request->session()->flash('success', (string) trans('import.prerequisites_saved_for_' . $importProvider));
|
||||
|
||||
// if has job, redirect to global config for provider
|
||||
// if no job, back to index!
|
||||
if (null === $importJob) {
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
|
||||
// update job:
|
||||
$this->repository->setStatus($importJob, 'has_prereq');
|
||||
|
||||
// redirect to job config:
|
||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -1,234 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Amount.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Amount.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Amount implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
|
||||
* - Jamie Zawinski.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
if (null === $value) {
|
||||
return '0';
|
||||
}
|
||||
Log::debug(sprintf('Start with amount "%s"', $value));
|
||||
$original = $value;
|
||||
$value = $this->stripAmount((string) $value);
|
||||
$decimal = null;
|
||||
|
||||
if ($this->decimalIsDot($value)) {
|
||||
$decimal = '.';
|
||||
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
|
||||
}
|
||||
|
||||
if ($this->decimalIsComma($value)) {
|
||||
$decimal = ',';
|
||||
Log::debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
|
||||
}
|
||||
|
||||
// decimal character is null? find out if "0.1" or ".1" or "0,1" or ",1"
|
||||
if ($this->alternativeDecimalSign($value)) {
|
||||
$decimal = $this->getAlternativeDecimalSign($value);
|
||||
}
|
||||
|
||||
// decimal character still null? Search from the left for '.',',' or ' '.
|
||||
if (null === $decimal) {
|
||||
$decimal = $this->findFromLeft($value);
|
||||
}
|
||||
|
||||
// if decimal is dot, replace all comma's and spaces with nothing
|
||||
if (null !== $decimal) {
|
||||
$value = $this->replaceDecimal($decimal, $value);
|
||||
Log::debug(sprintf('Converted amount from "%s" to "%s".', $original, $value));
|
||||
}
|
||||
|
||||
if (null === $decimal) {
|
||||
// replace all:
|
||||
$search = ['.', ' ', ','];
|
||||
$value = str_replace($search, '', $value);
|
||||
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $original, $value));
|
||||
}
|
||||
if (strpos($value, '.') === 0) {
|
||||
$value = '0' . $value;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
Log::debug(sprintf('Final NUMERIC value is: "%s"', $value));
|
||||
|
||||
return $value;
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug(sprintf('Final value is: "%s"', $value));
|
||||
$formatted = sprintf('%01.12f', $value);
|
||||
Log::debug(sprintf('Is formatted to : "%s"', $formatted));
|
||||
|
||||
return $formatted;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value has a dot or comma on an alternative place,
|
||||
* catching strings like ",1" or ".5".
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function alternativeDecimalSign(string $value): bool
|
||||
{
|
||||
$length = strlen($value);
|
||||
$altPosition = $length - 2;
|
||||
|
||||
return $length > 1 && ('.' === $value[$altPosition] || ',' === $value[$altPosition]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to see if the decimal separator is a comma.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function decimalIsComma(string $value): bool
|
||||
{
|
||||
$length = strlen($value);
|
||||
$decimalPosition = $length - 3;
|
||||
|
||||
return $length > 2 && ',' === $value[$decimalPosition];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to see if the decimal separator is a dot.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function decimalIsDot(string $value): bool
|
||||
{
|
||||
$length = strlen($value);
|
||||
$decimalPosition = $length - 3;
|
||||
|
||||
return ($length > 2 && '.' === $value[$decimalPosition]) || ($length > 2 && strpos($value, '.') > $decimalPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search from the left for decimal sign.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function findFromLeft(string $value): ?string
|
||||
{
|
||||
$decimal = null;
|
||||
Log::debug('Decimal is still NULL, probably number with >2 decimals. Search for a dot.');
|
||||
$res = strrpos($value, '.');
|
||||
if (!(false === $res)) {
|
||||
// blandly assume this is the one.
|
||||
Log::debug(sprintf('Searched from the left for "." in amount "%s", assume this is the decimal sign.', $value));
|
||||
$decimal = '.';
|
||||
}
|
||||
|
||||
return $decimal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alternative decimal point used, such as a dot or a comma,
|
||||
* from strings like ",1" or "0.5".
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getAlternativeDecimalSign(string $value): string
|
||||
{
|
||||
$length = strlen($value);
|
||||
$altPosition = $length - 2;
|
||||
|
||||
return $value[$altPosition];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces other characters like thousand separators with nothing to make the decimal separator the only special
|
||||
* character in the string.
|
||||
*
|
||||
* @param string $decimal
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function replaceDecimal(string $decimal, string $value): string
|
||||
{
|
||||
$search = [',', ' ']; // default when decimal sign is a dot.
|
||||
if (',' === $decimal) {
|
||||
$search = ['.', ' '];
|
||||
}
|
||||
$value = str_replace($search, '', $value);
|
||||
|
||||
/** @noinspection CascadeStringReplacementInspection */
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip amount from weird characters.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function stripAmount(string $value): string
|
||||
{
|
||||
if (0 === strpos($value, '--')) {
|
||||
$value = substr($value, 2);
|
||||
}
|
||||
// have to strip the € because apparantly the Postbank (DE) thinks "1.000,00 €" is a normal way to format a number.
|
||||
$value = trim((string) str_replace(['€'], '', $value));
|
||||
$str = preg_replace('/[^\-\(\)\.\,0-9 ]/', '', $value);
|
||||
$len = strlen($str);
|
||||
if ('(' === $str[0] && ')' === $str[$len - 1]) {
|
||||
$str = '-' . substr($str, 1, $len - 2);
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Stripped "%s" away to "%s"', $value, $str));
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AmountCredit.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
/**
|
||||
* Class AmountCredit
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AmountCredit implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Convert an amount, always return positive.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app(Amount::class);
|
||||
$result = $converter->convert($value);
|
||||
$result = app('steam')->positive($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AmountDebit.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
/**
|
||||
* Class AmountDebit
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AmountDebit implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Convert amount, always return positive.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app(Amount::class);
|
||||
$result = $converter->convert($value);
|
||||
$result = app('steam')->positive($result);
|
||||
$result = bcmul($result, '-1');
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AmountNegated.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
/**
|
||||
* Class AmountNegated
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AmountNegated implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Negate amount.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app(Amount::class);
|
||||
$result = $converter->convert($value);
|
||||
$result = bcmul($result, '-1');
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BankDebitCredit.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class BankDebitCredit
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BankDebitCredit implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert a value.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function convert($value): int
|
||||
{
|
||||
Log::debug('Going to convert ', ['value' => $value]);
|
||||
$negative = [
|
||||
'D', // Old style Rabobank (NL). Short for "Debit"
|
||||
'A', // New style Rabobank (NL). Short for "Af"
|
||||
'DR', // https://old.reddit.com/r/FireflyIII/comments/bn2edf/generic_debitcredit_indicator/
|
||||
'Af', // ING (NL).
|
||||
'Debet', // Triodos (NL)
|
||||
'S', // "Soll", German term for debit
|
||||
'Debit', // Community America (US)
|
||||
];
|
||||
if (in_array(trim($value), $negative, true)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ConverterInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
/**
|
||||
* Interface ConverterInterface.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Convert a value.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function convert($value);
|
||||
}
|
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BunqJobConfiguration.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Bunq\BunqJobConfigurationInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class BunqJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BunqJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var BunqJobConfigurationInterface Bunq job interface */
|
||||
private $handler;
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
return $this->handler->configurationComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
return $this->handler->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
return $this->handler->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
return $this->handler->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
$this->handler = $this->getHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct handler.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return BunqJobConfigurationInterface
|
||||
*/
|
||||
private function getHandler(): BunqJobConfigurationInterface
|
||||
{
|
||||
Log::debug(sprintf('Now in BunqJobConfiguration::getHandler() with stage "%s"', $this->importJob->stage));
|
||||
$handler = null;
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
$handler = app(NewBunqJobHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'choose-accounts':
|
||||
/** @var ChooseAccountsHandler $handler */
|
||||
$handler = app(ChooseAccountsHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(sprintf('Firefly III cannot create a configuration handler for stage "%s"', $this->importJob->stage));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $handler;
|
||||
}
|
||||
}
|
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FakeJobConfiguration.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class FakeJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FakeJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
* configuration array of job must have two values:
|
||||
* 'artist' must be 'david bowie', case insensitive
|
||||
* 'song' must be 'golden years', case insensitive.
|
||||
* if stage is not "new", then album must be 'station to station'
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
$config = $this->importJob->configuration;
|
||||
if ('new' === $this->importJob->stage) {
|
||||
return
|
||||
isset($config['artist'], $config['song'], $config['apply-rules'])
|
||||
&& 'david bowie' === strtolower($config['artist'])
|
||||
&& 'golden years' === strtolower($config['song']);
|
||||
}
|
||||
|
||||
return isset($config['album']) && 'station to station' === strtolower($config['album']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
$artist = strtolower($data['artist'] ?? '');
|
||||
$song = strtolower($data['song'] ?? '');
|
||||
$album = strtolower($data['album'] ?? '');
|
||||
$applyRules = isset($data['apply_rules']) ? 1 === (int) $data['apply_rules'] : null;
|
||||
$configuration = $this->importJob->configuration;
|
||||
if ('david bowie' === $artist) {
|
||||
// store artist
|
||||
$configuration['artist'] = $artist;
|
||||
}
|
||||
|
||||
if ('golden years' === $song) {
|
||||
// store song
|
||||
$configuration['song'] = $song;
|
||||
}
|
||||
|
||||
if ('station to station' === $album) {
|
||||
// store album
|
||||
$configuration['album'] = $album;
|
||||
}
|
||||
if (null !== $applyRules) {
|
||||
$configuration['apply-rules'] = $applyRules;
|
||||
}
|
||||
|
||||
$this->repository->setConfiguration($this->importJob, $configuration);
|
||||
$messages = new MessageBag();
|
||||
|
||||
if (3 !== count($configuration)) {
|
||||
$messages->add('some_key', 'Ignore this error: ' . count($configuration));
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
return [
|
||||
'rulesOptions' => [
|
||||
1 => (string) trans('firefly.yes'),
|
||||
0 => (string) trans('firefly.no'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
// first configure artist:
|
||||
$config = $this->importJob->configuration;
|
||||
$artist = $config['artist'] ?? '';
|
||||
$song = $config['song'] ?? '';
|
||||
$album = $config['album'] ?? '';
|
||||
$applyRules = $config['apply-rules'] ?? null;
|
||||
if (null === $applyRules) {
|
||||
return 'import.fake.apply-rules';
|
||||
}
|
||||
if ('david bowie' !== strtolower($artist)) {
|
||||
return 'import.fake.enter-artist';
|
||||
}
|
||||
if ('golden years' !== strtolower($song)) {
|
||||
return 'import.fake.enter-song';
|
||||
}
|
||||
if ('new' !== $this->importJob->stage && 'station to station' !== strtolower($album)) {
|
||||
return 'import.fake.enter-album';
|
||||
}
|
||||
|
||||
return 'impossible-view'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Set import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
}
|
@@ -1,161 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FileJobConfiguration.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\FileConfigurationInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class FileJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FileJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
return 'ready_to_run' === $this->importJob->stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
$configurator = $this->getConfigurationObject();
|
||||
$configurator->setImportJob($this->importJob);
|
||||
|
||||
return $configurator->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
$configurator = $this->getConfigurationObject();
|
||||
$configurator->setImportJob($this->importJob);
|
||||
|
||||
return $configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
return 'import.file.new';
|
||||
case 'configure-upload':
|
||||
return 'import.file.configure-upload';
|
||||
case 'roles':
|
||||
return 'import.file.roles';
|
||||
case 'map':
|
||||
return 'import.file.map';
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
sprintf('FileJobConfiguration::getNextView() cannot handle stage "%s"', $this->importJob->stage)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration handler for this specific stage.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return FileConfigurationInterface
|
||||
*/
|
||||
private function getConfigurationObject(): FileConfigurationInterface
|
||||
{
|
||||
$class = 'DoNotExist';
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new': // has nothing, no file upload or anything.
|
||||
$class = NewFileJobHandler::class;
|
||||
break;
|
||||
case 'configure-upload':
|
||||
$class = ConfigureUploadHandler::class;
|
||||
break;
|
||||
case 'roles':
|
||||
$class = ConfigureRolesHandler::class;
|
||||
break;
|
||||
case 'map':
|
||||
$class = ConfigureMappingHandler::class;
|
||||
break;
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return app($class);
|
||||
}
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FinTSConfigurationSteps.php
|
||||
* Copyright (c) 2019 https://github.com/bnw
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class FinTSConfigurationSteps
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
abstract class FinTSConfigurationSteps
|
||||
{
|
||||
public const NEW = 'new';
|
||||
public const CHOOSE_ACCOUNT = 'choose_account';
|
||||
public const GO_FOR_IMPORT = 'go-for-import';
|
||||
}
|
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FinTSJobConfiguration.php
|
||||
* Copyright (c) 2019 https://github.com/bnw
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Support\Import\JobConfiguration\FinTS\ChooseAccountHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\FinTS\FinTSConfigurationInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\FinTS\NewFinTSJobHandler;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class FinTSJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FinTSJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var ImportJob */
|
||||
private $importJob;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
return $this->importJob->stage === FinTSConfigurationSteps::GO_FOR_IMPORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
return $this->getConfigurationObject()->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
return $this->getConfigurationObject()->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
switch ($this->importJob->stage) {
|
||||
case FinTSConfigurationSteps::NEW:
|
||||
case FinTSConfigurationSteps::CHOOSE_ACCOUNT:
|
||||
return 'import.fints.' . $this->importJob->stage;
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
sprintf('FinTSJobConfiguration::getNextView() cannot handle stage "%s"', $this->importJob->stage)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration handler for this specific stage.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return FinTSConfigurationInterface
|
||||
*/
|
||||
private function getConfigurationObject(): FinTSConfigurationInterface
|
||||
{
|
||||
$class = 'DoNotExist';
|
||||
switch ($this->importJob->stage) {
|
||||
case FinTSConfigurationSteps::NEW:
|
||||
$class = NewFinTSJobHandler::class;
|
||||
break;
|
||||
case FinTSConfigurationSteps::CHOOSE_ACCOUNT:
|
||||
$class = ChooseAccountHandler::class;
|
||||
break;
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$configurator = app($class);
|
||||
$configurator->setImportJob($this->importJob);
|
||||
|
||||
return $configurator;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* JobConfigurationInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Interface JobConfigurationInterface.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface JobConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool;
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag;
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array;
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string;
|
||||
|
||||
/**
|
||||
* Set import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void;
|
||||
}
|
@@ -1,156 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreJobConfiguration.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewSpectreJobHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\SpectreJobConfigurationInterface;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SpectreJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class SpectreJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var SpectreJobConfigurationInterface The job handler. */
|
||||
private $handler;
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
return $this->handler->configurationComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
return $this->handler->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
return $this->handler->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
return $this->handler->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
$this->handler = $this->getHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct handler.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return SpectreJobConfigurationInterface
|
||||
*/
|
||||
private function getHandler(): SpectreJobConfigurationInterface
|
||||
{
|
||||
Log::debug(sprintf('Now in SpectreJobConfiguration::getHandler() with stage "%s"', $this->importJob->stage));
|
||||
$handler = null;
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
/** @var NewSpectreJobHandler $handler */
|
||||
$handler = app(NewSpectreJobHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'do-authenticate':
|
||||
/** @var DoAuthenticateHandler $handler */
|
||||
$handler = app(DoAuthenticateHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'choose-login':
|
||||
/** @var ChooseLoginHandler $handler */
|
||||
$handler = app(ChooseLoginHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'authenticated':
|
||||
/** @var AuthenticatedHandler $handler */
|
||||
$handler = app(AuthenticatedHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'choose-accounts':
|
||||
/** @var ChooseAccountsHandler $handler */
|
||||
$handler = app(ChooseAccountsHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(sprintf('Firefly III cannot create a configuration handler for stage "%s"', $this->importJob->stage));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $handler;
|
||||
}
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* YnabJobConfiguration.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Ynab\NewYnabJobHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectAccountsHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectBudgetHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Ynab\YnabJobConfigurationInterface;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class YnabJobConfiguration
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class YnabJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
/** @var YnabJobConfigurationInterface The job handler. */
|
||||
private $handler;
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
return $this->handler->configurationComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function configureJob(array $data): MessageBag
|
||||
{
|
||||
return $this->handler->configureJob($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
{
|
||||
return $this->handler->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
return $this->handler->getNextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
$this->handler = $this->getHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct handler.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return YnabJobConfigurationInterface
|
||||
*/
|
||||
private function getHandler(): YnabJobConfigurationInterface
|
||||
{
|
||||
Log::debug(sprintf('Now in YnabJobConfiguration::getHandler() with stage "%s"', $this->importJob->stage));
|
||||
$handler = null;
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
/** @var NewYnabJobHandler $handler */
|
||||
$handler = app(NewYnabJobHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'select_budgets':
|
||||
/** @var SelectBudgetHandler $handler */
|
||||
$handler = app(SelectBudgetHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
case 'select_accounts':
|
||||
$handler = app(SelectAccountsHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(sprintf('Firefly III cannot create a YNAB configuration handler for stage "%s"', $this->importJob->stage));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $handler;
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AssetAccountIbans.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class AssetAccounts.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AssetAccountIbans implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of asset accounts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$set = $accountRepository->getAccountsByType(
|
||||
[AccountType::DEFAULT, AccountType::ASSET,
|
||||
AccountType::LOAN, AccountType::DEBT,
|
||||
AccountType::CREDITCARD, AccountType::MORTGAGE,
|
||||
]
|
||||
);
|
||||
$topList = [];
|
||||
$list = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($set as $account) {
|
||||
$iban = $account->iban ?? '';
|
||||
$accountId = (int) $account->id;
|
||||
if ('' !== $iban) {
|
||||
$name = $account->iban . ' (' . $account->name . ')';
|
||||
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';
|
||||
}
|
||||
|
||||
$topList[$accountId] = $name;
|
||||
}
|
||||
if ('' === $iban) {
|
||||
$name = $account->name;
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';
|
||||
}
|
||||
$list[$accountId] = $name;
|
||||
}
|
||||
}
|
||||
/** @noinspection AdditionOperationOnArraysInspection */
|
||||
$list = $topList + $list;
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AssetAccounts.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class AssetAccounts.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AssetAccounts implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of asset accounts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$set = $accountRepository->getAccountsByType(
|
||||
[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]
|
||||
);
|
||||
$list = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($set as $account) {
|
||||
$accountId = (int) $account->id;
|
||||
$name = $account->name;
|
||||
$iban = $account->iban ?? '';
|
||||
if ('' !== $iban) {
|
||||
$name .= ' (' . $iban . ')';
|
||||
}
|
||||
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = trans('import.import_liability_select') . ': ' . $name;
|
||||
}
|
||||
|
||||
$list[$accountId] = $name;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Bills.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Bills.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Bills implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of bills.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$result = $repository->getBills();
|
||||
$list = [];
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($result as $bill) {
|
||||
$billId = (int) $bill->id;
|
||||
$list[$billId] = $bill->name;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Budgets.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Budgets.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Budgets implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of budgets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$result = $repository->getActiveBudgets();
|
||||
$list = [];
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($result as $budget) {
|
||||
$budgetId = (int) $budget->id;
|
||||
$list[$budgetId] = $budget->name;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Categories.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Categories.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Categories implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$result = $repository->getCategories();
|
||||
$list = [];
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($result as $category) {
|
||||
$categoryId = (int) $category->id;
|
||||
$list[$categoryId] = $category->name;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* MapperInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
/**
|
||||
* Interface MapperInterface.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of objects.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array;
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OpposingAccountIbans.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class OpposingAccounts.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class OpposingAccountIbans implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of opposing accounts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$set = $accountRepository->getAccountsByType(
|
||||
[
|
||||
AccountType::DEFAULT, AccountType::ASSET,
|
||||
AccountType::EXPENSE, AccountType::BENEFICIARY,
|
||||
AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,
|
||||
AccountType::CREDITCARD, AccountType::MORTGAGE,
|
||||
]
|
||||
);
|
||||
$topList = [];
|
||||
$list = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($set as $account) {
|
||||
$iban = $account->iban ?? '';
|
||||
$accountId = (int) $account->id;
|
||||
if ('' !== $iban) {
|
||||
$name = $account->iban . ' (' . $account->name . ')';
|
||||
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';
|
||||
}
|
||||
|
||||
$topList[$accountId] = $name;
|
||||
|
||||
}
|
||||
if ('' === $iban) {
|
||||
$name = $account->name;
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';
|
||||
}
|
||||
$list[$accountId] = $name;
|
||||
}
|
||||
}
|
||||
/** @noinspection AdditionOperationOnArraysInspection */
|
||||
$list = $topList + $list;
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OpposingAccounts.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class OpposingAccounts.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
class OpposingAccounts implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of opposing accounts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$set = $accountRepository->getAccountsByType(
|
||||
[
|
||||
AccountType::DEFAULT, AccountType::ASSET,
|
||||
AccountType::EXPENSE, AccountType::BENEFICIARY,
|
||||
AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,
|
||||
AccountType::CREDITCARD, AccountType::MORTGAGE,
|
||||
]
|
||||
);
|
||||
$list = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($set as $account) {
|
||||
$accountId = (int) $account->id;
|
||||
$name = $account->name;
|
||||
$iban = $account->iban ?? '';
|
||||
if ('' !== $iban) {
|
||||
$name .= ' (' . $iban . ')';
|
||||
}
|
||||
// is a liability?
|
||||
if (in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {
|
||||
$name = trans('import.import_liability_select') . ': ' . $name;
|
||||
}
|
||||
$list[$accountId] = $name;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Tags.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Tags.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Tags implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of tags.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$result = $repository->get();
|
||||
$list = [];
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($result as $tag) {
|
||||
$tagId = (int) $tag->id;
|
||||
$list[$tagId] = $tag->tag;
|
||||
}
|
||||
asort($list);
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TransactionCurrencies.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Mapper;
|
||||
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class TransactionCurrencies.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class TransactionCurrencies implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of currencies.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = $repository->get();
|
||||
$list = [];
|
||||
foreach ($currencies as $currency) {
|
||||
$currencyId = (int) $currency->id;
|
||||
$list[$currencyId] = $currency->name . ' (' . $currency->code . ')';
|
||||
}
|
||||
asort($list);
|
||||
|
||||
$list = [0 => (string) trans('import.map_do_not_map')] + $list;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PreProcessorInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Interface PreProcessorInterface.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface PreProcessorInterface
|
||||
{
|
||||
/**
|
||||
* Run preprocessor.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(string $value): array;
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TagsComma.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Class TagsComma.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class TagsComma implements PreProcessorInterface
|
||||
{
|
||||
/**
|
||||
* Explode and filter list of comma separated tags.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(string $value): array
|
||||
{
|
||||
$set = explode(',', $value);
|
||||
$set = array_map('trim', $set);
|
||||
$set = array_filter($set, '\strlen');
|
||||
|
||||
return array_values($set);
|
||||
}
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TagsSpace.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Class TagsSpace.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class TagsSpace implements PreProcessorInterface
|
||||
{
|
||||
/**
|
||||
* Explode and filter list of space separated tags.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(string $value): array
|
||||
{
|
||||
$set = explode(' ', $value);
|
||||
$set = array_map('trim', $set);
|
||||
$set = array_filter($set, '\strlen');
|
||||
|
||||
return array_values($set);
|
||||
}
|
||||
}
|
@@ -1,236 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BunqPrerequisites.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use bunq\Util\BunqEnumApiEnvironmentType;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Bunq\ApiContext;
|
||||
use FireflyIII\Services\IP\IPRetrievalInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* This class contains all the routines necessary to connect to Bunq.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User The current user */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* BunqPrerequisites constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.bunq.prerequisites';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
Log::debug('Now in BunqPrerequisites::getViewParameters()');
|
||||
$key = '';
|
||||
$externalIP = '';
|
||||
if ($this->hasApiKey()) {
|
||||
$key = app('preferences')->getForUser($this->user, 'bunq_api_key', null)->data;
|
||||
}
|
||||
if ($this->hasExternalIP()) {
|
||||
$externalIP = app('preferences')->getForUser($this->user, 'bunq_external_ip', null)->data;
|
||||
}
|
||||
if (!$this->hasExternalIP()) {
|
||||
/** @var IPRetrievalInterface $service */
|
||||
$service = app(IPRetrievalInterface::class);
|
||||
$externalIP = (string) $service->getIP();
|
||||
}
|
||||
|
||||
return ['api_key' => $key, 'external_ip' => $externalIP];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return $this->hasApiKey() && $this->hasExternalIP() && $this->hasApiContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
$apiKey = $data['api_key'] ?? '';
|
||||
$externalIP = $data['external_ip'] ?? '';
|
||||
Log::debug('Storing bunq API key');
|
||||
app('preferences')->setForUser($this->user, 'bunq_api_key', $apiKey);
|
||||
app('preferences')->setForUser($this->user, 'bunq_external_ip', $externalIP);
|
||||
$environment = $this->getBunqEnvironment();
|
||||
$deviceDescription = 'Firefly III v' . config('firefly.version');
|
||||
$permittedIps = [$externalIP];
|
||||
Log::debug(sprintf('Environment for bunq is %s', $environment->getChoiceString()));
|
||||
|
||||
try {
|
||||
/** @var ApiContext $object */
|
||||
$object = app(ApiContext::class);
|
||||
$apiContext = $object->create($environment, $apiKey, $deviceDescription, $permittedIps);
|
||||
} catch (FireflyException $e) {
|
||||
$messages = new MessageBag();
|
||||
$messages->add('bunq_error', $e->getMessage());
|
||||
|
||||
return $messages;
|
||||
}
|
||||
// store context in JSON:
|
||||
try {
|
||||
$json = $apiContext->toJson();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
$messages = new MessageBag();
|
||||
$messages->add('bunq_error', $e->getMessage());
|
||||
|
||||
return $messages;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// and store for user:
|
||||
app('preferences')->setForUser($this->user, 'bunq_api_context', $json);
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct bunq environment.
|
||||
*
|
||||
* @return BunqEnumApiEnvironmentType
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getBunqEnvironment(): BunqEnumApiEnvironmentType
|
||||
{
|
||||
$env = config('firefly.bunq_use_sandbox');
|
||||
if (null === $env) {
|
||||
return BunqEnumApiEnvironmentType::PRODUCTION();
|
||||
}
|
||||
if (false === $env) {
|
||||
return BunqEnumApiEnvironmentType::PRODUCTION();
|
||||
}
|
||||
|
||||
return BunqEnumApiEnvironmentType::SANDBOX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have API context.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasApiContext(): bool
|
||||
{
|
||||
$apiContext = app('preferences')->getForUser($this->user, 'bunq_api_context', null);
|
||||
if (null === $apiContext) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $apiContext->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the API key.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasApiKey(): bool
|
||||
{
|
||||
$apiKey = app('preferences')->getForUser($this->user, 'bunq_api_key', null);
|
||||
if (null === $apiKey) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $apiKey->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we have an external IP.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasExternalIP(): bool
|
||||
{
|
||||
$externalIP = app('preferences')->getForUser($this->user, 'bunq_external_ip', null);
|
||||
if (null === $externalIP) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $externalIP->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,146 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FakePrerequisites.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
use function request;
|
||||
|
||||
/**
|
||||
* This class contains all the routines necessary for the fake import provider.
|
||||
*
|
||||
* Class FakePrerequisites
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FakePrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User The current user */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* FakePrerequisites constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.fake.prerequisites';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
$apiKey = '';
|
||||
if ($this->hasApiKey()) {
|
||||
$apiKey = app('preferences')->getForUser($this->user, 'fake_api_key', null)->data;
|
||||
}
|
||||
$oldKey = (string) request()->old('api_key');
|
||||
if ('' !== $oldKey) {
|
||||
$apiKey = request()->old('api_key'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return ['api_key' => $apiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return $this->hasApiKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store fake prerequisites.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
$apiKey = $data['api_key'] ?? '';
|
||||
$messageBag = new MessageBag();
|
||||
if (32 !== strlen($apiKey)) {
|
||||
$messageBag->add('api_key', 'API key must be 32 chars.');
|
||||
|
||||
return $messageBag;
|
||||
}
|
||||
|
||||
app('preferences')->setForUser($this->user, 'fake_api_key', $apiKey);
|
||||
|
||||
return $messageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have an API key.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasApiKey(): bool
|
||||
{
|
||||
$apiKey = app('preferences')->getForUser($this->user, 'fake_api_key', false);
|
||||
if (null === $apiKey) {
|
||||
return false;
|
||||
}
|
||||
if (null === $apiKey->data) {
|
||||
return false;
|
||||
}
|
||||
if (32 === strlen((string) $apiKey->data)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FilePrerequisites.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class contains all the routines necessary to import from a file. Hint: there are none.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FilePrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* FilePrerequisites constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
return new MessageBag;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PrerequisitesInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Interface PrerequisitesInterface
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface PrerequisitesInterface
|
||||
{
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string;
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array;
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool;
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void;
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag;
|
||||
}
|
@@ -1,206 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectrePrerequisites.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* This class contains all the routines necessary to connect to Spectre.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class SpectrePrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User The current user */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* SpectrePrerequisites constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.spectre.prerequisites';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
/** @var Preference $appIdPreference */
|
||||
$appIdPreference = app('preferences')->getForUser($this->user, 'spectre_app_id', null);
|
||||
$appId = null === $appIdPreference ? '' : $appIdPreference->data;
|
||||
/** @var Preference $secretPreference */
|
||||
$secretPreference = app('preferences')->getForUser($this->user, 'spectre_secret', null);
|
||||
$secret = null === $secretPreference ? '' : $secretPreference->data;
|
||||
$publicKey = $this->getPublicKey();
|
||||
|
||||
return [
|
||||
'app_id' => $appId,
|
||||
'secret' => $secret,
|
||||
'public_key' => $publicKey,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return $this->hasAppId() && $this->hasSecret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
Log::debug('Storing Spectre API keys..');
|
||||
app('preferences')->setForUser($this->user, 'spectre_app_id', $data['app_id'] ?? null);
|
||||
app('preferences')->setForUser($this->user, 'spectre_secret', $data['secret'] ?? null);
|
||||
Log::debug('Done!');
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates a new public/private keypair for the user. This isn't really secure, since the key is generated on the fly with
|
||||
* no regards for HSM's, smart cards or other things. It would require some low level programming to get this right. But the private key
|
||||
* is stored encrypted in the database so it's something.
|
||||
*/
|
||||
private function createKeyPair(): void
|
||||
{
|
||||
Log::debug('Generate new Spectre key pair for user.');
|
||||
$keyConfig = [
|
||||
'digest_alg' => 'sha512',
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
];
|
||||
// Create the private and public key
|
||||
$res = openssl_pkey_new($keyConfig);
|
||||
|
||||
// Extract the private key from $res to $privKey
|
||||
$privKey = '';
|
||||
openssl_pkey_export($res, $privKey);
|
||||
|
||||
// Extract the public key from $res to $pubKey
|
||||
$pubKey = openssl_pkey_get_details($res);
|
||||
|
||||
app('preferences')->setForUser($this->user, 'spectre_private_key', $privKey);
|
||||
app('preferences')->setForUser($this->user, 'spectre_public_key', $pubKey['key']);
|
||||
Log::debug('Created key pair');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a public key from the users preferences.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getPublicKey(): string
|
||||
{
|
||||
Log::debug('get public key');
|
||||
$preference = app('preferences')->getForUser($this->user, 'spectre_public_key', null);
|
||||
if (null === $preference) {
|
||||
Log::debug('public key is null');
|
||||
// create key pair
|
||||
$this->createKeyPair();
|
||||
}
|
||||
$preference = app('preferences')->getForUser($this->user, 'spectre_public_key', null);
|
||||
Log::debug('Return public key for user');
|
||||
|
||||
return $preference->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the App ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasAppId(): bool
|
||||
{
|
||||
$appId = app('preferences')->getForUser($this->user, 'spectre_app_id', null);
|
||||
if (null === $appId) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $appId->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the secret.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasSecret(): bool
|
||||
{
|
||||
$secret = app('preferences')->getForUser($this->user, 'spectre_secret', null);
|
||||
if (null === $secret) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $secret->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* YnabPrerequisites.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class YnabPrerequisites
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class YnabPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User The current user */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* YnabPrerequisites constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.ynab.prerequisites';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
Log::debug('Now in YnabPrerequisites::getViewParameters()');
|
||||
$clientId = '';
|
||||
$clientSecret = '';
|
||||
if ($this->hasClientId()) {
|
||||
$clientId = app('preferences')->getForUser($this->user, 'ynab_client_id', null)->data;
|
||||
}
|
||||
if ($this->hasClientSecret()) {
|
||||
$clientSecret = app('preferences')->getForUser($this->user, 'ynab_client_secret', null)->data;
|
||||
}
|
||||
|
||||
$callBackUri = route('import.callback.ynab');
|
||||
$isHttps = 0 === strpos($callBackUri, 'https://');
|
||||
|
||||
return ['client_id' => $clientId, 'client_secret' => $clientSecret, 'callback_uri' => $callBackUri, 'is_https' => $isHttps];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate if all prerequisites have been met.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
return $this->hasClientId() && $this->hasClientSecret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
$clientId = $data['client_id'] ?? '';
|
||||
$clientSecret = $data['client_secret'] ?? '';
|
||||
Log::debug('Storing YNAB client data');
|
||||
app('preferences')->setForUser($this->user, 'ynab_client_id', $clientId);
|
||||
app('preferences')->setForUser($this->user, 'ynab_client_secret', $clientSecret);
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the client ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasClientId(): bool
|
||||
{
|
||||
$clientId = app('preferences')->getForUser($this->user, 'ynab_client_id', null);
|
||||
if (null === $clientId) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $clientId->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the client secret
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasClientSecret(): bool
|
||||
{
|
||||
$clientSecret = app('preferences')->getForUser($this->user, 'ynab_client_secret', null);
|
||||
if (null === $clientSecret) {
|
||||
return false;
|
||||
}
|
||||
if ('' === (string) $clientSecret->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BunqRoutine.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
|
||||
use FireflyIII\Support\Import\Routine\Bunq\StageNewHandler;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class BunqRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BunqRoutine implements RoutineInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::info(sprintf('Now in BunqRoutine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage));
|
||||
$valid = ['ready_to_run']; // should be only ready_to_run
|
||||
if (in_array($this->importJob->status, $valid, true)) {
|
||||
switch ($this->importJob->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('BunqRoutine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore
|
||||
case 'new':
|
||||
// list all of the users accounts.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageNewHandler $handler */
|
||||
$handler = app(StageNewHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
// make user choose accounts to import from.
|
||||
$this->repository->setStage($this->importJob, 'choose-accounts');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
case 'go-for-import':
|
||||
// list all of the users accounts.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
|
||||
/** @var StageImportDataHandler $handler */
|
||||
$handler = app(StageImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$transactions = $handler->getTransactions();
|
||||
// could be that more transactions will arrive in a second run.
|
||||
if (true === $handler->isStillRunning()) {
|
||||
Log::debug('Handler indicates that it is still working.');
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
$this->repository->setStage($this->importJob, 'go-for-import');
|
||||
}
|
||||
$this->repository->appendTransactions($this->importJob, $transactions);
|
||||
if (false === $handler->isStillRunning()) {
|
||||
Log::info('Handler indicates that its done!');
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new FireflyException(sprintf('bunq import routine cannot handle status "%s"', $this->importJob->status)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FakeRoutine.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageAhoyHandler;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageFinalHandler;
|
||||
use FireflyIII\Support\Import\Routine\Fake\StageNewHandler;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FakeRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FakeRoutine implements RoutineInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Fake import routine has three stages:
|
||||
*
|
||||
* "new": will quietly log gibberish for 15 seconds, then switch to stage "ahoy".
|
||||
* will also set status to "ready_to_run" so it will arrive here again.
|
||||
* "ahoy": will log some nonsense and then drop job into status:"need_job_config" to force it back to the job config routine.
|
||||
* "final": will do some logging, sleep for 10 seconds and then finish. Generates 5 random transactions.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in run() for fake routine with status: %s', $this->importJob->status));
|
||||
if ('ready_to_run' !== $this->importJob->status) {
|
||||
throw new FireflyException(sprintf('Fake job should have status "ready_to_run", not "%s"', $this->importJob->status)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
switch ($this->importJob->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore
|
||||
case 'new':
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageNewHandler $handler */
|
||||
$handler = app(StageNewHandler::class);
|
||||
$handler->run();
|
||||
$this->repository->setStage($this->importJob, 'ahoy');
|
||||
// set job finished this step:
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
|
||||
return;
|
||||
case 'ahoy':
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageAhoyHandler $handler */
|
||||
$handler = app(StageAhoyHandler::class);
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
break;
|
||||
case 'final':
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageFinalHandler $handler */
|
||||
$handler = app(StageFinalHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$transactions = $handler->getTransactions();
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
$this->repository->setTransactions($this->importJob, $transactions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FileRoutine.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\File\FileProcessorInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FileRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FileRoutine implements RoutineInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in run() for file routine with status: %s', $this->importJob->status));
|
||||
if ('ready_to_run' === $this->importJob->status) {
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
// get processor, depending on file type
|
||||
// is just CSV for now.
|
||||
$processor = $this->getProcessor();
|
||||
$processor->setImportJob($this->importJob);
|
||||
$transactions = $processor->run();
|
||||
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
$this->repository->setTransactions($this->importJob, $transactions);
|
||||
|
||||
return;
|
||||
}
|
||||
throw new FireflyException(sprintf('Import routine cannot handle status "%s"', $this->importJob->status)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the appropriate file routine handler for
|
||||
* the file type of the job.
|
||||
*
|
||||
* @return FileProcessorInterface
|
||||
*/
|
||||
private function getProcessor(): FileProcessorInterface
|
||||
{
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$type = $config['file-type'] ?? 'csv';
|
||||
$class = config(sprintf('import.options.file.processors.%s', $type));
|
||||
|
||||
return app($class);
|
||||
}
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FinTSRoutine.php
|
||||
* Copyright (c) 2019 https://github.com/bnw
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class FinTSRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FinTSRoutine implements RoutineInterface
|
||||
{
|
||||
/** @var ImportJob */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in FinTSRoutine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage));
|
||||
$valid = ['ready_to_run']; // should be only ready_to_run
|
||||
if (in_array($this->importJob->status, $valid, true)) {
|
||||
switch ($this->importJob->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('FinTSRoutine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore
|
||||
case FinTSConfigurationSteps::GO_FOR_IMPORT:
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageImportDataHandler $handler */
|
||||
$handler = app(StageImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$transactions = $handler->getTransactions();
|
||||
|
||||
$this->repository->setTransactions($this->importJob, $transactions);
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* RoutineInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
|
||||
/**
|
||||
* Interface RoutineInterface
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface RoutineInterface
|
||||
{
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run(): void;
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void;
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreRoutine.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SpectreRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class SpectreRoutine implements RoutineInterface
|
||||
{
|
||||
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in SpectreRoutine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage));
|
||||
$valid = ['ready_to_run']; // should be only ready_to_run
|
||||
if (in_array($this->importJob->status, $valid, true)) {
|
||||
switch ($this->importJob->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore
|
||||
case 'new':
|
||||
// list all of the users logins.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageNewHandler $handler */
|
||||
$handler = app(StageNewHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
// if count logins is zero, go to authenticate stage
|
||||
if (0 === $handler->getCountLogins()) {
|
||||
$this->repository->setStage($this->importJob, 'do-authenticate');
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
|
||||
return;
|
||||
}
|
||||
// or return to config to select login.
|
||||
$this->repository->setStage($this->importJob, 'choose-login');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
break;
|
||||
case 'do-authenticate':
|
||||
// set job to require config.
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
case 'authenticated':
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
// get accounts from login, store in job.
|
||||
/** @var StageAuthenticatedHandler $handler */
|
||||
$handler = app(StageAuthenticatedHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
// return to config to select account(s).
|
||||
$this->repository->setStage($this->importJob, 'choose-accounts');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
break;
|
||||
case 'go-for-import':
|
||||
// user has chosen account mapping. Should now be ready to import data.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
$this->repository->setStage($this->importJob, 'do_import');
|
||||
/** @var StageImportDataHandler $handler */
|
||||
$handler = app(StageImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
}
|
@@ -1,146 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* YnabRoutine.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Routine;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Ynab\GetAccountsHandler;
|
||||
use FireflyIII\Support\Import\Routine\Ynab\ImportDataHandler;
|
||||
use FireflyIII\Support\Import\Routine\Ynab\StageGetAccessHandler;
|
||||
use FireflyIII\Support\Import\Routine\Ynab\StageGetBudgetsHandler;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class YnabRoutine
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class YnabRoutine implements RoutineInterface
|
||||
{
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* At the end of each run(), the import routine must set the job to the expected status.
|
||||
*
|
||||
* The final status of the routine must be "provider_finished".
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in YNAB routine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage));
|
||||
$valid = ['ready_to_run']; // should be only ready_to_run
|
||||
if (in_array($this->importJob->status, $valid, true)) {
|
||||
|
||||
// get access token from YNAB
|
||||
if ('get_access_token' === $this->importJob->stage) {
|
||||
// list all of the users accounts.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageGetAccessHandler $handler */
|
||||
$handler = app(StageGetAccessHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
// back to correct stage:
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
$this->repository->setStage($this->importJob, 'get_budgets');
|
||||
|
||||
return;
|
||||
}
|
||||
if ('get_budgets' === $this->importJob->stage) {
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageGetBudgetsHandler $handler */
|
||||
$handler = app(StageGetBudgetsHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
// count budgets in job, to determine next step.
|
||||
$configuration = $this->repository->getConfiguration($this->importJob);
|
||||
$budgets = $configuration['budgets'] ?? [];
|
||||
|
||||
// if more than 1 budget, select budget first.
|
||||
if (count($budgets) > 1) {
|
||||
$this->repository->setStage($this->importJob, 'select_budgets');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (1 === count($budgets)) {
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
$this->repository->setStage($this->importJob, 'get_accounts');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if ('get_accounts' === $this->importJob->stage) {
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
|
||||
/** @var GetAccountsHandler $handler */
|
||||
$handler = app(GetAccountsHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
$this->repository->setStage($this->importJob, 'select_accounts');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
}
|
||||
if ('go-for-import' === $this->importJob->stage) {
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
$this->repository->setStage($this->importJob, 'do_import');
|
||||
/** @var ImportDataHandler $handler */
|
||||
$handler = app(ImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('YNAB import routine cannot handle stage "%s"', $this->importJob->stage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the import job.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
}
|
@@ -1,243 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AbnAmroDescription.php
|
||||
* Copyright (c) 2019 Robert Horlings
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class AbnAmroDescription.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Parses the description from txt files for ABN AMRO bank accounts.
|
||||
*
|
||||
* Based on the logic as described in the following Gist:
|
||||
* https://gist.github.com/vDorst/68d555a6a90f62fec004
|
||||
*/
|
||||
class AbnAmroDescription implements SpecificInterface
|
||||
{
|
||||
/** @var array The current row. */
|
||||
public $row;
|
||||
|
||||
/**
|
||||
* Description of this specific fix.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_abn_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of specific fix.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_abn_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the fix.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
$this->row = array_values($row);
|
||||
|
||||
if (!isset($row[7])) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
// Try to parse the description in known formats.
|
||||
$parsed = $this->parseSepaDescription() || $this->parseTRTPDescription() || $this->parseGEABEADescription() || $this->parseABNAMRODescription();
|
||||
|
||||
// If the description could not be parsed, specify an unknown opposing
|
||||
// account, as an opposing account is required
|
||||
if (!$parsed) {
|
||||
$this->row[8] = (string) trans('firefly.unknown'); // opposing-account-name
|
||||
}
|
||||
|
||||
return $this->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description with costs from ABN AMRO itself.
|
||||
*
|
||||
* @return bool true if the description is GEA/BEA-format, false otherwise
|
||||
*/
|
||||
protected function parseABNAMRODescription(): bool
|
||||
{
|
||||
// See if the current description is formatted in ABN AMRO format
|
||||
if (preg_match('/ABN AMRO.{24} (.*)/', $this->row[7], $matches)) {
|
||||
$this->row[8] = 'ABN AMRO'; // this one is new (opposing account name)
|
||||
$this->row[7] = $matches[1]; // this is the description
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in GEA/BEA format.
|
||||
*
|
||||
* @return bool true if the description is GEA/BEAformat, false otherwise
|
||||
*/
|
||||
protected function parseGEABEADescription(): bool
|
||||
{
|
||||
// See if the current description is formatted in GEA/BEA format
|
||||
if (preg_match('/([BG]EA) +(NR:[a-zA-Z:0-9]+) +([0-9.\/]+) +([^,]*)/', $this->row[7], $matches)) {
|
||||
// description and opposing account will be the same.
|
||||
$this->row[8] = $matches[4]; // 'opposing-account-name'
|
||||
$this->row[7] = $matches[4]; // 'description'
|
||||
|
||||
if ('GEA' === $matches[1]) {
|
||||
$this->row[7] = 'GEA ' . $matches[4]; // 'description'
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in SEPA format.
|
||||
*
|
||||
* @return bool true if the description is SEPA format, false otherwise
|
||||
*
|
||||
*/
|
||||
protected function parseSepaDescription(): bool
|
||||
{
|
||||
// See if the current description is formatted as a SEPA plain description
|
||||
if (preg_match('/^SEPA(.{28})/', $this->row[7], $matches)) {
|
||||
$type = $matches[1];
|
||||
$reference = '';
|
||||
$name = '';
|
||||
$newDescription = '';
|
||||
|
||||
// SEPA plain descriptions contain several key-value pairs, split by a colon
|
||||
preg_match_all('/([A-Za-z]+(?=:\s)):\s([A-Za-z 0-9._#-]+(?=\s|$))/', $this->row[7], $matches, PREG_SET_ORDER);
|
||||
|
||||
if (is_array($matches)) {
|
||||
foreach ($matches as $match) {
|
||||
$key = $match[1];
|
||||
$value = trim($match[2]);
|
||||
switch (strtoupper($key)) {
|
||||
case 'OMSCHRIJVING':
|
||||
$newDescription = $value;
|
||||
break;
|
||||
case 'NAAM':
|
||||
$this->row[8] = $value;
|
||||
$name = $value;
|
||||
break;
|
||||
case 'KENMERK':
|
||||
$reference = $value;
|
||||
break;
|
||||
case 'IBAN':
|
||||
$this->row[9] = $value;
|
||||
break;
|
||||
default: // @codeCoverageIgnore
|
||||
// Ignore the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set a new description for the current transaction. If none was given
|
||||
// set the description to type, name and reference
|
||||
$this->row[7] = $newDescription;
|
||||
if ('' === $newDescription) {
|
||||
$this->row[7] = sprintf('%s - %s (%s)', $type, $name, $reference);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in TRTP format.
|
||||
*
|
||||
* @return bool true if the description is TRTP format, false otherwise
|
||||
*
|
||||
*/
|
||||
protected function parseTRTPDescription(): bool
|
||||
{
|
||||
// See if the current description is formatted in TRTP format
|
||||
if (preg_match_all('!\/([A-Z]{3,4})\/([^/]*)!', $this->row[7], $matches, PREG_SET_ORDER)) {
|
||||
$type = '';
|
||||
$name = '';
|
||||
$reference = '';
|
||||
$newDescription = '';
|
||||
|
||||
// Search for properties specified in the TRTP format. If no description
|
||||
// is provided, use the type, name and reference as new description
|
||||
if (is_array($matches)) {
|
||||
foreach ($matches as $match) {
|
||||
$key = $match[1];
|
||||
$value = trim($match[2]);
|
||||
|
||||
switch (strtoupper($key)) {
|
||||
case 'NAME':
|
||||
$this->row[8] = $value;
|
||||
break;
|
||||
case 'REMI':
|
||||
$newDescription = $value;
|
||||
break;
|
||||
case 'IBAN':
|
||||
$this->row[9] = $value;
|
||||
break;
|
||||
case 'EREF':
|
||||
$reference = $value;
|
||||
break;
|
||||
case 'TRTP':
|
||||
$type = $value;
|
||||
break;
|
||||
default: // @codeCoverageIgnore
|
||||
// Ignore the rest
|
||||
}
|
||||
}
|
||||
|
||||
// Set a new description for the current transaction. If none was given
|
||||
// set the description to type, name and reference
|
||||
$this->row[7] = $newDescription;
|
||||
if ('' === $newDescription) {
|
||||
$this->row[7] = sprintf('%s - %s (%s)', $type, $name, $reference);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Belfius.php
|
||||
* Copyright (c) 2019 Sander Kleykens <sander@kleykens.com>
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class Belfius.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Fixes Belfius CSV files to:
|
||||
* - Correct descriptions for recurring transactions so doubles can be detected when the equivalent incoming
|
||||
* transaction is imported.
|
||||
*
|
||||
*/
|
||||
class Belfius implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Description of this specific fix.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_belfius_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of specific fix.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_belfius_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the description for outgoing recurring transactions so doubles can be detected when the equivalent incoming
|
||||
* transaction is imported for another bank account.
|
||||
*
|
||||
* @return array the row containing the new description
|
||||
*/
|
||||
protected static function processRecurringTransactionDescription(array $row): array
|
||||
{
|
||||
if (!isset($row[5]) || !isset($row[14])) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
$opposingAccountName = $row[5];
|
||||
$description = $row[14];
|
||||
|
||||
preg_match('/DOORLOPENDE OPDRACHT.*\s+' . preg_quote($opposingAccountName, '/') . '\s+(.+)\s+REF.\s*:/', $description, $matches);
|
||||
|
||||
if (isset($matches[1])) {
|
||||
$row[14] = $matches[1];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the fix.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
return Belfius::processRecurringTransactionDescription($row);
|
||||
}
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IngBelgium.php
|
||||
* Copyright (c) 2019 Sander Kleykens <sander@kleykens.com>
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class IngBelgium.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Parses the description and opposing account information (IBAN and name) from CSV files for ING Belgium bank accounts.
|
||||
*
|
||||
*/
|
||||
class IngBelgium implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Description of the current specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_ingbelgium_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the current specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_ingbelgium_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description from the transaction details and makes sure structured descriptions are in the
|
||||
* "+++090/9337/55493+++" format.
|
||||
*
|
||||
* @return string the description
|
||||
*/
|
||||
protected static function description(string $transactionDetails): string
|
||||
{
|
||||
$description = IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/Mededeling:\s*(.+)$/');
|
||||
|
||||
return IngBelgium::convertStructuredDescriptionToProperFormat($description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opposing account's IBAN from the transaction details.
|
||||
*
|
||||
* @return string the opposing account's IBAN
|
||||
*/
|
||||
protected static function opposingAccountIban(string $transactionDetails): string
|
||||
{
|
||||
return IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/IBAN:\s*(.+?)(?=\s+)/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opposing account name from the transaction details.
|
||||
*
|
||||
* @return string the opposing account name
|
||||
*/
|
||||
protected static function opposingAccountName(string $transactionDetails): string
|
||||
{
|
||||
return IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/Van:\s*(.+?)(?=\s{2,})/');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description and opposing account information (IBAN and name) from the transaction details and adds
|
||||
* them to the row of data.
|
||||
*
|
||||
* @return array the row containing the description and opposing account's IBAN
|
||||
*/
|
||||
protected static function processTransactionDetails(array $row): array
|
||||
{
|
||||
if (isset($row[9])) {
|
||||
$transactionDetails = $row[9];
|
||||
$row[11] = IngBelgium::opposingAccountName($transactionDetails);
|
||||
$row[12] = IngBelgium::opposingAccountIban($transactionDetails);
|
||||
$row[13] = IngBelgium::description($transactionDetails);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
private static function convertStructuredDescriptionToProperFormat(string $description): string
|
||||
{
|
||||
preg_match('/^\*\*\*(\d{3}\/\d{4}\/\d{5})\*\*\*$/', $description, $matches);
|
||||
if (isset($matches[1])) {
|
||||
return '+++' . $matches[1] . '+++';
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
private static function parseInformationFromTransactionDetails(string $transactionDetails, string $regex): string
|
||||
{
|
||||
if (isset($transactionDetails)) {
|
||||
preg_match($regex, $transactionDetails, $matches);
|
||||
if (isset($matches[1])) {
|
||||
return trim($matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the specific code.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
return IngBelgium::processTransactionDetails($row);
|
||||
}
|
||||
}
|
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IngDescription.php
|
||||
* Copyright (c) 2019 https://github.com/tomwerf
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class IngDescription.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Parses the description from CSV files for Ing bank accounts.
|
||||
*
|
||||
* With Mutation 'InternetBankieren', 'Overschrijving', 'Verzamelbetaling' and
|
||||
* 'Incasso' the Name of Opposing account the Opposing IBAN number are in the
|
||||
* Description. This class will remove them, and add Name in description by
|
||||
* 'Betaalautomaat' so those are easily recognizable
|
||||
*/
|
||||
class IngDescription implements SpecificInterface
|
||||
{
|
||||
/** @var array The current row. */
|
||||
public $row;
|
||||
|
||||
/**
|
||||
* Description of the current specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_ing_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the current specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_ing_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the specific code.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
$this->row = array_values($row);
|
||||
array_push($this->row); // New column for "Valutadatum"
|
||||
if (count($this->row) >= 8) { // check if the array is correct
|
||||
switch ($this->row[4]) { // Get value for the mutation type
|
||||
case 'GT': // InternetBankieren
|
||||
case 'OV': // Overschrijving
|
||||
case 'VZ': // Verzamelbetaling
|
||||
case 'IC': // Incasso
|
||||
case 'DV': // Divers
|
||||
$this->removeIBANIngDescription(); // Remove "IBAN:", because it is already at "Tegenrekening"
|
||||
$this->removeNameIngDescription(); // Remove "Naam:", because it is already at "Naam/ Omschrijving"
|
||||
$this->removeIngDescription(); // Remove "Omschrijving", but not the value from description
|
||||
$this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column
|
||||
$this->MoveSavingsAccount(); // Move savings account number and name
|
||||
break;
|
||||
case 'BA': // Betaalautomaat
|
||||
$this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column
|
||||
$this->addNameIngDescription();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the Opposing name from cell 1 in the description for Betaalautomaten
|
||||
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
|
||||
*/
|
||||
protected function addNameIngDescription(): void
|
||||
{
|
||||
$this->row[8] = $this->row[1] . ' ' . $this->row[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Move "Valutadatum" from the description to new column.
|
||||
*/
|
||||
protected function moveValutadatumDescription(): void
|
||||
{
|
||||
$matches = [];
|
||||
if (preg_match('/Valutadatum: ([0-9-]+)/', $this->row[8], $matches)) {
|
||||
$this->row[9] = date("Ymd", strtotime($matches[1]));
|
||||
$this->row[8] = preg_replace('/Valutadatum: [0-9-]+/', '', $this->row[8]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove IBAN number out of the description
|
||||
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
|
||||
*/
|
||||
protected function removeIBANIngDescription(): void
|
||||
{
|
||||
// Try replace the iban number with nothing. The IBAN nr is found in the third column
|
||||
$this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove "Omschrijving" (and NOT its value) from the description.
|
||||
*/
|
||||
protected function removeIngDescription(): void
|
||||
{
|
||||
$this->row[8] = preg_replace('/Omschrijving: /', '', $this->row[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove "Naam" (and its value) from the description.
|
||||
*/
|
||||
protected function removeNameIngDescription(): void
|
||||
{
|
||||
$this->row[8] = preg_replace('/Naam:.*?([a-zA-Z\/]+:)/', '$1', $this->row[8]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move savings account number to column 1 and name to column 3.
|
||||
*/
|
||||
private function MoveSavingsAccount(): void
|
||||
{
|
||||
$matches = [];
|
||||
|
||||
if (preg_match('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', $this->row[8], $matches)) { // Search for saving acount at 'Mededelingen' column
|
||||
$this->row[1] = $this->row[1] . ' ' . $matches[2] . ' ' . $matches[3]; // Current name + Saving acount name + Acount number
|
||||
if ('' === (string) $this->row[3]) { // if Saving account number does not yet exists
|
||||
$this->row[3] = $matches[3]; // Copy savings account number
|
||||
}
|
||||
$this->row[8] = preg_replace('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', '', $this->row[8]); // Remove the savings account content from description
|
||||
} elseif (preg_match('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', $this->row[1], $matches)) { // Search for saving acount at 'Naam / Omschrijving' column
|
||||
$this->row[1] = $matches[2] . ' ' . $matches[3]; // Saving acount name + Acount number
|
||||
if ('' === (string) $this->row[3]) { // if Saving account number does not yet exists
|
||||
$this->row[3] = $matches[3]; // Copy savings account number
|
||||
}
|
||||
}
|
||||
|
||||
if ('' !== (string)$this->row[3]) { // if Saving account number exists
|
||||
if (! preg_match('/[A-Za-z]/', $this->row[3])) { // if Saving account number has no characters
|
||||
$this->row[3] = sprintf("%010d", $this->row[3]); // Make the number 10 digits
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PresidentsChoice.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class PresidentsChoice.
|
||||
*
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class PresidentsChoice implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Description of specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_pres_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_pres_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this specific.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
$row = array_values($row);
|
||||
// first, if column 2 is empty and 3 is not, do nothing.
|
||||
// if column 3 is empty and column 2 is not, move amount to column 3, *-1
|
||||
if (isset($row[3]) && '' === $row[3]) {
|
||||
$row[3] = bcmul($row[2], '-1');
|
||||
}
|
||||
if (isset($row[1])) {
|
||||
// copy description into column 2, which is now usable.
|
||||
$row[2] = $row[1];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* RabobankDescription.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class RabobankDescription.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class RabobankDescription implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Description of this specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_rabo_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of this specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_rabo_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the specific.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
$row = array_values($row);
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SnsDescription.php
|
||||
* Copyright (c) 2019 hugovanduijn@gmail.com.
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class SnsDescription.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class SnsDescription implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Get description of specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
{
|
||||
return 'import.specific_sns_descr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of specific.
|
||||
*
|
||||
* @return string
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'import.specific_sns_name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run specific.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $row): array
|
||||
{
|
||||
$row = array_values($row);
|
||||
if (!isset($row[17])) {
|
||||
return $row;
|
||||
}
|
||||
$row[17] = ltrim($row[17], "'");
|
||||
$row[17] = rtrim($row[17], "'");
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpecificInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Interface SpecificInterface.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
interface SpecificInterface
|
||||
{
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription(): string;
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName(): string;
|
||||
|
||||
/**
|
||||
* Run specific.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $row): array;
|
||||
}
|
@@ -1,630 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ImportArrayStorage.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Storage;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Events\RequestedReportOnJournals;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Engine\RuleEngine;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Creates new transactions based on arrays.
|
||||
*
|
||||
* Class ImportArrayStorage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*
|
||||
*/
|
||||
class ImportArrayStorage
|
||||
{
|
||||
/** @var int Number of hits required for a transfer to match. */
|
||||
private const REQUIRED_HITS = 4;
|
||||
/** @var bool Check for transfers during import. */
|
||||
private $checkForTransfers = false;
|
||||
/** @var TransactionGroupRepositoryInterface */
|
||||
private $groupRepos;
|
||||
/** @var ImportJob The import job */
|
||||
private $importJob;
|
||||
/** @var JournalRepositoryInterface Journal repository for storage. */
|
||||
private $journalRepos;
|
||||
/** @var string */
|
||||
private $language = 'en_US';
|
||||
/** @var ImportJobRepositoryInterface Import job repository */
|
||||
private $repository;
|
||||
/** @var array The transfers the user already has. */
|
||||
private $transfers;
|
||||
|
||||
/**
|
||||
* Set job, count transfers in the array and create the repository.
|
||||
*
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
|
||||
$this->countTransfers();
|
||||
|
||||
$this->journalRepos = app(JournalRepositoryInterface::class);
|
||||
$this->journalRepos->setUser($importJob->user);
|
||||
|
||||
$this->groupRepos = app(TransactionGroupRepositoryInterface::class);
|
||||
$this->groupRepos->setUser($importJob->user);
|
||||
|
||||
// get language of user.
|
||||
/** @var Preference $pref */
|
||||
$pref = app('preferences')->getForUser($importJob->user, 'language', config('firefly.default_language', 'en_US'));
|
||||
$this->language = $pref->data;
|
||||
|
||||
Log::debug('Constructed ImportArrayStorage()');
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually does the storing. Does three things.
|
||||
* - Store journals
|
||||
* - Link to tag
|
||||
* - Run rules (if set to)
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return Collection
|
||||
*/
|
||||
public function store(): Collection
|
||||
{
|
||||
// store transactions
|
||||
$this->setStatus('storing_data');
|
||||
$collection = $this->storeGroupArray();
|
||||
$this->setStatus('stored_data');
|
||||
|
||||
// link tag:
|
||||
$this->setStatus('linking_to_tag');
|
||||
$this->linkToTag($collection);
|
||||
$this->setStatus('linked_to_tag');
|
||||
|
||||
// run rules, if configured to.
|
||||
$config = $this->importJob->configuration;
|
||||
if (isset($config['apply-rules']) && true === $config['apply-rules']) {
|
||||
$this->setStatus('applying_rules');
|
||||
$this->applyRules($collection);
|
||||
$this->setStatus('rules_applied');
|
||||
}
|
||||
|
||||
app('preferences')->mark();
|
||||
|
||||
// email about this:
|
||||
event(new RequestedReportOnJournals((int) $this->importJob->user_id, $collection));
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the users rules to the created journals.
|
||||
*
|
||||
* @param Collection $collection
|
||||
*
|
||||
*/
|
||||
private function applyRules(Collection $collection): void
|
||||
{
|
||||
Log::debug('Now in applyRules()');
|
||||
|
||||
/** @var RuleEngine $ruleEngine */
|
||||
$ruleEngine = app(RuleEngine::class);
|
||||
$ruleEngine->setUser($this->importJob->user);
|
||||
$ruleEngine->setAllRules(true);
|
||||
|
||||
// for this call, the rule engine only includes "store" rules:
|
||||
$ruleEngine->setTriggerMode(RuleEngine::TRIGGER_STORE);
|
||||
Log::debug('Start of engine loop');
|
||||
foreach ($collection as $group) {
|
||||
$this->applyRulesGroup($ruleEngine, $group);
|
||||
}
|
||||
Log::debug('End of engine loop.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleEngine $ruleEngine
|
||||
* @param TransactionGroup $group
|
||||
*/
|
||||
private function applyRulesGroup(RuleEngine $ruleEngine, TransactionGroup $group): void
|
||||
{
|
||||
Log::debug(sprintf('Processing group #%d', $group->id));
|
||||
foreach ($group->transactionJournals as $journal) {
|
||||
Log::debug(sprintf('Processing journal #%d from group #%d', $journal->id, $group->id));
|
||||
$ruleEngine->processTransactionJournal($journal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of transfers in the array. If this is zero, don't bother checking for double transfers.
|
||||
*/
|
||||
private function countTransfers(): void
|
||||
{
|
||||
Log::debug('Now in countTransfers()');
|
||||
/** @var array $array */
|
||||
$array = $this->repository->getTransactions($this->importJob);
|
||||
|
||||
|
||||
$count = 0;
|
||||
foreach ($array as $index => $group) {
|
||||
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
if (strtolower(TransactionType::TRANSFER) === strtolower($transaction['type'])) {
|
||||
$count++;
|
||||
Log::debug(sprintf('Row #%d is a transfer, increase count to %d', $index + 1, $count));
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Count of transfers in import array is %d.', $count));
|
||||
if ($count > 0) {
|
||||
$this->checkForTransfers = true;
|
||||
Log::debug('Will check for duplicate transfers.');
|
||||
// get users transfers. Needed for comparison.
|
||||
$this->getTransfers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $group
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function duplicateDetected(int $index, array $group): bool
|
||||
{
|
||||
Log::debug(sprintf('Now in duplicateDetected(%d)', $index));
|
||||
$transactions = $group['transactions'] ?? [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$hash = $this->getHash($transaction);
|
||||
$existingId = $this->hashExists($hash);
|
||||
if (null !== $existingId) {
|
||||
$message = (string) trans('import.duplicate_row', ['row' => $index, 'description' => $transaction['description']]);
|
||||
$this->logDuplicateObject($transaction, $existingId);
|
||||
$this->repository->addErrorMessage($this->importJob, $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// do transfer detection:
|
||||
if ($this->checkForTransfers && $this->transferExists($transaction)) {
|
||||
$message = (string) trans('import.duplicate_row', ['row' => $index, 'description' => $transaction['description']]);
|
||||
$this->logDuplicateTransfer($transaction);
|
||||
$this->repository->addErrorMessage($this->importJob, $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash of transaction.
|
||||
*
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHash(array $transaction): string
|
||||
{
|
||||
unset($transaction['import_hash_v2'], $transaction['original_source']);
|
||||
$json = json_encode($transaction, JSON_THROW_ON_ERROR);
|
||||
if (false === $json) {
|
||||
// @codeCoverageIgnoreStart
|
||||
/** @noinspection ForgottenDebugOutputInspection */
|
||||
Log::error('Could not encode import array.', $transaction);
|
||||
try {
|
||||
$json = random_int(1, 10000);
|
||||
} catch (Exception $e) {
|
||||
// seriously?
|
||||
Log::error(sprintf('random_int() just failed. I want a medal: %s', $e->getMessage()));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$hash = hash('sha256', $json);
|
||||
Log::debug(sprintf('The hash is: %s', $hash), $transaction);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getTransactionFromJournal(TransactionGroup $transactionGroup): array
|
||||
{
|
||||
// collect transactions using the journal collector
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->importJob->user);
|
||||
$collector->setGroup($transactionGroup);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the users transfers, so they can be compared to whatever the user is trying to import.
|
||||
*/
|
||||
private function getTransfers(): void
|
||||
{
|
||||
Log::debug('Now in getTransfers()');
|
||||
app('preferences')->mark();
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->importJob->user);
|
||||
$collector
|
||||
->setTypes([TransactionType::TRANSFER])->setLimit(10000)->setPage(1)
|
||||
->withAccountInformation();
|
||||
$this->transfers = $collector->getExtractedJournals();
|
||||
Log::debug(sprintf('Count of getTransfers() is %d', count($this->transfers)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the hash exists for the array the user wants to import.
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
private function hashExists(string $hash): ?int
|
||||
{
|
||||
$entry = $this->journalRepos->findByHash($hash);
|
||||
if (null === $entry) {
|
||||
Log::debug(sprintf('Found no transactions with hash %s.', $hash));
|
||||
|
||||
return null;
|
||||
}
|
||||
Log::info(sprintf('Found a transaction journal with an existing hash: %s', $hash));
|
||||
|
||||
return (int) $entry->transaction_journal_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link all imported journals to a tag.
|
||||
*
|
||||
* @param Collection $collection
|
||||
*/
|
||||
private function linkToTag(Collection $collection): void
|
||||
{
|
||||
if (0 === $collection->count()) {
|
||||
return;
|
||||
}
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$repository->setUser($this->importJob->user);
|
||||
$data = [
|
||||
'tag' => (string) trans('import.import_with_key', ['key' => $this->importJob->key]),
|
||||
'date' => new Carbon,
|
||||
'description' => null,
|
||||
'latitude' => null,
|
||||
'longitude' => null,
|
||||
'zoom_level' => null,
|
||||
'tagMode' => 'nothing',
|
||||
];
|
||||
$tag = $repository->store($data);
|
||||
|
||||
Log::debug(sprintf('Created tag #%d ("%s")', $tag->id, $tag->tag));
|
||||
Log::debug('Looping groups...');
|
||||
|
||||
// TODO double loop.
|
||||
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($collection as $group) {
|
||||
Log::debug(sprintf('Looping journals in group #%d', $group->id));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journalIds = $group->transactionJournals->pluck('id')->toArray();
|
||||
$tagId = $tag->id;
|
||||
foreach ($journalIds as $journalId) {
|
||||
Log::debug(sprintf('Linking journal #%d to tag #%d...', $journalId, $tagId));
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
DB::table('tag_transaction_journal')->insert(['transaction_journal_id' => $journalId, 'tag_id' => $tagId]);
|
||||
} catch (QueryException $e) {
|
||||
Log::error(sprintf('Could not link journal #%d to tag #%d because: %s', $journalId, $tagId, $e->getMessage()));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
Log::info(sprintf('Linked %d journals to tag #%d ("%s")', $collection->count(), $tag->id, $tag->tag));
|
||||
}
|
||||
$this->repository->setTag($this->importJob, $tag);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Log about a duplicate object (double hash).
|
||||
*
|
||||
* @param array $transaction
|
||||
* @param int $existingId
|
||||
*/
|
||||
private function logDuplicateObject(array $transaction, int $existingId): void
|
||||
{
|
||||
Log::info(
|
||||
'Transaction is a duplicate, and will not be imported (the hash exists).',
|
||||
[
|
||||
'existing' => $existingId,
|
||||
'description' => $transaction['description'] ?? '',
|
||||
'amount' => $transaction['transactions'][0]['amount'] ?? 0,
|
||||
'date' => $transaction['date'] ?? '',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Log about a duplicate transfer.
|
||||
*
|
||||
* @param array $transaction
|
||||
*/
|
||||
private function logDuplicateTransfer(array $transaction): void
|
||||
{
|
||||
Log::info(
|
||||
'Transaction is a duplicate transfer, and will not be imported (such a transfer exists already).',
|
||||
[
|
||||
'description' => $transaction['description'] ?? '',
|
||||
'amount' => $transaction['transactions'][0]['amount'] ?? 0,
|
||||
'date' => $transaction['date'] ?? '',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand method to quickly set job status
|
||||
*
|
||||
* @param string $status
|
||||
*/
|
||||
private function setStatus(string $status): void
|
||||
{
|
||||
$this->repository->setStatus($this->importJob, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $group
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
private function storeGroup(int $index, array $group): ?TransactionGroup
|
||||
{
|
||||
Log::debug(sprintf('Going to store entry #%d', $index + 1));
|
||||
|
||||
// do some basic error catching.
|
||||
foreach ($group['transactions'] as $groupIndex => $transaction) {
|
||||
$group['transactions'][$groupIndex]['date'] = Carbon::parse($transaction['date'], config('app.timezone'));
|
||||
$group['transactions'][$groupIndex]['description'] = '' === $transaction['description'] ? '(empty description)' : $transaction['description'];
|
||||
}
|
||||
|
||||
// do duplicate detection!
|
||||
if ($this->duplicateDetected($index, $group)) {
|
||||
Log::warning(sprintf('Row #%d seems to be a imported already and will be ignored.', $index));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// store the group
|
||||
try {
|
||||
$newGroup = $this->groupRepos->store($group);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->repository->addErrorMessage($this->importJob, sprintf('Row #%d could not be imported. %s', $index, $e->getMessage()));
|
||||
|
||||
return null;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
Log::debug(sprintf('Stored as group #%d', $newGroup->id));
|
||||
|
||||
// add to collection of transfers, if necessary:
|
||||
if ('transfer' === strtolower($group['transactions'][0]['type'])) {
|
||||
$journals = $this->getTransactionFromJournal($newGroup);
|
||||
Log::debug('We just stored a transfer, so add the journal to the list of transfers.');
|
||||
foreach ($journals as $newJournal) {
|
||||
$this->transfers[] = $newJournal;
|
||||
}
|
||||
Log::debug(sprintf('List length is now %d', count($this->transfers)));
|
||||
}
|
||||
|
||||
return $newGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store array as journals.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function storeGroupArray(): Collection
|
||||
{
|
||||
/** @var array $array */
|
||||
$array = $this->repository->getTransactions($this->importJob);
|
||||
$count = count($array);
|
||||
|
||||
Log::notice(sprintf('Will now store the groups. Count of groups is %d.', $count));
|
||||
Log::notice('Going to store...');
|
||||
|
||||
$collection = new Collection;
|
||||
foreach ($array as $index => $group) {
|
||||
Log::debug(sprintf('Now store #%d', $index + 1));
|
||||
$result = $this->storeGroup($index, $group);
|
||||
if (null !== $result) {
|
||||
$collection->push($result);
|
||||
}
|
||||
}
|
||||
Log::notice(sprintf('Done storing. Firefly III has stored %d transactions.', $collection->count()));
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a transfer exists.
|
||||
*
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
private function transferExists(array $transaction): bool
|
||||
{
|
||||
Log::debug('transferExists() Check if transaction is a double transfer.');
|
||||
|
||||
// how many hits do we need?
|
||||
Log::debug(sprintf('System has %d existing transfers', count($this->transfers)));
|
||||
// loop over each split:
|
||||
|
||||
// check if is a transfer
|
||||
if (strtolower(TransactionType::TRANSFER) !== strtolower($transaction['type'])) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug(sprintf('Is a %s, not a transfer so no.', $transaction['type']));
|
||||
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
||||
Log::debug(sprintf('Required hits for transfer comparison is %d', self::REQUIRED_HITS));
|
||||
|
||||
// get the amount:
|
||||
/** @noinspection UnnecessaryCastingInspection */
|
||||
$amount = (string) ($transaction['amount'] ?? '0');
|
||||
if (bccomp($amount, '0') === -1) {
|
||||
$amount = bcmul($amount, '-1'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// get the description:
|
||||
//$description = '' === (string)$transaction['description'] ? $transaction['description'] : $transaction['description'];
|
||||
$description = (string) $transaction['description'];
|
||||
|
||||
// get the source and destination ID's:
|
||||
$transactionSourceIDs = [(int) $transaction['source_id'], (int) $transaction['destination_id']];
|
||||
sort($transactionSourceIDs);
|
||||
|
||||
// get the source and destination names:
|
||||
$transactionSourceNames = [(string) $transaction['source_name'], (string) $transaction['destination_name']];
|
||||
sort($transactionSourceNames);
|
||||
|
||||
// then loop all transfers:
|
||||
/** @var array $transfer */
|
||||
foreach ($this->transfers as $transfer) {
|
||||
// number of hits for this split-transfer combination:
|
||||
$hits = 0;
|
||||
Log::debug(sprintf('Now looking at transaction journal #%d', $transfer['transaction_journal_id']));
|
||||
// compare amount:
|
||||
$originalAmount = app('steam')->positive($transfer['amount']);
|
||||
Log::debug(sprintf('Amount %s compared to %s', $amount, $originalAmount));
|
||||
if (0 !== bccomp($amount, $originalAmount)) {
|
||||
Log::debug('Amount is not a match, continue with next transfer.');
|
||||
continue;
|
||||
}
|
||||
++$hits;
|
||||
Log::debug(sprintf('Comparison is a hit! (%s)', $hits));
|
||||
|
||||
// compare description:
|
||||
// $comparison = '(empty description)' === $transfer['description'] ? '' : $transfer['description'];
|
||||
$comparison = $transfer['description'];
|
||||
Log::debug(sprintf('Comparing "%s" to "%s" (original: "%s")', $description, $transfer['description'], $comparison));
|
||||
if ($description !== $comparison) {
|
||||
Log::debug('Description is not a match, continue with next transfer.');
|
||||
continue; // @codeCoverageIgnore
|
||||
}
|
||||
++$hits;
|
||||
Log::debug(sprintf('Comparison is a hit! (%s)', $hits));
|
||||
|
||||
// compare date:
|
||||
$transferDate = $transfer['date']->format('Y-m-d H:i:s');
|
||||
$transactionDate = $transaction['date']->format('Y-m-d H:i:s');
|
||||
Log::debug(sprintf('Comparing dates "%s" to "%s"', $transactionDate, $transferDate));
|
||||
if ($transactionDate !== $transferDate) {
|
||||
Log::debug('Date is not a match, continue with next transfer.');
|
||||
continue; // @codeCoverageIgnore
|
||||
}
|
||||
++$hits;
|
||||
Log::debug(sprintf('Comparison is a hit! (%s)', $hits));
|
||||
|
||||
// compare source and destination id's
|
||||
$transferSourceIDs = [(int) $transfer['source_account_id'], (int) $transfer['destination_account_id']];
|
||||
sort($transferSourceIDs);
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
Log::debug('Comparing current transaction source+dest IDs', $transactionSourceIDs);
|
||||
Log::debug('.. with current transfer source+dest IDs', $transferSourceIDs);
|
||||
if ($transactionSourceIDs === $transferSourceIDs) {
|
||||
++$hits;
|
||||
Log::debug(sprintf('Source IDs are the same! (%d)', $hits));
|
||||
}
|
||||
if ($transactionSourceIDs !== $transferSourceIDs) {
|
||||
Log::debug('Source IDs are not the same.');
|
||||
}
|
||||
unset($transferSourceIDs);
|
||||
|
||||
// compare source and destination names
|
||||
$transferSource = [(string) ($transfer['source_account_name'] ?? ''), (string) ($transfer['destination_account_name'] ?? '')];
|
||||
sort($transferSource);
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
Log::debug('Comparing current transaction source+dest names', $transactionSourceNames);
|
||||
Log::debug('.. with current transfer source+dest names', $transferSource);
|
||||
if ($transactionSourceNames === $transferSource && $transferSource !== ['', '']) {
|
||||
// @codeCoverageIgnoreStart
|
||||
++$hits;
|
||||
Log::debug(sprintf('Source names are the same! (%d)', $hits));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if ($transactionSourceNames !== $transferSource) {
|
||||
Log::debug('Source names are not the same.');
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Number of hits is %d', $hits));
|
||||
if ($hits >= self::REQUIRED_HITS) {
|
||||
Log::debug(sprintf('Is more than %d, return true.', self::REQUIRED_HITS));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Log::debug('Is not an existing transfer, return false.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -94,6 +94,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property-read int|null $notes_count
|
||||
* @property-read int|null $piggy_banks_count
|
||||
* @property-read int|null $transactions_count
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property int $account_type_id
|
||||
* @property bool $encrypted
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks
|
||||
*/
|
||||
class Account extends Model
|
||||
{
|
||||
|
@@ -1,150 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportJob.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Eloquent;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class ImportJob.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @property array $transactions
|
||||
* @property array $configuration
|
||||
* @property User $user
|
||||
* @property int $user_id
|
||||
* @property string $status
|
||||
* @property string $stage
|
||||
* @property string $key
|
||||
* @property string $provider
|
||||
* @property string $file_type
|
||||
* @property int $tag_id
|
||||
* @property Tag $tag
|
||||
* @property array $errors
|
||||
* @property array extended_status
|
||||
* @property int id
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property-read Collection|Attachment[] $attachments
|
||||
* @method static Builder|ImportJob newModelQuery()
|
||||
* @method static Builder|ImportJob newQuery()
|
||||
* @method static Builder|ImportJob query()
|
||||
* @method static Builder|ImportJob whereConfiguration($value)
|
||||
* @method static Builder|ImportJob whereCreatedAt($value)
|
||||
* @method static Builder|ImportJob whereErrors($value)
|
||||
* @method static Builder|ImportJob whereExtendedStatus($value)
|
||||
* @method static Builder|ImportJob whereFileType($value)
|
||||
* @method static Builder|ImportJob whereId($value)
|
||||
* @method static Builder|ImportJob whereKey($value)
|
||||
* @method static Builder|ImportJob whereProvider($value)
|
||||
* @method static Builder|ImportJob whereStage($value)
|
||||
* @method static Builder|ImportJob whereStatus($value)
|
||||
* @method static Builder|ImportJob whereTagId($value)
|
||||
* @method static Builder|ImportJob whereTransactions($value)
|
||||
* @method static Builder|ImportJob whereUpdatedAt($value)
|
||||
* @method static Builder|ImportJob whereUserId($value)
|
||||
* @mixin Eloquent
|
||||
* @property-read int|null $attachments_count
|
||||
* @property int $id
|
||||
* @property array|null $extended_status
|
||||
*/
|
||||
class ImportJob extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts
|
||||
= [
|
||||
'user_id' => 'int',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'configuration' => 'array',
|
||||
'extended_status' => 'array',
|
||||
'transactions' => 'array',
|
||||
'errors' => 'array',
|
||||
];
|
||||
/** @var array Fields that can be filled */
|
||||
protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors'];
|
||||
|
||||
/**
|
||||
* Route binder. Converts the key in the URL to the specified object (or throw 404).
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value): ImportJob
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$key = trim($value);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var ImportJob $importJob */
|
||||
$importJob = $user->importJobs()->where('key', $key)->first();
|
||||
if (null !== $importJob) {
|
||||
return $importJob;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Attachment::class, 'attachable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function tag(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tag::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
@@ -8,6 +8,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class ObjectGroup
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks
|
||||
* @property-read int|null $piggy_banks_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ObjectGroup newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ObjectGroup newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ObjectGroup query()
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ObjectGroup extends Model
|
||||
{
|
||||
|
@@ -78,6 +78,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property-read int|null $notes_count
|
||||
* @property-read int|null $piggy_bank_events_count
|
||||
* @property-read int|null $piggy_bank_repetitions_count
|
||||
* @property bool $encrypted
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\ObjectGroup[] $objectGroups
|
||||
* @property-read int|null $object_groups_count
|
||||
*/
|
||||
class PiggyBank extends Model
|
||||
{
|
||||
|
@@ -78,6 +78,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|Location[] $locations
|
||||
* @property-read int|null $locations_count
|
||||
* @property-read int|null $transaction_journals_count
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property string $tagMode
|
||||
* @property string|null $description
|
||||
* @property float|null $latitude
|
||||
* @property float|null $longitude
|
||||
* @property int|null $zoomLevel
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
|
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportServiceProvider.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Providers;
|
||||
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepository;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportServiceProvider.
|
||||
* @deprecated
|
||||
*/
|
||||
class ImportServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->bind(
|
||||
ImportJobRepositoryInterface::class,
|
||||
function (Application $app) {
|
||||
/** @var ImportJobRepositoryInterface $repository */
|
||||
$repository = app(ImportJobRepository::class);
|
||||
if ($app->auth->check()) {
|
||||
$repository->setUser(auth()->user());
|
||||
}
|
||||
|
||||
return $repository;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,479 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportJobRepository.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\ImportJob;
|
||||
|
||||
use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Str;
|
||||
use Log;
|
||||
use Storage;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
/**
|
||||
* Class ImportJobRepository.
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*
|
||||
*/
|
||||
class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
{
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
|
||||
protected $uploadDisk;
|
||||
/** @var int */
|
||||
private $maxUploadSize;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->maxUploadSize = (int)config('firefly.maxUploadSize');
|
||||
$this->uploadDisk = Storage::disk('upload');
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $error
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function addErrorMessage(ImportJob $job, string $error): ImportJob
|
||||
{
|
||||
$errors = $job->errors;
|
||||
$errors[] = $error;
|
||||
$job->errors = $errors;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append transactions to array instead of replacing them.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return ImportJob
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function appendTransactions(ImportJob $job, array $transactions): ImportJob
|
||||
{
|
||||
Log::debug(sprintf('Now in appendTransactions(%s)', $job->key));
|
||||
$existingTransactions = $this->getTransactions($job);
|
||||
$new = array_merge($existingTransactions, $transactions);
|
||||
Log::debug(sprintf('Old transaction count: %d', count($existingTransactions)));
|
||||
Log::debug(sprintf('To be added transaction count: %d', count($transactions)));
|
||||
Log::debug(sprintf('New count: %d', count($new)));
|
||||
$this->setTransactions($job, $new);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countTransactions(ImportJob $job): int
|
||||
{
|
||||
$info = $job->transactions ?? [];
|
||||
if (isset($info['count'])) {
|
||||
return (int)$info['count'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $importProvider
|
||||
*
|
||||
* @return ImportJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function create(string $importProvider): ImportJob
|
||||
{
|
||||
$count = 0;
|
||||
$importProvider = strtolower($importProvider);
|
||||
|
||||
while ($count < 30) {
|
||||
$key = Str::random(12);
|
||||
$existing = $this->findByKey($key);
|
||||
if (null === $existing) {
|
||||
$importJob = ImportJob::create(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'tag_id' => null,
|
||||
'provider' => $importProvider,
|
||||
'file_type' => '',
|
||||
'key' => Str::random(12),
|
||||
'status' => 'new',
|
||||
'stage' => 'new',
|
||||
'configuration' => [],
|
||||
'extended_status' => [],
|
||||
'transactions' => [],
|
||||
'errors' => [],
|
||||
]
|
||||
);
|
||||
|
||||
// breaks the loop:
|
||||
return $importJob;
|
||||
}
|
||||
++$count;
|
||||
}
|
||||
throw new FireflyException('Could not create an import job with a unique key after 30 tries.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $jobId
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function find(int $jobId): ?ImportJob
|
||||
{
|
||||
return $this->user->importJobs()->find($jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function findByKey(string $key): ?ImportJob
|
||||
{
|
||||
/** @var ImportJob $result */
|
||||
$result = $this->user->importJobs()->where('key', $key)->first(['import_jobs.*']);
|
||||
if (null === $result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all import jobs.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->importJobs()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all attachments for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(ImportJob $job): Collection
|
||||
{
|
||||
return $job->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return configuration of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfiguration(ImportJob $job): array
|
||||
{
|
||||
return $job->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extended status of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtendedStatus(ImportJob $job): array
|
||||
{
|
||||
$status = $job->extended_status;
|
||||
if (is_array($status)) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return transactions from attachment.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function getTransactions(ImportJob $job): array
|
||||
{
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$array = [];
|
||||
if ($disk->exists($filename)) {
|
||||
$json = $disk->get($filename);
|
||||
$array = json_decode($json, true);
|
||||
}
|
||||
if (false === $array) {
|
||||
$array = [];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setConfiguration(ImportJob $job, array $configuration): ImportJob
|
||||
{
|
||||
Log::debug('Updating configuration...');
|
||||
//Log::debug(sprintf('Incoming config for job "%s" is: ', $job->key), $configuration);
|
||||
$currentConfig = $job->configuration;
|
||||
$newConfig = array_merge($currentConfig, $configuration);
|
||||
$job->configuration = $newConfig;
|
||||
$job->save();
|
||||
|
||||
//Log::debug(sprintf('Set config of job "%s" to: ', $job->key), $newConfig);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $stage
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setStage(ImportJob $job, string $stage): ImportJob
|
||||
{
|
||||
$job->stage = $stage;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $status
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setStatus(ImportJob $job, string $status): ImportJob
|
||||
{
|
||||
Log::debug(sprintf('Set status of job "%s" to "%s"', $job->key, $status));
|
||||
$job->status = $status;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTag(ImportJob $job, Tag $tag): ImportJob
|
||||
{
|
||||
$job->tag()->associate($tag);
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTransactions(ImportJob $job, array $transactions): ImportJob
|
||||
{
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$json = json_encode($transactions);
|
||||
|
||||
// set count for easy access
|
||||
$array = ['count' => count($transactions)];
|
||||
$job->transactions = $array;
|
||||
$job->save();
|
||||
// store file.
|
||||
$disk->put($filename, $json);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle upload for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $name
|
||||
* @param string $fileName
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storeCLIUpload(ImportJob $job, string $name, string $fileName): MessageBag
|
||||
{
|
||||
$messages = new MessageBag;
|
||||
if (!file_exists($fileName)) {
|
||||
$messages->add('notfound', sprintf('File not found: %s', $fileName));
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
$count = $job->attachments()->get()->filter(
|
||||
function (Attachment $att) use ($name) {
|
||||
return $att->filename === $name;
|
||||
}
|
||||
)->count();
|
||||
|
||||
if ($count > 0) {// don't upload, but also don't complain about it.
|
||||
Log::error(sprintf('Detected duplicate upload. Will ignore second "%s" file.', $name));
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
$content = file_get_contents($fileName);
|
||||
$attachment = new Attachment; // create Attachment object.
|
||||
$attachment->user()->associate($job->user);
|
||||
$attachment->attachable()->associate($job);
|
||||
$attachment->md5 = substr(hash('sha256', $content), 0, 32); // limit due to DB.
|
||||
$attachment->filename = $name;
|
||||
$attachment->mime = 'plain/txt';
|
||||
$attachment->size = strlen($content);
|
||||
$attachment->uploaded = false;
|
||||
$attachment->save();
|
||||
|
||||
$this->uploadDisk->put($attachment->fileName(), $content);
|
||||
$attachment->uploaded = true; // update attachment
|
||||
$attachment->save();
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle upload for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $name
|
||||
* @param UploadedFile $file
|
||||
*
|
||||
* @return MessageBag
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function storeFileUpload(ImportJob $job, string $name, UploadedFile $file): MessageBag
|
||||
{
|
||||
$messages = new MessageBag;
|
||||
if ($this->validSize($file)) {
|
||||
$name = e($file->getClientOriginalName());
|
||||
$messages->add('size', (string)trans('validation.file_too_large', ['name' => $name]));
|
||||
|
||||
return $messages;
|
||||
}
|
||||
$count = $job->attachments()->get()->filter(
|
||||
function (Attachment $att) use ($name) {
|
||||
return $att->filename === $name;
|
||||
}
|
||||
)->count();
|
||||
if ($count > 0) { // don't upload, but also don't complain about it.
|
||||
Log::error(sprintf('Detected duplicate upload. Will ignore second "%s" file.', $name));
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
$attachment = new Attachment; // create Attachment object.
|
||||
$attachment->user()->associate($job->user);
|
||||
$attachment->attachable()->associate($job);
|
||||
$attachment->md5 = md5_file($file->getRealPath());
|
||||
$attachment->filename = $name;
|
||||
$attachment->mime = $file->getMimeType();
|
||||
$attachment->size = $file->getSize();
|
||||
$attachment->uploaded = false;
|
||||
$attachment->save();
|
||||
$fileObject = $file->openFile();
|
||||
$fileObject->rewind();
|
||||
|
||||
|
||||
if (0 === $file->getSize()) {
|
||||
throw new FireflyException('Cannot upload empty or non-existent file.');
|
||||
}
|
||||
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
$this->uploadDisk->put($attachment->fileName(), $content);
|
||||
$attachment->uploaded = true; // update attachment
|
||||
$attachment->save();
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validSize(UploadedFile $file): bool
|
||||
{
|
||||
$size = $file->getSize();
|
||||
|
||||
return $size > $this->maxUploadSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByTag(ImportJob $job): int
|
||||
{
|
||||
return $job->tag->transactionJournals->count();
|
||||
}
|
||||
}
|
@@ -1,207 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportJobRepositoryInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\ImportJob;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
/**
|
||||
* Interface ImportJobRepositoryInterface.
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
interface ImportJobRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Add message to job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $error
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function addErrorMessage(ImportJob $job, string $error): ImportJob;
|
||||
|
||||
/**
|
||||
* Append transactions to array instead of replacing them.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function appendTransactions(ImportJob $job, array $transactions): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countTransactions(ImportJob $job): int;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByTag(ImportJob $job): int;
|
||||
|
||||
/**
|
||||
* @param string $importProvider
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function create(string $importProvider): ImportJob;
|
||||
|
||||
/**
|
||||
* @param int $jobId
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function find(int $jobId): ?ImportJob;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function findByKey(string $key): ?ImportJob;
|
||||
|
||||
/**
|
||||
* Return all import jobs.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* Return all attachments for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(ImportJob $job): Collection;
|
||||
|
||||
/**
|
||||
* Return configuration of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfiguration(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* Return extended status of job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtendedStatus(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* Return transactions from attachment.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setConfiguration(ImportJob $job, array $configuration): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $stage
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setStage(ImportJob $job, string $stage): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $status
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setStatus(ImportJob $job, string $status): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTag(ImportJob $job, Tag $tag): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTransactions(ImportJob $job, array $transactions): ImportJob;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
/**
|
||||
* Store file.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $name
|
||||
* @param string $fileName
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storeCLIUpload(ImportJob $job, string $name, string $fileName): MessageBag;
|
||||
|
||||
/**
|
||||
* Handle upload for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $name
|
||||
* @param UploadedFile $file
|
||||
*
|
||||
* @return MessageBag
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function storeFileUpload(ImportJob $job, string $name, UploadedFile $file): MessageBag;
|
||||
|
||||
|
||||
}
|
@@ -98,32 +98,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$service->destroy($journal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a journal by its hash.
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return TransactionJournalMeta|null
|
||||
*/
|
||||
public function findByHash(string $hash): ?TransactionJournalMeta
|
||||
{
|
||||
$jsonEncode = json_encode($hash);
|
||||
$hashOfHash = hash('sha256', $jsonEncode);
|
||||
Log::debug(sprintf('JSON encoded hash is: %s', $jsonEncode));
|
||||
Log::debug(sprintf('Hash of hash is: %s', $hashOfHash));
|
||||
|
||||
$result = TransactionJournalMeta::withTrashed()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
->where('hash', $hashOfHash)
|
||||
->where('name', 'import_hash_v2')
|
||||
->first(['journal_meta.*']);
|
||||
if (null === $result) {
|
||||
Log::debug('Result is null');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
*
|
||||
|
@@ -67,18 +67,6 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function destroyJournal(TransactionJournal $journal): void;
|
||||
|
||||
|
||||
/**
|
||||
* TODO move to import repository.
|
||||
*
|
||||
* Find a journal by its hash.
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return TransactionJournalMeta|null
|
||||
*/
|
||||
public function findByHash(string $hash): ?TransactionJournalMeta;
|
||||
|
||||
/**
|
||||
* TODO Refactor to "find".
|
||||
* Find a specific journal.
|
||||
|
@@ -112,26 +112,6 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
return $this->user->ruleGroups()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rules for a user tailored to the import process.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getForImport(): Collection
|
||||
{
|
||||
return Rule::distinct()
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
|
||||
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rule_groups.active', 1)
|
||||
->where('rule_triggers.trigger_type', 'user_action')
|
||||
->where('rule_triggers.trigger_value', 'store-journal')
|
||||
->where('rules.active', 1)
|
||||
->orderBy('rule_groups.order', 'ASC')
|
||||
->orderBy('rules.order', 'ASC')
|
||||
->get(['rules.*', 'rule_groups.order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
|
@@ -72,13 +72,6 @@ interface RuleRepositoryInterface
|
||||
*/
|
||||
public function getFirstRuleGroup(): RuleGroup;
|
||||
|
||||
/**
|
||||
* Get the rules for a user tailored to the import process.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getForImport(): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
|
@@ -261,8 +261,6 @@ class UserRepository implements UserRepositoryInterface
|
||||
->where('amount', '>', 0)
|
||||
->whereNull('budgets.deleted_at')
|
||||
->where('budgets.user_id', $user->id)->get(['budget_limits.budget_id'])->count();
|
||||
$return['import_jobs'] = $user->importJobs()->count();
|
||||
$return['import_jobs_success'] = $user->importJobs()->where('status', 'finished')->count();
|
||||
$return['rule_groups'] = $user->ruleGroups()->count();
|
||||
$return['rules'] = $user->rules()->count();
|
||||
$return['tags'] = $user->tags()->count();
|
||||
|
@@ -28,7 +28,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@@ -37,7 +36,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
@@ -94,7 +92,6 @@ class IsValidAttachmentModel implements Rule
|
||||
Bill::class => 'validateBill',
|
||||
Budget::class => 'validateBudget',
|
||||
Category::class => 'validateCategory',
|
||||
ImportJob::class => 'validateImportJob',
|
||||
PiggyBank::class => 'validatePiggyBank',
|
||||
Tag::class => 'validateTag',
|
||||
Transaction::class => 'validateTransaction',
|
||||
@@ -207,20 +204,6 @@ class IsValidAttachmentModel implements Rule
|
||||
return null !== $repository->findTransaction((int) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateImportJob(int $value): bool
|
||||
{
|
||||
/** @var ImportJobRepositoryInterface $repository */
|
||||
$repository = app(ImportJobRepositoryInterface::class);
|
||||
$repository->setUser(auth()->user());
|
||||
|
||||
return null !== $repository->find($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
|
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiContext.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
use bunq\Context\ApiContext as BunqApiContext;
|
||||
use bunq\Context\BunqContext;
|
||||
use bunq\Util\BunqEnumApiEnvironmentType;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Log;
|
||||
use Tests\Object\FakeApiContext;
|
||||
|
||||
/**
|
||||
* Special class to hide away bunq's static initialisation methods.
|
||||
*
|
||||
* Class ApiContext
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ApiContext
|
||||
{
|
||||
|
||||
/**
|
||||
* @param BunqEnumApiEnvironmentType $environmentType
|
||||
* @param string $apiKey
|
||||
* @param string $description
|
||||
* @param array $permittedIps
|
||||
* @param string|null $proxyUrl
|
||||
*
|
||||
* @return BunqApiContext|FakeApiContext
|
||||
*
|
||||
*@throws FireflyException
|
||||
*/
|
||||
public function create(BunqEnumApiEnvironmentType $environmentType, string $apiKey, string $description, array $permittedIps, string $proxyUrl = null
|
||||
) {
|
||||
$permittedIps = $permittedIps ?? [];
|
||||
try {
|
||||
$context = BunqApiContext::create($environmentType, $apiKey, $description, $permittedIps, $proxyUrl);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
if (stripos($message, 'Generating a new private key failed')) {
|
||||
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
|
||||
}
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @param string $jsonString
|
||||
*/
|
||||
public function fromJson(string $jsonString): void
|
||||
{
|
||||
try {
|
||||
$apiContext = BunqApiContext::fromJson($jsonString);
|
||||
BunqContext::loadApiContext($apiContext);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
if (stripos($message, 'Generating a new private key failed')) {
|
||||
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
|
||||
}
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* MonetaryAccount.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
|
||||
use bunq\Model\Generated\Endpoint\BunqResponseMonetaryAccountList;
|
||||
use bunq\Model\Generated\Endpoint\MonetaryAccount as BunqMonetaryAccount;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class MonetaryAccount
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class MonetaryAccount
|
||||
{
|
||||
/**
|
||||
* @param array $params
|
||||
* @param array $customHeaders
|
||||
*
|
||||
* @return BunqResponseMonetaryAccountList
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function listing(array $params = null, array $customHeaders = null): BunqResponseMonetaryAccountList
|
||||
{
|
||||
$params = $params ?? [];
|
||||
$customHeaders = $customHeaders ?? [];
|
||||
try {
|
||||
$result = BunqMonetaryAccount::listing($params, $customHeaders);
|
||||
} catch (Exception $e) {
|
||||
throw new FireflyException($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
|
||||
use bunq\Model\Generated\Endpoint\BunqResponsePaymentList;
|
||||
use bunq\Model\Generated\Endpoint\Payment as BunqPayment;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class Payment
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class Payment
|
||||
{
|
||||
/**
|
||||
* @param int|null $monetaryAccountId
|
||||
* @param array|null $params
|
||||
* @param array|null $customHeaders
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return BunqResponsePaymentList
|
||||
*/
|
||||
public function listing(int $monetaryAccountId = null, array $params = null, array $customHeaders = null): BunqResponsePaymentList
|
||||
{
|
||||
$monetaryAccountId = $monetaryAccountId ?? 0;
|
||||
$params = $params ?? [];
|
||||
$customHeaders = $customHeaders ?? [];
|
||||
try {
|
||||
$result = BunqPayment::listing($monetaryAccountId, $params, $customHeaders);
|
||||
} catch (Exception $e) {
|
||||
throw new FireflyException($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GithubObject.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Object;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class GithubObject
|
||||
*/
|
||||
class GithubObject
|
||||
{
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Release.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Release
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Release extends GithubObject
|
||||
{
|
||||
/** @var string */
|
||||
private $content;
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $title;
|
||||
/** @var Carbon */
|
||||
private $updated;
|
||||
|
||||
/**
|
||||
* Release constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $data['id'];
|
||||
$this->updated = new Carbon($data['updated']);
|
||||
$this->title = $data['title'];
|
||||
$this->content = $data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getUpdated(): Carbon
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GithubRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Request;
|
||||
|
||||
/**
|
||||
* Interface GithubRequest
|
||||
* @deprecated
|
||||
*/
|
||||
interface GithubRequest
|
||||
{
|
||||
public function call(): void;
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* UpdateRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Request;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Github\Object\Release;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class UpdateRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class UpdateRequest implements GithubRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $releases = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$uri = 'https://github.com/firefly-iii/firefly-iii/releases.atom';
|
||||
Log::debug(sprintf('Going to call %s', $uri));
|
||||
try {
|
||||
$client = new Client();
|
||||
$res = $client->request('GET', $uri);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Response error from Github: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
if (200 !== $res->getStatusCode()) {
|
||||
throw new FireflyException(sprintf('Returned code %d.', $res->getStatusCode()));
|
||||
}
|
||||
try {
|
||||
$releaseXml = new SimpleXMLElement($res->getBody()->getContents(), LIBXML_NOCDATA);
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from github updat result: %s', $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not get body from github updat result: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
//fetch the products for each category
|
||||
if (isset($releaseXml->entry)) {
|
||||
Log::debug(sprintf('Count of entries is: %d', count($releaseXml->entry)));
|
||||
foreach ($releaseXml->entry as $entry) {
|
||||
$array = [
|
||||
'id' => (string)$entry->id,
|
||||
'updated' => (string)$entry->updated,
|
||||
'title' => (string)$entry->title,
|
||||
'content' => (string)$entry->content,
|
||||
];
|
||||
Log::debug(sprintf('Found version %s', $entry->title));
|
||||
$this->releases[] = new Release($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getReleases(): array
|
||||
{
|
||||
return $this->releases;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IPRetrievalInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\IP;
|
||||
|
||||
/**
|
||||
* Interface IPRetrievalInterface
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
interface IPRetrievalInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the user's IP address.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getIP(): ?string;
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IpifyOrg.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\IP;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class IpifyOrg
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class IpifyOrg implements IPRetrievalInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's IP address.
|
||||
*
|
||||
* @noinspection MultipleReturnStatementsInspection
|
||||
* @return null|string
|
||||
*/
|
||||
public function getIP(): ?string
|
||||
{
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('GET', 'https://api.ipify.org');
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
Log::warning(sprintf('The ipify.org service could not retrieve external IP: %s', $e->getMessage()));
|
||||
Log::warning($e->getTraceAsString());
|
||||
|
||||
return null;
|
||||
}
|
||||
if (200 !== $res->getStatusCode()) {
|
||||
Log::warning(sprintf('Could not retrieve external IP: %d', $res->getStatusCode()));
|
||||
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$body = (string)$res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from ipify.org result: %s', $e->getMessage()));
|
||||
$body = null;
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* DuplicatedCustomerException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class DuplicatedCustomerException
|
||||
* @deprecated
|
||||
*/
|
||||
class DuplicatedCustomerException extends SpectreException
|
||||
{
|
||||
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class SpectreException
|
||||
* @deprecated
|
||||
*/
|
||||
class SpectreException extends Exception
|
||||
{
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* WrongRequestFormatException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class WrongRequestFormatException
|
||||
* @deprecated
|
||||
*/
|
||||
class WrongRequestFormatException extends SpectreException
|
||||
{
|
||||
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Account.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @deprecated
|
||||
*/
|
||||
class Account extends SpectreObject
|
||||
{
|
||||
/** @var float */
|
||||
private $balance;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var string */
|
||||
private $currencyCode;
|
||||
/** @var array */
|
||||
private $extra = [];
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var int */
|
||||
private $loginId;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var string */
|
||||
private $nature;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Account constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->loginId = $data['login_id'];
|
||||
$this->currencyCode = $data['currency_code'];
|
||||
$this->balance = $data['balance'];
|
||||
$this->name = $data['name'];
|
||||
$this->nature = $data['nature'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
$extraArray = is_array($data['extra']) ? $data['extra'] : [];
|
||||
foreach ($extraArray as $key => $value) {
|
||||
$this->extra[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getBalance(): float
|
||||
{
|
||||
return $this->balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode(): string
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExtra(): array
|
||||
{
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNature(): string
|
||||
{
|
||||
return $this->nature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'balance' => $this->balance,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'currency_code' => $this->currencyCode,
|
||||
'extra' => $this->extra,
|
||||
'id' => $this->id,
|
||||
'login_id' => $this->loginId,
|
||||
'name' => $this->name,
|
||||
'nature' => $this->nature,
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
@@ -1,214 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Attempt.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Attempt
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @deprecated
|
||||
*/
|
||||
class Attempt extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $apiMode;
|
||||
/** @var int */
|
||||
private $apiVersion;
|
||||
/** @var bool */
|
||||
private $automaticFetch;
|
||||
/** @var bool */
|
||||
private $categorize;
|
||||
/** @var Carbon */
|
||||
private $consentGivenAt;
|
||||
/** @var array */
|
||||
private $consentTypes;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var array */
|
||||
private $customFields;
|
||||
/** @var bool */
|
||||
private $dailyRefresh;
|
||||
/** @var string */
|
||||
private $deviceType;
|
||||
/** @var array */
|
||||
private $excludeAccounts;
|
||||
/** @var Carbon */
|
||||
private $failAt;
|
||||
/** @var string */
|
||||
private $failErrorClass;
|
||||
/** @var string */
|
||||
private $failMessage;
|
||||
/** @var array */
|
||||
private $fetchScopes;
|
||||
/** @var bool */
|
||||
private $finished;
|
||||
/** @var bool */
|
||||
private $finishedRecent;
|
||||
/** @var Carbon */
|
||||
private $fromDate;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var bool */
|
||||
private $interactive;
|
||||
/** @var string */
|
||||
private $locale;
|
||||
/** @var bool */
|
||||
private $partial;
|
||||
/** @var string */
|
||||
private $remoteIp;
|
||||
/** @var bool */
|
||||
private $showConsentInformation;
|
||||
/** @var array */
|
||||
private $stages;
|
||||
/** @var bool */
|
||||
private $storeCredentials;
|
||||
/** @var Carbon */
|
||||
private $successAt;
|
||||
/** @var Carbon */
|
||||
private $toDate;
|
||||
/** @var Carbon */
|
||||
private $updatedAt; // undocumented
|
||||
/** @var string */
|
||||
private $userAgent;
|
||||
|
||||
/**
|
||||
* Attempt constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->apiMode = $data['api_mode'];
|
||||
$this->apiVersion = $data['api_version'];
|
||||
$this->automaticFetch = $data['automatic_fetch'];
|
||||
$this->categorize = $data['categorize'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->consentGivenAt = new Carbon($data['consent_given_at']);
|
||||
$this->consentTypes = $data['consent_types'];
|
||||
$this->customFields = $data['custom_fields'];
|
||||
$this->dailyRefresh = $data['daily_refresh'];
|
||||
$this->deviceType = $data['device_type'];
|
||||
$this->userAgent = $data['user_agent'] ?? '';
|
||||
$this->remoteIp = $data['remote_ip'];
|
||||
$this->excludeAccounts = $data['exclude_accounts'];
|
||||
$this->failAt = new Carbon($data['fail_at']);
|
||||
$this->failErrorClass = $data['fail_error_class'];
|
||||
$this->failMessage = $data['fail_message'];
|
||||
$this->fetchScopes = $data['fetch_scopes'];
|
||||
$this->finished = $data['finished'];
|
||||
$this->finishedRecent = $data['finished_recent'];
|
||||
$this->fromDate = new Carbon($data['from_date']);
|
||||
$this->id = $data['id'];
|
||||
$this->interactive = $data['interactive'];
|
||||
$this->locale = $data['locale'];
|
||||
$this->partial = $data['partial'];
|
||||
$this->showConsentInformation = $data['show_consent_confirmation'];
|
||||
$this->stages = $data['stages'] ?? [];
|
||||
$this->storeCredentials = $data['store_credentials'];
|
||||
$this->successAt = new Carbon($data['success_at']);
|
||||
$this->toDate = new Carbon($data['to_date']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getCreatedAt(): Carbon
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getFailAt(): Carbon
|
||||
{
|
||||
return $this->failAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getFailErrorClass(): ?string
|
||||
{
|
||||
return $this->failErrorClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getFailMessage(): ?string
|
||||
{
|
||||
return $this->failMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'api_mode' => $this->apiMode,
|
||||
'api_version' => $this->apiVersion,
|
||||
'automatic_fetch' => $this->automaticFetch,
|
||||
'categorize' => $this->categorize,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'custom_fields' => $this->customFields,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'device_type' => $this->deviceType,
|
||||
'user_agent' => $this->userAgent,
|
||||
'remote_ip' => $this->remoteIp,
|
||||
'exclude_accounts' => $this->excludeAccounts,
|
||||
'fail_at' => $this->failAt->toIso8601String(),
|
||||
'fail_error_class' => $this->failErrorClass,
|
||||
'fail_message' => $this->failMessage,
|
||||
'fetch_scopes' => $this->fetchScopes,
|
||||
'finished' => $this->finished,
|
||||
'finished_recent' => $this->finishedRecent,
|
||||
'from_date' => $this->fromDate->toIso8601String(),
|
||||
'id' => $this->id,
|
||||
'interactive' => $this->interactive,
|
||||
'locale' => $this->locale,
|
||||
'partial' => $this->partial,
|
||||
'show_consent_confirmation' => $this->showConsentInformation,
|
||||
'stages' => $this->stages,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
'success_at' => $this->successAt->toIso8601String(),
|
||||
'to_date' => $this->toDate->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @deprecated
|
||||
*/
|
||||
class Customer extends SpectreObject
|
||||
{
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $identifier;
|
||||
/** @var string */
|
||||
private $secret;
|
||||
|
||||
/**
|
||||
* Customer constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->identifier = $data['identifier'];
|
||||
$this->secret = $data['secret'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
*/
|
||||
public function setIdentifier(string $identifier): void
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $secret
|
||||
*/
|
||||
public function setSecret(string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'identifier' => $this->identifier,
|
||||
'secret' => $this->secret,
|
||||
];
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Holder.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* Class Holder
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class Holder extends SpectreObject
|
||||
{
|
||||
/**
|
||||
* Holder constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Login.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
/**
|
||||
* Class Login
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @deprecated
|
||||
*/
|
||||
class Login extends SpectreObject
|
||||
{
|
||||
/** @var Carbon */
|
||||
private $consentGivenAt;
|
||||
/** @var array */
|
||||
private $consentTypes;
|
||||
/** @var string */
|
||||
private $countryCode;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var int */
|
||||
private $customerId;
|
||||
/** @var bool */
|
||||
private $dailyRefresh;
|
||||
/** @var Holder */
|
||||
private $holderInfo;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var Attempt */
|
||||
private $lastAttempt;
|
||||
/** @var Carbon */
|
||||
private $lastSuccessAt;
|
||||
/** @var Carbon */
|
||||
private $nextRefreshPossibleAt;
|
||||
/** @var string */
|
||||
private $providerCode;
|
||||
/** @var int */
|
||||
private $providerId;
|
||||
/** @var string */
|
||||
private $providerName;
|
||||
/** @var bool */
|
||||
private $showConsentConfirmation;
|
||||
/** @var string */
|
||||
private $status;
|
||||
/** @var bool */
|
||||
private $storeCredentials;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Login constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->consentGivenAt = new Carbon($data['consent_given_at']);
|
||||
$this->consentTypes = $data['consent_types'];
|
||||
$this->countryCode = $data['country_code'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
$this->customerId = $data['customer_id'];
|
||||
$this->dailyRefresh = $data['daily_refresh'];
|
||||
$this->holderInfo = new Holder($data['holder_info']);
|
||||
$this->id = (int)$data['id'];
|
||||
$this->lastAttempt = new Attempt($data['last_attempt']);
|
||||
$this->lastSuccessAt = new Carbon($data['last_success_at']);
|
||||
$this->nextRefreshPossibleAt = new Carbon($data['next_refresh_possible_at']);
|
||||
$this->providerCode = $data['provider_code'];
|
||||
$this->providerId = $data['provider_id'];
|
||||
$this->providerName = $data['provider_name'];
|
||||
$this->showConsentConfirmation = $data['show_consent_confirmation'];
|
||||
$this->status = $data['status'];
|
||||
$this->storeCredentials = $data['store_credentials'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCountryCode(): string
|
||||
{
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attempt
|
||||
*/
|
||||
public function getLastAttempt(): Attempt
|
||||
{
|
||||
return $this->lastAttempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getLastSuccessAt(): Carbon
|
||||
{
|
||||
return $this->lastSuccessAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName(): string
|
||||
{
|
||||
return $this->providerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getUpdatedAt(): Carbon
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'country_code' => $this->countryCode,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
'customer_id' => $this->customerId,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'holder_info' => $this->holderInfo->toArray(),
|
||||
'id' => $this->id,
|
||||
'last_attempt' => $this->lastAttempt->toArray(),
|
||||
'last_success_at' => $this->lastSuccessAt->toIso8601String(),
|
||||
'next_refresh_possible_at' => $this->nextRefreshPossibleAt->toIso8601String(),
|
||||
'provider_code' => $this->providerCode,
|
||||
'provider_id' => $this->providerId,
|
||||
'provider_name' => $this->providerName,
|
||||
'show_consent_confirmation' => $this->showConsentConfirmation,
|
||||
'status' => $this->status,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreObject.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class SpectreObject
|
||||
* @deprecated
|
||||
*/
|
||||
class SpectreObject
|
||||
{
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Token.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class Token
|
||||
* @deprecated
|
||||
*/
|
||||
class Token extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $connectUrl;
|
||||
/** @var Carbon */
|
||||
private $expiresAt;
|
||||
/** @var string */
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* Token constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->token = $data['token'];
|
||||
$this->expiresAt = new Carbon($data['expires_at']);
|
||||
$this->connectUrl = $data['connect_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectUrl(): string
|
||||
{
|
||||
return $this->connectUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getExpiresAt(): Carbon
|
||||
{
|
||||
return $this->expiresAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'connect_url' => $this->connectUrl,
|
||||
'expires_at' => $this->expiresAt->toW3cString(),
|
||||
'token' => $this->token,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@@ -1,227 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Transaction.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*/
|
||||
class Transaction extends SpectreObject
|
||||
{
|
||||
/** @var int */
|
||||
private $accountId;
|
||||
/** @var string */
|
||||
private $amount;
|
||||
/** @var string */
|
||||
private $category;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var string */
|
||||
private $currencyCode;
|
||||
/** @var string */
|
||||
private $description;
|
||||
/** @var bool */
|
||||
private $duplicated;
|
||||
/** @var TransactionExtra */
|
||||
private $extra;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var Carbon */
|
||||
private $madeOn;
|
||||
/** @var string */
|
||||
private $mode;
|
||||
/** @var string */
|
||||
private $status;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Transaction constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->mode = $data['mode'];
|
||||
$this->status = $data['status'];
|
||||
$this->madeOn = new Carbon($data['made_on']);
|
||||
$this->amount = $data['amount'];
|
||||
$this->currencyCode = $data['currency_code'];
|
||||
$this->description = $data['description'];
|
||||
$this->category = $data['category'];
|
||||
$this->duplicated = $data['duplicated'];
|
||||
$this->extra = new TransactionExtra($data['extra'] ?? []);
|
||||
$this->accountId = $data['account_id'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
return (string)$this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory(): string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode(): string
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionExtra|null
|
||||
*/
|
||||
public function getExtra(): ?TransactionExtra
|
||||
{
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHash(): string
|
||||
{
|
||||
$array = [
|
||||
'id' => $this->id,
|
||||
'mode' => $this->mode,
|
||||
'status' => $this->status,
|
||||
'made_on' => $this->madeOn->toIso8601String(),
|
||||
'amount' => $this->amount,
|
||||
'currency_code' => $this->currencyCode,
|
||||
'description' => $this->description,
|
||||
'category' => $this->category,
|
||||
'duplicated' => $this->duplicated,
|
||||
'extra' => $this->extra->toArray(),
|
||||
'account_id' => $this->accountId,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return hash('sha256', json_encode($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getMadeOn(): Carbon
|
||||
{
|
||||
return $this->madeOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMode(): string
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get opposing account data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOpposingAccountData(): array
|
||||
{
|
||||
$data = [
|
||||
'name' => null,
|
||||
'iban' => null,
|
||||
'number' => null,
|
||||
'bic' => null,
|
||||
];
|
||||
$extra = $this->getExtra();
|
||||
if (null !== $extra) {
|
||||
$arr = $extra->toArray();
|
||||
foreach ($arr as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'account_number':
|
||||
$data['number'] = $value;
|
||||
$data['name'] = $data['name'] ?? (string)trans('import.spectre_account_with_number', ['number' => $value]);
|
||||
break;
|
||||
case 'payee':
|
||||
$data['name'] = $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDuplicated(): bool
|
||||
{
|
||||
return $this->duplicated;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,174 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TransactionExtra.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class TransactionExtra
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class TransactionExtra extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $accountBalanceSnapshot;
|
||||
/** @var string */
|
||||
private $accountNumber;
|
||||
/** @var string */
|
||||
private $additional;
|
||||
/** @var string */
|
||||
private $assetAmount;
|
||||
/** @var string */
|
||||
private $assetCode;
|
||||
/** @var string */
|
||||
private $categorizationConfidence;
|
||||
/** @var string */
|
||||
private $checkNumber;
|
||||
/** @var string */
|
||||
private $customerCategoryCode;
|
||||
/** @var string */
|
||||
private $customerCategoryName;
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $information;
|
||||
/** @var string */
|
||||
private $mcc;
|
||||
/** @var string */
|
||||
private $originalAmount;
|
||||
/** @var string */
|
||||
private $originalCategory;
|
||||
/** @var string */
|
||||
private $originalCurrencyCode;
|
||||
/** @var string */
|
||||
private $originalSubCategory;
|
||||
/** @var string */
|
||||
private $payee;
|
||||
/** @var bool */
|
||||
private $possibleDuplicate;
|
||||
/** @var Carbon */
|
||||
private $postingDate;
|
||||
/** @var Carbon */
|
||||
private $postingTime;
|
||||
/** @var string */
|
||||
private $recordNumber;
|
||||
/** @var array */
|
||||
private $tags;
|
||||
/** @var Carbon */
|
||||
private $time;
|
||||
/** @var string */
|
||||
private $type;
|
||||
/** @var string */
|
||||
private $unitPrice;
|
||||
/** @var string */
|
||||
private $units;
|
||||
|
||||
/**
|
||||
* TransactionExtra constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $data['id'] ?? null;
|
||||
$this->recordNumber = $data['record_number'] ?? null;
|
||||
$this->information = $data['information'] ?? null;
|
||||
$this->time = isset($data['time']) ? new Carbon($data['time']) : null;
|
||||
$this->postingDate = isset($data['posting_date']) ? new Carbon($data['posting_date']) : null;
|
||||
$this->postingTime = isset($data['posting_time']) ? new Carbon($data['posting_time']) : null;
|
||||
$this->accountNumber = $data['account_number'] ?? null;
|
||||
$this->originalAmount = $data['original_amount'] ?? null;
|
||||
$this->originalCurrencyCode = $data['original_currency_code'] ?? null;
|
||||
$this->assetCode = $data['asset_code'] ?? null;
|
||||
$this->assetAmount = $data['asset_amount'] ?? null;
|
||||
$this->originalCategory = $data['original_category'] ?? null;
|
||||
$this->originalSubCategory = $data['original_subcategory'] ?? null;
|
||||
$this->customerCategoryCode = $data['customer_category_code'] ?? null;
|
||||
$this->customerCategoryName = $data['customer_category_name'] ?? null;
|
||||
$this->possibleDuplicate = $data['possible_duplicate'] ?? null;
|
||||
$this->tags = $data['tags'] ?? null;
|
||||
$this->mcc = $data['mcc'] ?? null;
|
||||
$this->payee = $data['payee'] ?? null;
|
||||
$this->type = $data['type'] ?? null;
|
||||
$this->checkNumber = $data['check_number'] ?? null;
|
||||
$this->units = $data['units'] ?? null;
|
||||
$this->additional = $data['additional'] ?? null;
|
||||
$this->unitPrice = $data['unit_price'] ?? null;
|
||||
$this->accountBalanceSnapshot = $data['account_balance_snapshot'] ?? null;
|
||||
$this->categorizationConfidence = $data['categorization_confidence'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
||||
$array = [
|
||||
'id' => $this->id,
|
||||
'record_number' => $this->recordNumber,
|
||||
'information' => $this->information,
|
||||
'time' => null === $this->time ? null : $this->time->toIso8601String(),
|
||||
'posting_date' => null === $this->postingDate ? null : $this->postingDate->toIso8601String(),
|
||||
'posting_time' => null === $this->postingTime ? null : $this->postingTime->toIso8601String(),
|
||||
'account_number' => $this->accountNumber,
|
||||
'original_amount' => $this->originalAmount,
|
||||
'original_currency_code' => $this->originalCurrencyCode,
|
||||
'asset_code' => $this->assetCode,
|
||||
'asset_amount' => $this->assetAmount,
|
||||
'original_category' => $this->originalCategory,
|
||||
'original_subcategory' => $this->originalSubCategory,
|
||||
'customer_category_code' => $this->customerCategoryCode,
|
||||
'customer_category_name' => $this->customerCategoryName,
|
||||
'possible_duplicate' => $this->possibleDuplicate,
|
||||
'tags' => $this->tags,
|
||||
'mcc' => $this->mcc,
|
||||
'payee' => $this->payee,
|
||||
'type' => $this->type,
|
||||
'check_number' => $this->checkNumber,
|
||||
'units' => $this->units,
|
||||
'additional' => $this->additional,
|
||||
'unit_price' => $this->unitPrice,
|
||||
'account_balance_snapshot' => $this->accountBalanceSnapshot,
|
||||
'categorization_confidence' => $this->categorizationConfidence,
|
||||
];
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateTokenRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Token;
|
||||
|
||||
|
||||
/**
|
||||
* Class CreateTokenRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class CreateTokenRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
private $customer;
|
||||
|
||||
/** @var Token */
|
||||
private $token;
|
||||
|
||||
/** @var string */
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
// add mandatory fields to login object
|
||||
$data = [
|
||||
'data' => [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'fetch_scopes' => ['accounts', 'transactions'],
|
||||
'daily_refresh' => true,
|
||||
'include_fake_providers' => true,
|
||||
'show_consent_confirmation' => true,
|
||||
'credentials_strategy' => 'ask',
|
||||
'return_to' => $this->uri,
|
||||
],
|
||||
];
|
||||
$uri = '/api/v4/tokens/create';
|
||||
$response = $this->sendSignedSpectrePost($uri, $data);
|
||||
$this->token = new Token($response['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Token
|
||||
*/
|
||||
public function getToken(): Token
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer): void
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
*/
|
||||
public function setUri(string $uri): void
|
||||
{
|
||||
$this->uri = $uri;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListAccountsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListAccountsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListAccountsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $accounts = [];
|
||||
/** @var Login */
|
||||
private $login;
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListAccountsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'login_id' => $this->login->getId()];
|
||||
$uri = '/api/v4/accounts?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $accountArray) {
|
||||
$this->accounts[] = new Account($accountArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAccounts(): array
|
||||
{
|
||||
return $this->accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Login $login
|
||||
*/
|
||||
public function setLogin(Login $login): void
|
||||
{
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListCustomersRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class ListCustomersRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListCustomersRequest extends SpectreRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $customers = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListCustomersRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId];
|
||||
$uri = '/api/v4/customers/?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $customerArray) {
|
||||
$this->customers[] = new Customer($customerArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomers(): array
|
||||
{
|
||||
return $this->customers;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListLoginsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListLoginsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListLoginsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
private $customer;
|
||||
|
||||
/** @var array */
|
||||
private $logins = [];
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListLoginsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'customer_id' => $this->customer->getId()];
|
||||
$uri = '/api/v4/logins/?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
$collection = new Collection;
|
||||
// store logins:
|
||||
/** @var array $loginArray */
|
||||
foreach ($response['data'] as $loginArray) {
|
||||
$collection->push(new Login($loginArray));
|
||||
}
|
||||
// sort logins by date created:
|
||||
$sorted = $collection->sortByDesc(
|
||||
static function (Login $login) {
|
||||
return $login->getUpdatedAt()->timestamp;
|
||||
}
|
||||
);
|
||||
$this->logins = $sorted->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLogins(): array
|
||||
{
|
||||
return $this->logins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer): void
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListTransactionsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Transaction;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListTransactionsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListTransactionsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Account */
|
||||
private $account;
|
||||
/** @var array */
|
||||
private $transactions = [];
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListTransactionsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'account_id' => $this->account->getId()];
|
||||
$uri = '/api/v4/transactions?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $transactionArray) {
|
||||
$this->transactions[] = new Transaction($transactionArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(): array
|
||||
{
|
||||
return $this->transactions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
public function setAccount(Account $account): void
|
||||
{
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* NewCustomerRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NewCustomerRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class NewCustomerRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$data = [
|
||||
'data' => [
|
||||
'identifier' => 'default_ff3_customer',
|
||||
],
|
||||
];
|
||||
$uri = '/api/v4/customers/';
|
||||
Log::debug(sprintf('Going to call %s with info:', $uri), $data);
|
||||
$response = $this->sendSignedSpectrePost($uri, $data);
|
||||
// create customer:
|
||||
$this->customer = new Customer($response['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer(): Customer
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
}
|
@@ -1,308 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\User;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class SpectreRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
abstract class SpectreRequest
|
||||
{
|
||||
/** @var int */
|
||||
protected $expiresAt = 0;
|
||||
/** @var string */
|
||||
private $appId;
|
||||
/** @var string */
|
||||
private $privateKey;
|
||||
/** @var string */
|
||||
private $secret;
|
||||
/** @var string */
|
||||
private $server;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract public function call(): void;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getAppId(): string
|
||||
{
|
||||
return $this->appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $appId
|
||||
*/
|
||||
public function setAppId(string $appId): void
|
||||
{
|
||||
$this->appId = $appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $secret
|
||||
*/
|
||||
public function setSecret(string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getServer(): string
|
||||
{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $privateKey
|
||||
*/
|
||||
public function setPrivateKey(string $privateKey): void
|
||||
{
|
||||
$this->privateKey = $privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->server = 'https://' . config('import.options.spectre.server');
|
||||
$this->expiresAt = time() + 180;
|
||||
$privateKey = app('preferences')->getForUser($user, 'spectre_private_key', null);
|
||||
$this->privateKey = $privateKey->data;
|
||||
|
||||
// set client ID
|
||||
$appId = app('preferences')->getForUser($user, 'spectre_app_id', null);
|
||||
if (null !== $appId && '' !== (string)$appId->data) {
|
||||
$this->appId = $appId->data;
|
||||
}
|
||||
|
||||
// set service secret
|
||||
$secret = app('preferences')->getForUser($user, 'spectre_secret', null);
|
||||
if (null !== $secret && '' !== (string)$secret->data) {
|
||||
$this->secret = $secret->data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $uri
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function generateSignature(string $method, string $uri, string $data): string
|
||||
{
|
||||
if ('' === $this->privateKey) {
|
||||
throw new FireflyException('No private key present.');
|
||||
}
|
||||
$method = strtolower($method);
|
||||
if ('get' === $method || 'delete' === $method) {
|
||||
$data = '';
|
||||
}
|
||||
$toSign = $this->expiresAt . '|' . strtoupper($method) . '|' . $uri . '|' . $data . ''; // no file so no content there.
|
||||
Log::debug(sprintf('String to sign: "%s"', $toSign));
|
||||
$signature = '';
|
||||
|
||||
// Sign the data
|
||||
openssl_sign($toSign, $signature, $this->privateKey, OPENSSL_ALGO_SHA256);
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultHeaders(): array
|
||||
{
|
||||
$userAgent = sprintf('FireflyIII v%s', config('firefly.version'));
|
||||
|
||||
return [
|
||||
'App-id' => $this->getAppId(),
|
||||
'Secret' => $this->getSecret(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-type' => 'application/json',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'User-Agent' => $userAgent,
|
||||
'Expires-at' => $this->expiresAt,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function sendSignedSpectreGet(string $uri, array $data): array
|
||||
{
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$sendBody = json_encode($data); // OK
|
||||
$fullUri = $this->server . $uri;
|
||||
$signature = $this->generateSignature('get', $fullUri, $sendBody);
|
||||
$headers['Signature'] = $signature;
|
||||
|
||||
Log::debug('Final headers for spectre signed get request:', $headers);
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('GET', $fullUri, ['headers' => $headers]);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Guzzle Exception: %s', $e->getMessage()));
|
||||
}
|
||||
$statusCode = $res->getStatusCode();
|
||||
try {
|
||||
$returnBody = $res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::GET result: %s', $e->getMessage()));
|
||||
$returnBody = '';
|
||||
}
|
||||
$this->detectError($returnBody, $statusCode);
|
||||
|
||||
$array = json_decode($returnBody, true);
|
||||
$responseHeaders = $res->getHeaders();
|
||||
$array['ResponseHeaders'] = $responseHeaders;
|
||||
$array['ResponseStatusCode'] = $statusCode;
|
||||
|
||||
if (isset($array['error_class'])) {
|
||||
$message = $array['error_message'] ?? '(no message)';
|
||||
throw new FireflyException(sprintf('Error of class %s: %s', $array['error_class'], $message));
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function sendSignedSpectrePost(string $uri, array $data): array
|
||||
{
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$body = json_encode($data);
|
||||
$fullUri = $this->server . $uri;
|
||||
$signature = $this->generateSignature('post', $fullUri, $body);
|
||||
$headers['Signature'] = $signature;
|
||||
|
||||
Log::debug('Final headers for spectre signed POST request:', $headers);
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('POST', $fullUri, ['headers' => $headers, 'body' => $body]);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Guzzle Exception: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
$body = $res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
|
||||
$body = '';
|
||||
}
|
||||
|
||||
$statusCode = $res->getStatusCode();
|
||||
$this->detectError($body, $statusCode);
|
||||
|
||||
$array = json_decode($body, true);
|
||||
$responseHeaders = $res->getHeaders();
|
||||
$array['ResponseHeaders'] = $responseHeaders;
|
||||
$array['ResponseStatusCode'] = $statusCode;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $body
|
||||
*
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function detectError(string $body, int $statusCode): void
|
||||
{
|
||||
$array = json_decode($body, true);
|
||||
if (isset($array['error_class'])) {
|
||||
$message = $array['error_message'] ?? '(no message)';
|
||||
$errorClass = $array['error_class'];
|
||||
$class = sprintf('\\FireflyIII\\Services\\Spectre\Exception\\%sException', $errorClass);
|
||||
if (class_exists($class)) {
|
||||
throw new $class($message);
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message));
|
||||
}
|
||||
|
||||
if (200 !== $statusCode) {
|
||||
throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $body));
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user