mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Extended the validator and created more code to handle exceptions.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
@@ -12,7 +12,6 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Log;
|
||||
@@ -58,13 +57,25 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
||||
if (!is_null($account->id)) {
|
||||
Log::debug('Found account by name', ['id' => $account->id]);
|
||||
$this->setCertainty(50);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
// try to find by the name we would give it:
|
||||
$accountName = 'Asset account with number ' . e($value);
|
||||
$account = $repository->findByName($accountName, [AccountType::ASSET]);
|
||||
if (!is_null($account->id)) {
|
||||
Log::debug('Found account by name', ['id' => $account->id]);
|
||||
$this->setCertainty(50);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
$account = $repository->store(
|
||||
['name' => 'Account with number ' . $value, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'asset',
|
||||
'virtualBalance' => 0, 'active' => true]
|
||||
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
||||
);
|
||||
$this->setCertainty(100);
|
||||
|
||||
|
37
app/Import/Converter/ExternalId.php
Normal file
37
app/Import/Converter/ExternalId.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* ExternalId.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
/**
|
||||
* Class ExternalId
|
||||
*
|
||||
* @package FireflyIII\Import\Converter
|
||||
*/
|
||||
class ExternalId extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
// this should replace all control characters
|
||||
// but leave utf8 intact:
|
||||
$value = preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', $value);
|
||||
$this->setCertainty(100);
|
||||
|
||||
return strval(trim($value));
|
||||
|
||||
}
|
||||
}
|
@@ -14,6 +14,7 @@ namespace FireflyIII\Import\Converter;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -61,13 +62,23 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
// try to find by the name we would give it:
|
||||
$accountName = 'Import account with number ' . e($value);
|
||||
$account = $repository->findByName($accountName, [AccountType::IMPORT]);
|
||||
if (!is_null($account->id)) {
|
||||
Log::debug('Found account by name', ['id' => $account->id]);
|
||||
$this->setCertainty(50);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
$account = $repository->store(
|
||||
['name' => 'Account with number ' . $value, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'asset',
|
||||
'virtualBalance' => 0, 'active' => true]
|
||||
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
||||
'accountType' => 'import',
|
||||
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
||||
);
|
||||
$this->setCertainty(100);
|
||||
|
||||
return $account;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user