Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| LdcWebStatusChecker | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | n/a |
0 / 0 |
|||
| handle | n/a |
0 / 0 |
5 | n/a |
0 / 0 |
|||||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console\Commands; |
| 4 | |
| 5 | use Illuminate\Console\Command; |
| 6 | |
| 7 | /** |
| 8 | * Command Name: LDC Web Status Checker |
| 9 | * Description: Envoi des infos Serveur/Laravel vers LDC Web |
| 10 | * Version: 1.1 |
| 11 | * Author: Vincent BRIDIER |
| 12 | * Author URI: vincent.bridier@ldc.fr |
| 13 | * |
| 14 | * @codeCoverageIgnore |
| 15 | */ |
| 16 | class LdcWebStatusChecker extends Command |
| 17 | { |
| 18 | /** |
| 19 | * The name and signature of the console command. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $signature = 'ldcweb:statuschecker'; |
| 24 | |
| 25 | /** |
| 26 | * The console command description. |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | protected $description = 'Envoi des infos Serveur/Laravel vers LDC Web'; |
| 31 | |
| 32 | /** |
| 33 | * Execute the console command. |
| 34 | * |
| 35 | * @return mixed |
| 36 | */ |
| 37 | public function handle() |
| 38 | { |
| 39 | $data = []; |
| 40 | $data['uuid'] = config('ldcweb.project_uuid'); |
| 41 | |
| 42 | // Sitemap.xml ? |
| 43 | if (file_exists(public_path() . '/sitemap.xml')) { |
| 44 | $data['sitemap'] = 'true'; |
| 45 | } else { |
| 46 | $data['sitemap'] = 'false'; |
| 47 | } |
| 48 | |
| 49 | // Robots.txt ? |
| 50 | if (file_exists(public_path() . '/robots.txt')) { |
| 51 | $data['robots'] = 'true'; |
| 52 | } else { |
| 53 | $data['robots'] = 'false'; |
| 54 | } |
| 55 | |
| 56 | // Check logs. |
| 57 | $data['logs'] = 0; |
| 58 | $patherror = storage_path('/logs'); |
| 59 | $files = glob($patherror . '/*.log'); |
| 60 | if (count($files) > 0) { |
| 61 | foreach ($files as $file) { |
| 62 | $data['logs'] = $data['logs'] + filesize($file); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $data['code']['version'] = app()->version(); |
| 67 | |
| 68 | // Send by cURL. |
| 69 | $url = 'https://ldc-web.ldc.fr/api/status-checker'; |
| 70 | $ch = curl_init($url); |
| 71 | $payload = ['token' => 'CE8S52Qq7stf5k8frF4T', 'datas' => json_encode($data)]; |
| 72 | curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); |
| 73 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 74 | curl_exec($ch); |
| 75 | curl_close($ch); |
| 76 | return 0; |
| 77 | } |
| 78 | } |