ldc-dam/app/Console/Commands/LDCWebStatusChecker.php

79 lines
1.9 KiB
PHP
Raw Normal View History

2020-04-30 12:28:15 +02:00
<?php
2022-04-19 16:07:27 +02:00
2022-04-20 15:23:31 +02:00
namespace App\Console\Commands;
use Illuminate\Console\Command;
/**
2022-04-19 16:07:27 +02:00
* Command Name: LDC Web Status Checker
* Description: Envoi des infos Serveur/Laravel vers LDC Web
2022-04-20 15:23:31 +02:00
* Version: 1.1
2022-04-19 16:07:27 +02:00
* Author: Vincent BRIDIER
* Author URI: vincent.bridier@ldc.fr
2022-04-20 15:23:31 +02:00
*
* @codeCoverageIgnore
2022-04-19 16:07:27 +02:00
*/
2022-04-20 15:23:31 +02:00
class LdcWebStatusChecker extends Command
2020-04-30 12:28:15 +02:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ldcweb:statuschecker';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Envoi des infos Serveur/Laravel vers LDC Web';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2022-04-19 16:07:27 +02:00
$data = [];
2022-04-20 15:23:31 +02:00
$data['uuid'] = config('ldcweb.project_uuid');
2020-04-30 12:28:15 +02:00
// Sitemap.xml ?
if (file_exists(public_path() . '/sitemap.xml')) {
$data['sitemap'] = 'true';
2022-04-19 16:07:27 +02:00
} else {
2020-04-30 12:28:15 +02:00
$data['sitemap'] = 'false';
}
// Robots.txt ?
if (file_exists(public_path() . '/robots.txt')) {
$data['robots'] = 'true';
2022-04-19 16:07:27 +02:00
} else {
2020-04-30 12:28:15 +02:00
$data['robots'] = 'false';
}
2022-04-20 15:23:31 +02:00
// Check logs.
2020-04-30 12:28:15 +02:00
$data['logs'] = 0;
2022-04-19 16:07:27 +02:00
$patherror = storage_path('/logs');
$files = glob($patherror . '/*.log');
if (count($files) > 0) {
2020-04-30 12:28:15 +02:00
foreach ($files as $file) {
$data['logs'] = $data['logs'] + filesize($file);
}
}
$data['code']['version'] = app()->version();
2022-04-20 15:23:31 +02:00
// Send by cURL.
2022-04-19 16:07:27 +02:00
$url = 'https://ldc-web.ldc.fr/api/status-checker';
$ch = curl_init($url);
2020-04-30 12:28:15 +02:00
$payload = ['token' => 'CE8S52Qq7stf5k8frF4T', 'datas' => json_encode($data)];
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2022-04-20 15:23:31 +02:00
curl_exec($ch);
2020-04-30 12:28:15 +02:00
curl_close($ch);
2022-04-20 15:23:31 +02:00
return 0;
2020-04-30 12:28:15 +02:00
}
}