Passed
Push — develop ( 368e3d...115c7b )
by Nikolay
12:16
created

CheckConnection::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 15
rs 9.9
cc 4
nc 4
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\Core\Workers\Libs\WorkerPrepareAdvice;
21
22
use MikoPBX\Core\System\Network;
23
use MikoPBX\Core\System\Processes;
24
use MikoPBX\Core\System\Util;
25
use Phalcon\Di\Injectable;
26
27
/**
28
 * Class CheckConnection
29
 * This class is responsible for checking internet connection on backend.
30
 *
31
 * @package MikoPBX\Core\Workers\Libs\WorkerPrepareAdvice
32
 */
33
class CheckConnection extends Injectable
34
{
35
36
    /**
37
     * Checks whether internet connection is available or not
38
     *
39
     * @return array
40
     *
41
     */
42
    public function process():array
43
    {
44
        $messages = [];
45
        $pathTimeout = Util::which('timeout');
46
        $pathCurl = Util::which('curl');
47
        $retCode = Processes::mwExec("$pathTimeout 5 $pathCurl 'https://www.google.com/'");
48
        if ($retCode !== 0) {
49
            $messages['warning'][] = ['messageTpl'=>'adv_ProblemWithInternetConnection'];
50
            if (file_exists(Network::INTERNET_FLAG_FILE)) {
51
                unlink(Network::INTERNET_FLAG_FILE);
52
            }
53
        } elseif (!file_exists(Network::INTERNET_FLAG_FILE)) {
54
                touch(Network::INTERNET_FLAG_FILE);
55
        }
56
        return $messages;
57
    }
58
}