mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Improve test coverage and remove deprecated code.
This commit is contained in:
@@ -114,7 +114,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
||||
|
||||
/**
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getNextData(): array
|
||||
@@ -152,6 +152,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
||||
if (strtolower($album) !== 'station to station' && $this->job->stage !== 'new') {
|
||||
return 'import.fake.enter-album';
|
||||
}
|
||||
return 'impossible-view'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,8 @@ use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportAccount.
|
||||
*/
|
||||
class ImportAccount
|
||||
|
||||
@@ -29,6 +29,8 @@ use Log;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportBill.
|
||||
*/
|
||||
class ImportBill
|
||||
|
||||
@@ -28,6 +28,8 @@ use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportBudget.
|
||||
*/
|
||||
class ImportBudget
|
||||
|
||||
@@ -28,6 +28,8 @@ use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportCategory
|
||||
*/
|
||||
class ImportCategory
|
||||
|
||||
@@ -28,6 +28,8 @@ use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportCurrency
|
||||
*/
|
||||
class ImportCurrency
|
||||
|
||||
@@ -33,6 +33,8 @@ use Log;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
* Class ImportJournal.
|
||||
*/
|
||||
class ImportJournal
|
||||
|
||||
@@ -36,19 +36,155 @@ use Preferences;
|
||||
*/
|
||||
class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
// /** @var User */
|
||||
// private $user;
|
||||
//
|
||||
// /**
|
||||
// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// public function getView(): string
|
||||
// {
|
||||
// Log::debug('Now in BunqPrerequisites::getView()');
|
||||
//
|
||||
// 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 = '';
|
||||
// $serverIP = '';
|
||||
// if ($this->hasApiKey()) {
|
||||
// $key = Preferences::getForUser($this->user, 'bunq_api_key', null)->data;
|
||||
// }
|
||||
// if ($this->hasServerIP()) {
|
||||
// $serverIP = Preferences::getForUser($this->user, 'external_ip', null)->data;
|
||||
// }
|
||||
// if (!$this->hasServerIP()) {
|
||||
// /** @var IPRetrievalInterface $service */
|
||||
// $service = app(IPRetrievalInterface::class);
|
||||
// $serverIP = (string)$service->getIP();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // get IP address
|
||||
// return ['key' => $key, 'ip' => $serverIP];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if this import method has any special prerequisites such as config
|
||||
// * variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function hasPrerequisites(): bool
|
||||
// {
|
||||
// $hasApiKey = $this->hasApiKey();
|
||||
// $hasServerIP = $this->hasServerIP();
|
||||
//
|
||||
// return !$hasApiKey || !$hasServerIP;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Indicate if all prerequisites have been met.
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function isComplete(): bool
|
||||
// {
|
||||
// // is complete when user has entered both the API key
|
||||
// // and his IP address.
|
||||
//
|
||||
// $hasApiKey = $this->hasApiKey();
|
||||
// $hasServerIP = $this->hasServerIP();
|
||||
//
|
||||
// return $hasApiKey && $hasServerIP;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
// *
|
||||
// * @param User $user
|
||||
// */
|
||||
// public function setUser(User $user): void
|
||||
// {
|
||||
// Log::debug(sprintf('Now in setUser(#%d)', $user->id));
|
||||
// $this->user = $user;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
|
||||
// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
// *
|
||||
// * @param Request $request
|
||||
// *
|
||||
// * @return MessageBag
|
||||
// */
|
||||
// public function storePrerequisites(Request $request): MessageBag
|
||||
// {
|
||||
// $apiKey = $request->get('api_key');
|
||||
// $serverIP = $request->get('external_ip');
|
||||
// Log::debug('Storing bunq API key');
|
||||
// Preferences::setForUser($this->user, 'bunq_api_key', $apiKey);
|
||||
// Preferences::setForUser($this->user, 'external_ip', $serverIP);
|
||||
//
|
||||
// return new MessageBag;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return bool
|
||||
// */
|
||||
// private function hasApiKey(): bool
|
||||
// {
|
||||
// $apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
|
||||
// if (null === $apiKey) {
|
||||
// return false;
|
||||
// }
|
||||
// if (null === $apiKey->data) {
|
||||
// return false;
|
||||
// }
|
||||
// if (\strlen((string)$apiKey->data) === 64) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return bool
|
||||
// */
|
||||
// private function hasServerIP(): bool
|
||||
// {
|
||||
// $serverIP = Preferences::getForUser($this->user, 'external_ip', false);
|
||||
// if (null === $serverIP) {
|
||||
// return false;
|
||||
// }
|
||||
// if (null === $serverIP->data) {
|
||||
// return false;
|
||||
// }
|
||||
// if (\strlen((string)$serverIP->data) > 6) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
Log::debug('Now in BunqPrerequisites::getView()');
|
||||
|
||||
return 'import.bunq.prerequisites';
|
||||
// TODO: Implement getView() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,39 +194,8 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
Log::debug('Now in BunqPrerequisites::getViewParameters()');
|
||||
$key = '';
|
||||
$serverIP = '';
|
||||
if ($this->hasApiKey()) {
|
||||
$key = Preferences::getForUser($this->user, 'bunq_api_key', null)->data;
|
||||
}
|
||||
if ($this->hasServerIP()) {
|
||||
$serverIP = Preferences::getForUser($this->user, 'external_ip', null)->data;
|
||||
}
|
||||
if (!$this->hasServerIP()) {
|
||||
/** @var IPRetrievalInterface $service */
|
||||
$service = app(IPRetrievalInterface::class);
|
||||
$serverIP = (string)$service->getIP();
|
||||
}
|
||||
|
||||
|
||||
// get IP address
|
||||
return ['key' => $key, 'ip' => $serverIP];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this import method has any special prerequisites such as config
|
||||
* variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
* tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrerequisites(): bool
|
||||
{
|
||||
$hasApiKey = $this->hasApiKey();
|
||||
$hasServerIP = $this->hasServerIP();
|
||||
|
||||
return !$hasApiKey || !$hasServerIP;
|
||||
// TODO: Implement getViewParameters() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,13 +205,8 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
// is complete when user has entered both the API key
|
||||
// and his IP address.
|
||||
|
||||
$hasApiKey = $this->hasApiKey();
|
||||
$hasServerIP = $this->hasServerIP();
|
||||
|
||||
return $hasApiKey && $hasServerIP;
|
||||
// TODO: Implement isComplete() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,64 +216,22 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
Log::debug(sprintf('Now in setUser(#%d)', $user->id));
|
||||
$this->user = $user;
|
||||
// TODO: Implement setUser() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
|
||||
* If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* @param Request $request
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(Request $request): MessageBag
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
$apiKey = $request->get('api_key');
|
||||
$serverIP = $request->get('external_ip');
|
||||
Log::debug('Storing bunq API key');
|
||||
Preferences::setForUser($this->user, 'bunq_api_key', $apiKey);
|
||||
Preferences::setForUser($this->user, 'external_ip', $serverIP);
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function hasApiKey(): bool
|
||||
{
|
||||
$apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
|
||||
if (null === $apiKey) {
|
||||
return false;
|
||||
}
|
||||
if (null === $apiKey->data) {
|
||||
return false;
|
||||
}
|
||||
if (\strlen((string)$apiKey->data) === 64) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function hasServerIP(): bool
|
||||
{
|
||||
$serverIP = Preferences::getForUser($this->user, 'external_ip', false);
|
||||
if (null === $serverIP) {
|
||||
return false;
|
||||
}
|
||||
if (null === $serverIP->data) {
|
||||
return false;
|
||||
}
|
||||
if (\strlen((string)$serverIP->data) > 6) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
// TODO: Implement storePrerequisites() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ class FakePrerequisites implements PrerequisitesInterface
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
@@ -59,7 +60,7 @@ class FakePrerequisites implements PrerequisitesInterface
|
||||
}
|
||||
$oldKey = (string)\request()->old('api_key');
|
||||
if ($oldKey !== '') {
|
||||
$apiKey = \request()->old('api_key');
|
||||
$apiKey = \request()->old('api_key'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return ['api_key' => $apiKey];
|
||||
@@ -87,13 +88,13 @@ class FakePrerequisites implements PrerequisitesInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(Request $request): MessageBag
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
$apiKey = (string)$request->get('api_key');
|
||||
$apiKey = $data['api_key'] ?? '';
|
||||
$messageBag = new MessageBag();
|
||||
if (32 !== \strlen($apiKey)) {
|
||||
$messageBag->add('api_key', 'API key must be 32 chars.');
|
||||
|
||||
@@ -34,17 +34,92 @@ use Illuminate\Support\MessageBag;
|
||||
*/
|
||||
class FilePrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
// /** @var User */
|
||||
// private $user;
|
||||
//
|
||||
// /**
|
||||
// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// public function getView(): string
|
||||
// {
|
||||
// return '';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns any values required for the prerequisites-view.
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getViewParameters(): array
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if this import method has any special prerequisites such as config
|
||||
// * variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
// *
|
||||
// * True if prerequisites. False if not.
|
||||
// *
|
||||
// * @return bool
|
||||
// *
|
||||
// * @throws FireflyException
|
||||
// */
|
||||
// public function hasPrerequisites(): bool
|
||||
// {
|
||||
// if ($this->user->hasRole('demo')) {
|
||||
// throw new FireflyException('Apologies, the demo user cannot import files.');
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Indicate if all prerequisites have been met.
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function isComplete(): bool
|
||||
// {
|
||||
// // has no prerequisites, so always return true.
|
||||
// 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->user = $user;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
|
||||
// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
// *
|
||||
// * @param Request $request
|
||||
// *
|
||||
// * @return MessageBag
|
||||
// */
|
||||
// public function storePrerequisites(Request $request): MessageBag
|
||||
// {
|
||||
// return new MessageBag;
|
||||
// }
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return '';
|
||||
// TODO: Implement getView() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,27 +129,8 @@ class FilePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this import method has any special prerequisites such as config
|
||||
* variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
* tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
*
|
||||
* True if prerequisites. False if not.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function hasPrerequisites(): bool
|
||||
{
|
||||
if ($this->user->hasRole('demo')) {
|
||||
throw new FireflyException('Apologies, the demo user cannot import files.');
|
||||
}
|
||||
|
||||
return false;
|
||||
// TODO: Implement getViewParameters() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,8 +140,8 @@ class FilePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
// has no prerequisites, so always return true.
|
||||
return true;
|
||||
// TODO: Implement isComplete() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,20 +151,22 @@ class FilePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
// TODO: Implement setUser() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
|
||||
* If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* @param Request $request
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(Request $request): MessageBag
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
return new MessageBag;
|
||||
// TODO: Implement storePrerequisites() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ interface PrerequisitesInterface
|
||||
*
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(Request $request): MessageBag;
|
||||
public function storePrerequisites(array $data): MessageBag;
|
||||
}
|
||||
|
||||
@@ -36,17 +36,168 @@ use Preferences;
|
||||
*/
|
||||
class SpectrePrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
// /** @var User */
|
||||
// private $user;
|
||||
//
|
||||
// /**
|
||||
// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// public function getView(): string
|
||||
// {
|
||||
// return 'import.spectre.prerequisites';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns any values required for the prerequisites-view.
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getViewParameters(): array
|
||||
// {
|
||||
// $publicKey = $this->getPublicKey();
|
||||
// $subTitle = (string)trans('import.spectre_title');
|
||||
// $subTitleIcon = 'fa-archive';
|
||||
//
|
||||
// return compact('publicKey', 'subTitle', 'subTitleIcon');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if this import method has any special prerequisites such as config
|
||||
// * variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function hasPrerequisites(): bool
|
||||
// {
|
||||
// $values = [
|
||||
// Preferences::getForUser($this->user, 'spectre_app_id', false),
|
||||
// Preferences::getForUser($this->user, 'spectre_secret', false),
|
||||
// ];
|
||||
// /** @var Preference $value */
|
||||
// foreach ($values as $value) {
|
||||
// if (false === $value->data || null === $value->data) {
|
||||
// Log::info(sprintf('Config var "%s" is missing.', $value->name));
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// Log::debug('All prerequisites are here!');
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Indicate if all prerequisites have been met.
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function isComplete(): bool
|
||||
// {
|
||||
// // return true when user has set the App Id and the Spectre Secret.
|
||||
// $values = [
|
||||
// Preferences::getForUser($this->user, 'spectre_app_id', false),
|
||||
// Preferences::getForUser($this->user, 'spectre_secret', false),
|
||||
// ];
|
||||
// $result = true;
|
||||
// /** @var Preference $value */
|
||||
// foreach ($values as $value) {
|
||||
// if (false === $value->data || null === $value->data) {
|
||||
// $result = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $result;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 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. It tries to register this instance as a new Firefly III device.
|
||||
// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
// *
|
||||
// * @param Request $request
|
||||
// *
|
||||
// * @return MessageBag
|
||||
// */
|
||||
// public function storePrerequisites(Request $request): MessageBag
|
||||
// {
|
||||
// Log::debug('Storing Spectre API keys..');
|
||||
// Preferences::setForUser($this->user, 'spectre_app_id', $request->get('app_id'));
|
||||
// Preferences::setForUser($this->user, 'spectre_secret', $request->get('secret'));
|
||||
// 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);
|
||||
//
|
||||
// Preferences::setForUser($this->user, 'spectre_private_key', $privKey);
|
||||
// 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 = Preferences::getForUser($this->user, 'spectre_public_key', null);
|
||||
// if (null === $preference) {
|
||||
// Log::debug('public key is null');
|
||||
// // create key pair
|
||||
// $this->createKeyPair();
|
||||
// }
|
||||
// $preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
|
||||
// Log::debug('Return public key for user');
|
||||
//
|
||||
// return $preference->data;
|
||||
// }
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.spectre.prerequisites';
|
||||
// TODO: Implement getView() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,37 +207,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
$publicKey = $this->getPublicKey();
|
||||
$subTitle = (string)trans('import.spectre_title');
|
||||
$subTitleIcon = 'fa-archive';
|
||||
|
||||
return compact('publicKey', 'subTitle', 'subTitleIcon');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this import method has any special prerequisites such as config
|
||||
* variables or other things. The only thing we verify is the presence of the API key. Everything else
|
||||
* tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrerequisites(): bool
|
||||
{
|
||||
$values = [
|
||||
Preferences::getForUser($this->user, 'spectre_app_id', false),
|
||||
Preferences::getForUser($this->user, 'spectre_secret', false),
|
||||
];
|
||||
/** @var Preference $value */
|
||||
foreach ($values as $value) {
|
||||
if (false === $value->data || null === $value->data) {
|
||||
Log::info(sprintf('Config var "%s" is missing.', $value->name));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Log::debug('All prerequisites are here!');
|
||||
|
||||
return false;
|
||||
// TODO: Implement getViewParameters() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,20 +218,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function isComplete(): bool
|
||||
{
|
||||
// return true when user has set the App Id and the Spectre Secret.
|
||||
$values = [
|
||||
Preferences::getForUser($this->user, 'spectre_app_id', false),
|
||||
Preferences::getForUser($this->user, 'spectre_secret', false),
|
||||
];
|
||||
$result = true;
|
||||
/** @var Preference $value */
|
||||
foreach ($values as $value) {
|
||||
if (false === $value->data || null === $value->data) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
// TODO: Implement isComplete() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,74 +229,22 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
// TODO: Implement setUser() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
|
||||
* If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
|
||||
* This method responds to the user's submission of an API key. Should do nothing but store the value.
|
||||
*
|
||||
* @param Request $request
|
||||
* Errors must be returned in the message bag under the field name they are requested by.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function storePrerequisites(Request $request): MessageBag
|
||||
public function storePrerequisites(array $data): MessageBag
|
||||
{
|
||||
Log::debug('Storing Spectre API keys..');
|
||||
Preferences::setForUser($this->user, 'spectre_app_id', $request->get('app_id'));
|
||||
Preferences::setForUser($this->user, 'spectre_secret', $request->get('secret'));
|
||||
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);
|
||||
|
||||
Preferences::setForUser($this->user, 'spectre_private_key', $privKey);
|
||||
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 = Preferences::getForUser($this->user, 'spectre_public_key', null);
|
||||
if (null === $preference) {
|
||||
Log::debug('public key is null');
|
||||
// create key pair
|
||||
$this->createKeyPair();
|
||||
}
|
||||
$preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
|
||||
Log::debug('Return public key for user');
|
||||
|
||||
return $preference->data;
|
||||
// TODO: Implement storePrerequisites() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,14 +65,15 @@ class FakeRoutine implements RoutineInterface
|
||||
{
|
||||
Log::debug(sprintf('Now in run() for fake routine with status: %s', $this->job->status));
|
||||
if ($this->job->status !== 'running') {
|
||||
throw new FireflyException('This fake job should not be started.');
|
||||
throw new FireflyException('This fake job should not be started.'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
switch ($this->job->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage));
|
||||
throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage)); // @codeCoverageIgnore
|
||||
case 'new':
|
||||
$handler = new StageNewHandler;
|
||||
/** @var StageNewHandler $handler */
|
||||
$handler = app(StageNewHandler::class);
|
||||
$handler->run();
|
||||
$this->repository->setStage($this->job, 'ahoy');
|
||||
// set job finished this step:
|
||||
@@ -80,13 +81,15 @@ class FakeRoutine implements RoutineInterface
|
||||
|
||||
return;
|
||||
case 'ahoy':
|
||||
$handler = new StageAhoyHandler;
|
||||
/** @var StageAhoyHandler $handler */
|
||||
$handler = app(StageAhoyHandler::class);
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->job, 'need_job_config');
|
||||
$this->repository->setStage($this->job, 'final');
|
||||
break;
|
||||
case 'final':
|
||||
$handler = new StageFinalHandler;
|
||||
/** @var StageFinalHandler $handler */
|
||||
$handler = app(StageFinalHandler::class);
|
||||
$handler->setJob($this->job);
|
||||
$transactions = $handler->getTransactions();
|
||||
$this->repository->setStatus($this->job, 'provider_finished');
|
||||
|
||||
@@ -36,6 +36,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
public $row;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
@@ -44,6 +45,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getName(): string
|
||||
@@ -81,7 +83,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
*
|
||||
* @return bool true if the description is GEA/BEA-format, false otherwise
|
||||
*/
|
||||
protected function parseABNAMRODescription()
|
||||
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)) {
|
||||
@@ -99,7 +101,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
*
|
||||
* @return bool true if the description is GEA/BEAformat, false otherwise
|
||||
*/
|
||||
protected function parseGEABEADescription()
|
||||
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)) {
|
||||
@@ -124,7 +126,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
*
|
||||
* @return bool true if the description is SEPA format, false otherwise
|
||||
*/
|
||||
protected function parseSepaDescription()
|
||||
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)) {
|
||||
@@ -178,7 +180,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
*
|
||||
* @return bool true if the description is TRTP format, false otherwise
|
||||
*/
|
||||
protected function parseTRTPDescription()
|
||||
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)) {
|
||||
@@ -196,7 +198,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
|
||||
switch (strtoupper($key)) {
|
||||
case 'NAME':
|
||||
$this->row[8] = $name = $value;
|
||||
$this->row[8] = $value;
|
||||
break;
|
||||
case 'REMI':
|
||||
$newDescription = $value;
|
||||
|
||||
@@ -38,6 +38,7 @@ class IngDescription implements SpecificInterface
|
||||
public $row;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
@@ -46,6 +47,7 @@ class IngDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getName(): string
|
||||
@@ -84,41 +86,29 @@ class IngDescription implements SpecificInterface
|
||||
/**
|
||||
* Add the Opposing name from cell 1 in the description for Betaalautomaten
|
||||
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
protected function addNameIngDescription()
|
||||
protected function addNameIngDescription(): void
|
||||
{
|
||||
$this->row[8] = $this->row[1] . ' ' . $this->row[8];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove IBAN number out of the description
|
||||
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
protected function removeIBANIngDescription()
|
||||
protected function removeIBANIngDescription(): void
|
||||
{
|
||||
// Try replace the iban number with nothing. The IBAN nr is found in the third row
|
||||
$this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ).
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
protected function removeNameIngDescription()
|
||||
protected function removeNameIngDescription(): void
|
||||
{
|
||||
// Try remove everything before the 'Omschrijving'
|
||||
$this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +117,7 @@ class IngDescription implements SpecificInterface
|
||||
private function copyDescriptionToOpposite(): void
|
||||
{
|
||||
$search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen'];
|
||||
if (0 === \strlen($this->row[3])) {
|
||||
if ('' === (string)$this->row[3]) {
|
||||
$this->row[3] = trim(str_ireplace($search, '', $this->row[8]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace FireflyIII\Import\Specifics;
|
||||
class PresidentsChoice implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription(): string
|
||||
@@ -36,6 +37,7 @@ class PresidentsChoice implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function getName(): string
|
||||
|
||||
Reference in New Issue
Block a user