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