- Add Models Export Command
This commit is contained in:
parent
e9959a45ba
commit
a54d7b910c
3 changed files with 214 additions and 1 deletions
207
app/Console/Commands/ExportDatas.php
Normal file
207
app/Console/Commands/ExportDatas.php
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\DatastorePcc;
|
||||
use App\Models\DomainNames;
|
||||
use App\Models\GitRepos;
|
||||
use App\Models\LDCNetworks;
|
||||
use App\Models\Projects;
|
||||
use App\Models\Servers;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ExportDatas extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'datas:export';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Export data in Excel format';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->ExportProjects("EDL_WEB.csv");
|
||||
$this->ExportServers("EDL_Servers.csv");
|
||||
$this->ExportDatastorePcc("EDL_Datastore_pcc.csv");
|
||||
$this->ExportDomainNames("EDL_Domain_Names.csv");
|
||||
$this->ExportLdcNetworks("EDL_LDC_Networks.csv");
|
||||
$this->ExportGitRepos("EDL_GIT_Repos.csv");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function ExportGitRepos($filename)
|
||||
{
|
||||
$repos = GitRepos::orderBy('name', 'ASC')->get();
|
||||
Storage::disk('export')->append($filename, "Nom");
|
||||
foreach ($repos as $repo) {
|
||||
$infos = [
|
||||
trim($repo->name),
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
|
||||
private function ExportLdcNetworks($filename)
|
||||
{
|
||||
$networks = LDCNetworks::all();
|
||||
Storage::disk('export')->append($filename, "CIDR;First IP;Last IP");
|
||||
foreach ($networks as $network) {
|
||||
$infos = [
|
||||
trim($network->cidr),
|
||||
trim($network->first_ip),
|
||||
trim($network->last_ip),
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
|
||||
private function ExportDomainNames($filename)
|
||||
{
|
||||
$domains = DomainNames::all();
|
||||
Storage::disk('export')->append($filename, "ASCII;UTF-8;DATE D'EXPIRATION;RENOUVELLEMENT;MARQUE REF.;COMMENTAIRE");
|
||||
foreach ($domains as $domain) {
|
||||
$infos = [
|
||||
trim($domain->ascii_name),
|
||||
trim($domain->utf8_name),
|
||||
trim($domain->expiration_date),
|
||||
$domain->renew === 1 ? 'OUI' : 'NON',
|
||||
trim($domain->related_brand),
|
||||
trim($domain->comment),
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
|
||||
private function ExportDatastorePcc($filename)
|
||||
{
|
||||
$datastores = DatastorePcc::all();
|
||||
Storage::disk('export')->append($filename, "NOM;COMMENTAIRE");
|
||||
foreach ($datastores as $datastore) {
|
||||
$infos = [
|
||||
trim($datastore->title),
|
||||
trim($datastore->comment)
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
|
||||
private function ExportServers($filename)
|
||||
{
|
||||
$servers = Servers::orderBy('env', 'DESC')->get();
|
||||
Storage::disk('export')->append($filename, "ENV;NOM;TITRE;FUNCTION;SSH;IP INFRAWEB;VIRTUAL IP;DATASTORE PCC;COMMENTAIRE");
|
||||
foreach ($servers as $server) {
|
||||
$infos = [
|
||||
trim($server->env),
|
||||
trim($server->name),
|
||||
trim($server->title),
|
||||
trim($server->function),
|
||||
trim($server->ssh),
|
||||
trim($server->infraweb_ip),
|
||||
trim($server->virtual_ip),
|
||||
!is_null($server->datastore_pcc_id) ? trim(DatastorePcc::find($server->datastore_pcc_id)->title) : '',
|
||||
trim($server->comment)
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
|
||||
private function ExportProjects($filename)
|
||||
{
|
||||
$projects = Projects::orderBy('name', 'ASC')->get();
|
||||
$fields = [
|
||||
'DEV',
|
||||
'name',
|
||||
'dev_url',
|
||||
'https',
|
||||
'php',
|
||||
'dev_web_server_id',
|
||||
'dev_unix_user',
|
||||
'dev_unix_pwd',
|
||||
'dev_document_root',
|
||||
'dev_db_server_id',
|
||||
'dev_db_schema',
|
||||
'dev_db_user',
|
||||
'dev_db_pwd',
|
||||
'dev_htaccess_user',
|
||||
'dev_htaccess_pwd',
|
||||
'dev_comment',
|
||||
'dev_eai',
|
||||
'dev_whitelist_fw',
|
||||
];
|
||||
|
||||
Storage::disk('export')->append($filename, "ENV;NOM;URL;HTTPS;PHP;SERVEUR WEB;SSH;USER UNIX;PWD UNIX;DOCUMENT ROOT;SERVEUR BDD;SSH;USER DB;PWD DB;HTACCESS USER;HTACCESS PWD;COMMENTAIRE;FLUX EAI;WHITELIST FW");
|
||||
$this->writeProjectExport($projects, $fields, $filename);
|
||||
|
||||
$prod = implode(";", $fields);
|
||||
$prod = str_replace("dev", "prod", $prod);
|
||||
$prod = str_replace("DEV", "PROD", $prod);
|
||||
$prod = str_replace("prod_htaccess_user", "BLANK", $prod);
|
||||
$prod = str_replace("prod_htaccess_pwd", "BLANK", $prod);
|
||||
$fields = explode(";", $prod);
|
||||
|
||||
$this->writeProjectExport($projects, $fields, $filename);
|
||||
}
|
||||
|
||||
private function writeProjectExport($projects, $fields, $filename)
|
||||
{
|
||||
foreach ($projects as $project) {
|
||||
$infos = [];
|
||||
foreach ($fields as $field) {
|
||||
switch ($field) {
|
||||
case 'DEV':
|
||||
case 'PROD':
|
||||
$infos[] = $field;
|
||||
break;
|
||||
case 'https':
|
||||
$infos[] = $project->{$field} === 1 ? 'OUI' : 'NON';
|
||||
break;
|
||||
case 'dev_web_server_id':
|
||||
case 'dev_db_server_id':
|
||||
case 'prod_web_server_id':
|
||||
case 'prod_db_server_id':
|
||||
$server = Servers::find($project->{$field});
|
||||
$infos[] = trim($server->name);
|
||||
$infos[] = trim($server->ssh);
|
||||
break;
|
||||
case 'BLANK':
|
||||
$infos[] = "";
|
||||
break;
|
||||
default:
|
||||
$infos[] = trim($project->{$field});
|
||||
}
|
||||
}
|
||||
Storage::disk('export')->append($filename, implode(";", $infos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,10 +48,15 @@ return [
|
|||
'root' => storage_path('app'),
|
||||
],
|
||||
|
||||
'export' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('export'),
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'url' => env('APP_URL') . '/storage',
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
|
|
|
|||
1
storage/export/.gitignore
vendored
Normal file
1
storage/export/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*.csv
|
||||
Loading…
Add table
Reference in a new issue