2018-08-12 14:26:11 +02:00
|
|
|
<?php
|
|
|
|
|
2018-12-31 07:48:23 +01:00
|
|
|
/**
|
|
|
|
* Cron.php
|
2019-06-07 17:57:46 +02:00
|
|
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
2018-12-31 07:48:23 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-12-31 07:48:23 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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.
|
2018-12-31 07:48:23 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-12-31 07:48:23 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-12-31 07:48:23 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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/>.
|
2018-12-31 07:48:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-06-07 17:57:46 +02:00
|
|
|
namespace FireflyIII\Console\Commands\Tools;
|
2018-08-12 14:26:11 +02:00
|
|
|
|
2019-07-02 06:11:06 +02:00
|
|
|
use Carbon\Carbon;
|
2019-06-07 18:13:54 +02:00
|
|
|
use Exception;
|
2018-08-12 14:26:11 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
|
|
|
use Illuminate\Console\Command;
|
2019-07-02 06:11:06 +02:00
|
|
|
use InvalidArgumentException;
|
2018-08-12 14:26:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Cron
|
2018-08-23 18:33:07 +02:00
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
2018-08-12 14:26:11 +02:00
|
|
|
*/
|
|
|
|
class Cron extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Runs all Firefly III cron-job related commands. Configure a cron job according to the official Firefly III documentation.';
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-06-07 17:57:46 +02:00
|
|
|
protected $signature = 'firefly-iii:cron
|
|
|
|
{--F|force : Force the cron job(s) to execute.}
|
|
|
|
{--date= : Set the date in YYYY-MM-DD to make Firefly III think that\'s the current date.}
|
|
|
|
';
|
2018-08-12 14:26:11 +02:00
|
|
|
|
|
|
|
/**
|
2019-06-07 18:13:54 +02:00
|
|
|
* @return int
|
|
|
|
* @throws Exception
|
2018-08-12 14:26:11 +02:00
|
|
|
*/
|
|
|
|
public function handle(): int
|
|
|
|
{
|
2019-07-02 06:11:06 +02:00
|
|
|
$date = null;
|
|
|
|
try {
|
|
|
|
$date = new Carbon($this->option('date'));
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
$this->error(sprintf('"%s" is not a valid date', $this->option('date')));
|
|
|
|
$e->getMessage();
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:57:46 +02:00
|
|
|
|
2018-08-12 14:26:11 +02:00
|
|
|
$recurring = new RecurringCronjob;
|
2019-06-07 17:57:46 +02:00
|
|
|
$recurring->setForce($this->option('force'));
|
2019-07-02 06:11:06 +02:00
|
|
|
|
|
|
|
// set date in cron job:
|
|
|
|
if (null !== $date) {
|
|
|
|
$recurring->setDate($date);
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:26:11 +02:00
|
|
|
try {
|
|
|
|
$result = $recurring->fire();
|
|
|
|
} catch (FireflyException $e) {
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (false === $result) {
|
|
|
|
$this->line('The recurring transaction cron job did not fire.');
|
|
|
|
}
|
|
|
|
if (true === $result) {
|
|
|
|
$this->line('The recurring transaction cron job fired successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('More feedback on the cron jobs can be found in the log files.');
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|