2024-08-19 18:41:57 +02:00
< ? php
namespace App\Console\Commands ;
use App\Http\Controllers\GiteaApiController\GiteaExport ;
2024-09-06 15:22:33 +02:00
use DateTime ;
2024-08-19 18:41:57 +02:00
use Illuminate\Console\Command ;
2024-09-06 15:22:33 +02:00
use InvalidArgumentException ;
2024-08-19 18:41:57 +02:00
2024-09-06 15:22:33 +02:00
class csvExport extends Command
2024-08-19 18:41:57 +02:00
{
/**
* The name and signature of the console command .
*
* @ var string
*/
2024-09-06 15:22:33 +02:00
protected $signature = 'csvExport:generate {firstDay?} {lastDay?}' ;
2024-08-19 18:41:57 +02:00
/**
* The console command description .
*
* @ var string
*/
protected $description = 'Export in stringa del csv con integrazione di nextcloud e invio email.' ;
/**
* Create a new command instance .
*
* @ return void
*/
public function __construct ()
{
parent :: __construct ();
}
2024-09-06 15:22:33 +02:00
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 ;
}
2024-08-19 18:41:57 +02:00
/**
* Execute the console command .
*
* @ return mixed
*/
public function handle ()
{
// Write your script logic here
$this -> info ( 'Inizio esecuzione.' );
2024-09-06 15:22:33 +02:00
$this -> info ( 'Controllo se sono state inserite date custom.' );
$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;
2024-08-19 18:41:57 +02:00
$this -> info ( 'Export da ' . $firstDay . ' a ' . $lastDay );
$calculate_agent_cost = true ;
$third_party_integrations_allow = true ;
$third_party_integrations_nextcloud = true ;
$third_party_integrations_open_project = false ;
$email_send_allow = true ;
$this -> info (
'Le seguenti opzioni sono attive '
. ' calculate_agent_cost ' . $calculate_agent_cost . '\n'
. ' third_party_integrations_allow ' . $third_party_integrations_allow . '\n'
. ' third_party_integrations_nextcloud ' . $third_party_integrations_nextcloud . '\n'
. ' third_party_integrations_open_project ' . $third_party_integrations_open_project . '\n'
. ' email_send_allow ' . $email_send_allow . '\n'
);
$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' ]);
return Command :: SUCCESS ;
}
}