option('download-cer') && !$this->option('create-recurring') && !$this->option('create-auto-budgets') && !$this->option('send-subscription-warnings') && !$this->option('check-version') && !$this->option('send-webhook-messages'); $date = null; try { $date = new Carbon($this->option('date')); } catch (InvalidArgumentException $e) { $this->friendlyError(sprintf('"%s" is not a valid date', $this->option('date'))); } $force = (bool) $this->option('force'); // @phpstan-ignore-line // Fire exchange rates cron job. if (true === config('cer.download_enabled') && ($doAll || $this->option('download-cer'))) { try { $this->exchangeRatesCronJob($force, $date); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } // check for new version if ($doAll || $this->option('check-version')) { try { $this->checkForUpdates($force); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } // Fire recurring transaction cron job. if ($doAll || $this->option('create-recurring')) { try { $this->recurringCronJob($force, $date); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } // Fire auto-budget cron job: if ($doAll || $this->option('create-auto-budgets')) { try { $this->autoBudgetCronJob($force, $date); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } // Fire bill warning cron job if ($doAll || $this->option('send-subscription-warnings')) { try { $this->subscriptionWarningCronJob($force, $date); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } // Fire webhook messages cron job. if ($doAll || $this->option('send-webhook-messages')) { try { $this->webhookCronJob($force, $date); } catch (FireflyException $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); $this->friendlyError($e->getMessage()); } } $this->friendlyInfo('More feedback on the cron jobs can be found in the log files.'); return 0; } private function exchangeRatesCronJob(bool $force, ?Carbon $date): void { Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); $exchangeRates = new ExchangeRatesCronjob(); $exchangeRates->setForce($force); // set date in cron job: if ($date instanceof Carbon) { $exchangeRates->setDate($date); } $exchangeRates->fire(); if ($exchangeRates->jobErrored) { $this->friendlyError(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); } if ($exchangeRates->jobFired) { $this->friendlyInfo(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); } if ($exchangeRates->jobSucceeded) { $this->friendlyPositive(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); } } private function checkForUpdates(bool $force): void { $updateCheck = new UpdateCheckCronjob(); $updateCheck->setForce($force); $updateCheck->fire(); if ($updateCheck->jobErrored) { $this->friendlyError(sprintf('Error in "update check" cron: %s', $updateCheck->message)); } if ($updateCheck->jobFired) { $this->friendlyInfo(sprintf('"Update check" cron fired: %s', $updateCheck->message)); } if ($updateCheck->jobSucceeded) { $this->friendlyPositive(sprintf('"Update check" cron ran with success: %s', $updateCheck->message)); } } /** * @throws FireflyException */ private function recurringCronJob(bool $force, ?Carbon $date): void { $recurring = new RecurringCronjob(); $recurring->setForce($force); // set date in cron job: if ($date instanceof Carbon) { $recurring->setDate($date); } $recurring->fire(); if ($recurring->jobErrored) { $this->friendlyError(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message)); } if ($recurring->jobFired) { $this->friendlyInfo(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message)); } if ($recurring->jobSucceeded) { $this->friendlyPositive(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message)); } } private function autoBudgetCronJob(bool $force, ?Carbon $date): void { $autoBudget = new AutoBudgetCronjob(); $autoBudget->setForce($force); // set date in cron job: if ($date instanceof Carbon) { $autoBudget->setDate($date); } $autoBudget->fire(); if ($autoBudget->jobErrored) { $this->friendlyError(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message)); } if ($autoBudget->jobFired) { $this->friendlyInfo(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message)); } if ($autoBudget->jobSucceeded) { $this->friendlyPositive(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message)); } } /** * @throws FireflyException */ private function subscriptionWarningCronJob(bool $force, ?Carbon $date): void { $subscriptionWarningJob = new BillWarningCronjob(); $subscriptionWarningJob->setForce($force); // set date in cron job: if ($date instanceof Carbon) { $subscriptionWarningJob->setDate($date); } $subscriptionWarningJob->fire(); if ($subscriptionWarningJob->jobErrored) { $this->friendlyError(sprintf('Error in "subscription warnings" cron: %s', $subscriptionWarningJob->message)); } if ($subscriptionWarningJob->jobFired) { $this->friendlyInfo(sprintf('"Send subscription warnings" cron fired: %s', $subscriptionWarningJob->message)); } if ($subscriptionWarningJob->jobSucceeded) { $this->friendlyPositive(sprintf('"Send subscription warnings" cron ran with success: %s', $subscriptionWarningJob->message)); } } private function webhookCronJob(bool $force, ?Carbon $date): void { $webhook = new WebhookCronjob(); $webhook->setForce($force); // set date in cron job: if ($date instanceof Carbon) { $webhook->setDate($date); } $webhook->fire(); if ($webhook->jobErrored) { $this->friendlyError(sprintf('Error in "webhook" cron: %s', $webhook->message)); } if ($webhook->jobFired) { $this->friendlyInfo(sprintf('"Webhook" cron fired: %s', $webhook->message)); } if ($webhook->jobSucceeded) { $this->friendlyPositive(sprintf('"Webhook" cron ran with success: %s', $webhook->message)); } } }