rm: schedule add: custom date in artisan comand csvExport:generate con check date
This commit is contained in:
parent
3866a225ec
commit
3ced4077bf
|
@ -3,16 +3,18 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Http\Controllers\GiteaApiController\GiteaExport;
|
use App\Http\Controllers\GiteaApiController\GiteaExport;
|
||||||
|
use DateTime;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class exportCsv extends Command
|
class csvExport extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'csvExport:generate';
|
protected $signature = 'csvExport:generate {firstDay?} {lastDay?}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
@ -31,6 +33,32 @@ class exportCsv extends Command
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkDateValid($stringDate){
|
||||||
|
$d = DateTime::createFromFormat('Y-m-d', $stringDate);
|
||||||
|
if($d){
|
||||||
|
$d = $d->format('Y-m-d');
|
||||||
|
return $d && $d == $stringDate;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkInputDates(){
|
||||||
|
$firstDay = $this->argument('firstDay');
|
||||||
|
$lastDay = $this->argument('lastDay');
|
||||||
|
try{
|
||||||
|
if( $firstDay !== null && $lastDay !== null){
|
||||||
|
$this->info('Rilevate date richieste, controllo la correttezza del formato.');
|
||||||
|
if(!$this->checkDateValid($firstDay)) throw new InvalidArgumentException('Formato della prima data errata o data inesistente, formato richiesto Y-m-t, data fornita '. $firstDay);
|
||||||
|
if(!$this->checkDateValid($lastDay)) throw new InvalidArgumentException('Formato della seconda data errata o data inesistente, formato richiesto Y-m-t, data fornita '. $lastDay);
|
||||||
|
$this->info('Le date richieste sono correte.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (\InvalidArgumentException $e){
|
||||||
|
throw new InvalidArgumentException($e->getMessage());
|
||||||
|
}
|
||||||
|
$this->info('Non sono state rilevate date custom');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
|
@ -40,8 +68,10 @@ class exportCsv extends Command
|
||||||
{
|
{
|
||||||
// Write your script logic here
|
// Write your script logic here
|
||||||
$this->info('Inizio esecuzione.');
|
$this->info('Inizio esecuzione.');
|
||||||
$firstDay = date('Y-m-01'); // First day of the current month
|
$this->info('Controllo se sono state inserite date custom.');
|
||||||
$lastDay = date('Y-m-t'); // Last day of the current month
|
$this->checkInputDates();
|
||||||
|
$firstDay = $this->argument('firstDay') ? $this->argument('firstDay') : date('Y-m-01'); // First day of the current month;
|
||||||
|
$lastDay = $this->argument('lastDay') ? $this->argument('lastDay') : date('Y-m-t'); // Last day of the current month;
|
||||||
$this->info('Export da ' . $firstDay .' a '. $lastDay );
|
$this->info('Export da ' . $firstDay .' a '. $lastDay );
|
||||||
$calculate_agent_cost = true;
|
$calculate_agent_cost = true;
|
||||||
$third_party_integrations_allow = true;
|
$third_party_integrations_allow = true;
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use App\Console\Commands\exportCsv;
|
use App\Console\Commands\csvExport;
|
||||||
use App\Console\Commands\exportCsvCli;
|
|
||||||
use App\Http\Controllers\GiteaApiController\GiteaExport;
|
use App\Http\Controllers\GiteaApiController\GiteaExport;
|
||||||
use Dotenv\Dotenv;
|
use Dotenv\Dotenv;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
|
@ -17,7 +16,7 @@ class Kernel extends ConsoleKernel
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
exportCsv::class,
|
csvExport::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,43 +27,5 @@ class Kernel extends ConsoleKernel
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->call(function () {
|
|
||||||
$firstDay = date('Y-m-01'); // First day of the current month
|
|
||||||
$lastDay = date('Y-m-t'); // Last day of the current month
|
|
||||||
|
|
||||||
$calculate_agent_cost = true;
|
|
||||||
$third_party_integrations_allow = true;
|
|
||||||
$third_party_integrations_nextcloud = true;
|
|
||||||
$third_party_integrations_open_project = false;
|
|
||||||
$email_send_allow = true;
|
|
||||||
|
|
||||||
$gitea_export = new GiteaExport(
|
|
||||||
$calculate_agent_cost,
|
|
||||||
$third_party_integrations_allow,
|
|
||||||
$third_party_integrations_nextcloud,
|
|
||||||
$third_party_integrations_open_project,
|
|
||||||
$email_send_allow,
|
|
||||||
);
|
|
||||||
$gitea_export->export_issues($firstDay, $lastDay, ['state' => 'closed']);
|
|
||||||
})->monthly();
|
|
||||||
$schedule->call(function () {
|
|
||||||
$firstDay = date('Y-m-01'); // First day of the current month
|
|
||||||
$lastDay = date('Y-m-t'); // Last day of the current month
|
|
||||||
|
|
||||||
$calculate_agent_cost = true;
|
|
||||||
$third_party_integrations_allow = true;
|
|
||||||
$third_party_integrations_nextcloud = false;
|
|
||||||
$third_party_integrations_open_project = false;
|
|
||||||
$email_send_allow = true;
|
|
||||||
|
|
||||||
$gitea_export = new GiteaExport(
|
|
||||||
$calculate_agent_cost,
|
|
||||||
$third_party_integrations_allow,
|
|
||||||
$third_party_integrations_nextcloud,
|
|
||||||
$third_party_integrations_open_project,
|
|
||||||
$email_send_allow,
|
|
||||||
);
|
|
||||||
$gitea_export->export_issues($firstDay, $lastDay, ['state' => 'closed']);
|
|
||||||
})->everyFiveMinutes();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue