Remove and cleanup commands.

This commit is contained in:
James Cole 2020-05-24 12:17:53 +02:00
parent b8668b44a0
commit bc70174f44
39 changed files with 5 additions and 322 deletions

View File

@ -83,8 +83,6 @@ class CorrectDatabase extends Command
echo $result;
}
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -77,8 +77,6 @@ class CorrectOpeningBalanceCurrencies extends Command
$this->info('There was nothing to fix in the opening balance transactions.');
}
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -78,8 +78,6 @@ class CreateAccessTokens extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verify access tokens in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -79,8 +79,6 @@ class CreateLinkTypes extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified link types in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -76,8 +76,6 @@ class DeleteEmptyGroups extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty groups in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -58,8 +58,6 @@ class DeleteEmptyJournals extends Command
$this->deleteUnevenJournals();
$this->deleteEmptyJournals();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -62,7 +62,6 @@ class DeleteOrphanedTransactions extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified orphans in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -78,8 +78,6 @@ class DeleteZeroAmount extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified zero-amount integrity in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -101,8 +101,6 @@ class EnableCurrencies extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified currencies in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -106,7 +106,6 @@ class FixAccountTypes extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verifying account types took %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -75,7 +75,6 @@ class FixLongDescriptions extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified all transaction group and journal title lengths in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -98,7 +98,6 @@ class FixPiggies extends Command
$end = round(microtime(true) - $start, 2);
$this->line(sprintf('Verified the content of %d piggy bank events in %s seconds.', $set->count(), $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -67,7 +67,6 @@ class FixRecurringTransactions extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Corrected recurring transactions %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -75,7 +75,6 @@ class FixUnevenAmount extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified amount integrity in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -71,7 +71,6 @@ class RemoveBills extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified bills / journals in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -83,7 +83,6 @@ class RenameMetaFields extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Renamed meta fields in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -74,7 +74,6 @@ class TransferBudgets extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified budget/journals in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -123,7 +123,6 @@ class DecryptDatabase extends Command
}
$this->info('Done!');
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -63,279 +63,14 @@ class CreateCSVImport extends Command
{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.}';
/** @var ImportJob */
private $importJob;
/** @var ImportJobRepositoryInterface */
private $importRepository;
/** @var UserRepositoryInterface */
private $userRepository;
/**
* Run the command.
*/
public function handle(): int
{
$this->stupidLaravel();
// @codeCoverageIgnoreStart
if (!$this->verifyAccessToken()) {
$this->errorLine('Invalid access token.');
return 1;
}
if (!$this->validArguments()) {
$this->errorLine('Invalid arguments.');
return 1;
}
// @codeCoverageIgnoreEnd
/** @var User $user */
$user = $this->userRepository->findNull((int) $this->option('user'));
$file = (string) $this->argument('file');
$configuration = (string) $this->argument('configuration');
$this->importRepository->setUser($user);
$configurationData = json_decode(file_get_contents($configuration), true, 512, JSON_THROW_ON_ERROR);
$this->importJob = $this->importRepository->create('file');
// inform user (and log it)
$this->infoLine(sprintf('Import file : %s', $file));
$this->infoLine(sprintf('Configuration file : %s', $configuration));
$this->infoLine(sprintf('User : #%d (%s)', $user->id, $user->email));
$this->infoLine(sprintf('Job : %s', $this->importJob->key));
try {
$this->storeFile($file);
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
return 1;
}
// job is ready to go
$this->importRepository->setConfiguration($this->importJob, $configurationData);
$this->importRepository->setStatus($this->importJob, 'ready_to_run');
$this->infoLine('The import routine has started. The process is not visible. Please wait.');
Log::debug('Go for import!');
// keep repeating this call until job lands on "provider_finished"
try {
$this->processFile();
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
app('telemetry')->feature('system.command.errored', $this->signature);
return 1;
}
// then store data:
try {
$this->storeData();
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
app('telemetry')->feature('system.command.errored', $this->signature);
return 1;
}
// give feedback:
$this->giveFeedback();
// clear cache for user:
app('preferences')->setForUser($user, 'lastActivity', microtime());
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
$this->error('This command is disabled.');
return 1;
}
/**
* @param string $message
* @param array|null $data
*
* @codeCoverageIgnore
*/
private function errorLine(string $message, array $data = null): void
{
Log::error($message, $data ?? []);
$this->error($message);
}
/**
*
*/
private function giveFeedback(): void
{
$this->infoLine('Job has finished.');
if (null !== $this->importJob->tag) {
$this->infoLine(sprintf('%d transaction(s) have been imported.', $this->importJob->tag->transactionJournals->count()));
$this->infoLine(sprintf('You can find your transactions under tag "%s"', $this->importJob->tag->tag));
}
if (null === $this->importJob->tag) {
$this->errorLine('No transactions have been imported :(.');
}
if (count($this->importJob->errors) > 0) {
$this->infoLine(sprintf('%d error(s) occurred:', count($this->importJob->errors)));
foreach ($this->importJob->errors as $err) {
$this->errorLine('- ' . $err);
}
}
}
/**
* @param string $message
* @param array $data
*
* @codeCoverageIgnore
*/
private function infoLine(string $message, array $data = null): void
{
Log::info($message, $data ?? []);
$this->line($message);
}
/**
* Keep repeating import call until job lands on "provider_finished".
*
* @throws FireflyException
*/
private function processFile(): void
{
$className = config('import.routine.file');
$valid = ['provider_finished'];
$count = 0;
while (!in_array($this->importJob->status, $valid, true) && $count < 6) {
Log::debug(sprintf('Now in loop #%d.', $count + 1));
/** @var RoutineInterface $routine */
$routine = app($className);
$routine->setImportJob($this->importJob);
try {
$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->importRepository->setStatus($this->importJob, 'error');
throw new FireflyException($message);
}
$count++;
}
$this->importRepository->setStatus($this->importJob, 'provider_finished');
$this->importJob->status = 'provider_finished';
}
/**
*
* @throws FireflyException
*/
private function storeData(): void
{
if ('provider_finished' === $this->importJob->status) {
$this->infoLine('Import has finished. Please wait for storage of data.');
// set job to be storing data:
$this->importRepository->setStatus($this->importJob, 'storing_data');
/** @var ImportArrayStorage $storage */
$storage = app(ImportArrayStorage::class);
$storage->setImportJob($this->importJob);
try {
$storage->store();
} catch (FireflyException|Exception $e) {
$message = 'The import routine crashed: ' . $e->getMessage();
Log::error($message);
Log::error($e->getTraceAsString());
// set job errored out:
$this->importRepository->setStatus($this->importJob, 'error');
throw new FireflyException($message);
}
// set storage to be finished:
$this->importRepository->setStatus($this->importJob, 'storage_finished');
}
}
/**
* Store the supplied file as an attachment to this job.
*
* @param string $file
*
* @throws FireflyException
*/
private function storeFile(string $file): void
{
// store file as attachment.
if ('' !== $file) {
$messages = $this->importRepository->storeCLIUpload($this->importJob, 'import_file', $file);
if ($messages->count() > 0) {
throw new FireflyException($messages->first());
}
}
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
{
$this->userRepository = app(UserRepositoryInterface::class);
$this->importRepository = app(ImportJobRepositoryInterface::class);
}
/**
* Verify user inserts correct arguments.
*
* @noinspection MultipleReturnStatementsInspection
* @return bool
* @codeCoverageIgnore
*/
private function validArguments(): bool
{
$file = (string) $this->argument('file');
$configuration = (string) $this->argument('configuration');
$cwd = getcwd();
$enabled = (bool) config('import.enabled.file');
if (false === $enabled) {
$this->errorLine('CSV Provider is not enabled.');
return false;
}
if (!file_exists($file)) {
$this->errorLine(sprintf('Firefly III cannot find file "%s" (working directory: "%s").', $file, $cwd));
return false;
}
if (!file_exists($configuration)) {
$this->errorLine(sprintf('Firefly III cannot find configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return false;
}
$configurationData = json_decode(file_get_contents($configuration), true, 512, JSON_THROW_ON_ERROR);
if (null === $configurationData) {
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return false;
}
return true;
}
}

View File

@ -64,7 +64,6 @@ class ReportEmptyObjects extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Report on empty objects finished in %s seconds', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -69,7 +69,6 @@ class ReportIntegrity extends Command
echo $result;
}
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}
}

View File

@ -54,7 +54,6 @@ class ReportSum extends Command
{
$this->reportSum();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -53,7 +53,6 @@ class RestoreOAuthKeys extends Command
{
$this->restoreOAuthKeys();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -87,7 +87,6 @@ class AccountCurrencies extends Command
$this->info(sprintf('Verified and fixed account currencies in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -78,8 +78,6 @@ class BackToJournals extends Command
$this->info(sprintf('Updated category and budget info for all transaction journals in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -92,8 +92,6 @@ class BudgetLimitCurrency extends Command
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -91,8 +91,6 @@ class CCLiabilities extends Command
$this->info(sprintf('Verified credit card liabilities in %s seconds', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -101,8 +101,6 @@ class MigrateAttachments extends Command
$this->info(sprintf('Migrated attachment notes in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -100,8 +100,6 @@ class MigrateJournalNotes extends Command
$this->info(sprintf('Migrated notes in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -72,8 +72,6 @@ class MigrateRecurrenceMeta extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Migrated recurrence meta data in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -65,7 +65,6 @@ class MigrateTagLocations extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Migrated tag locations in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -112,8 +112,6 @@ class MigrateToGroups extends Command
$this->markAsMigrated();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -99,7 +99,6 @@ class MigrateToRules extends Command
$this->info(sprintf('Verified and fixed bills in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -90,7 +90,6 @@ class OtherCurrenciesCorrections extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified and fixed transaction currencies in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -91,7 +91,6 @@ class RenameAccountMeta extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Fixed account meta data in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -101,7 +101,6 @@ class TransactionIdentifier extends Command
$this->info(sprintf('Verified and fixed transaction identifiers in %s seconds.', $end));
$this->markAsExecuted();
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -111,7 +111,6 @@ class TransferCurrenciesCorrections extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified and fixed currency information for transfers in %s seconds.', $end));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -117,7 +117,6 @@ class UpgradeDatabase extends Command
// index will set FF3 version.
app('fireflyconfig')->set('ff3_version', (string) config('firefly.version'));
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}

View File

@ -58,9 +58,9 @@ class UpgradeFireflyInstructions extends Command
}
// collect system telemetry
// app('telemetry')->feature('system.php.version', PHP_VERSION);
// app('telemetry')->feature('system.os.version', PHP_OS);
// app('telemetry')->feature('system.command.executed', $this->signature);
app('telemetry')->feature('system.php.version', PHP_VERSION);
app('telemetry')->feature('system.os.version', PHP_OS);
app('telemetry')->feature('system.command.executed', $this->signature);
return 0;
}