Passed
Push — master ( 52d6d0...ade603 )
by Andreas
33:03
created

application   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 81.39%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 74
ccs 35
cts 43
cp 0.8139
rs 10
c 3
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B doRun() 0 47 8
A __construct() 0 17 1
1
<?php
2
/**
3
 * @package midcom.console
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
namespace midcom\console;
10
11
use Symfony\Component\Console\Application as base_application;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use midcom\console\command\exec;
16
use midcom\console\command\purgedeleted;
17
use midcom\console\command\blobdircleanup;
18
use midcom\console\command\rcsdircleanup;
19
use midcom\console\command\repligard;
20
use midcom\console\command\reindex;
21
use midcom\console\command\cron;
22
use midcom;
23
use midcom\console\command\cacheinvalidate;
24
25
/**
26
 * OpenPSA CLI command runner
27
 *
28
 * @package midcom.console
29
 */
30
class application extends base_application
31
{
32
    /**
33
     * @inheritDoc
34
     */
35 1
    public function __construct($name = 'midcom\console', $version = midcom::VERSION)
36
    {
37 1
        parent::__construct($name, $version);
38
39 1
        $this->getDefinition()
40 1
            ->addOption(new InputOption('--servername', '-s', InputOption::VALUE_REQUIRED, 'HTTP server name', 'localhost'));
41 1
        $this->getDefinition()
42 1
            ->addOption(new InputOption('--port', '-p', InputOption::VALUE_REQUIRED, 'HTTP server port', '80'));
43
44 1
        $this->add(new exec);
45 1
        $this->add(new purgedeleted);
46 1
        $this->add(new repligard);
47 1
        $this->add(new blobdircleanup);
48 1
        $this->add(new rcsdircleanup);
49 1
        $this->add(new reindex);
50 1
        $this->add(new cron);
51 1
        $this->add(new cacheinvalidate);
52 1
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 1
    public function doRun(InputInterface $input, OutputInterface $output)
58
    {
59
        // we need the to register the mgdschema classes before starting midcom,
60 1
        if (!defined('OPENPSA2_UNITTEST_RUN') && !\midcom_connection::setup(OPENPSA_PROJECT_BASEDIR)) {
61
            throw new \RuntimeException('Could not open midgard connection: ' . \midcom_connection::get_error_string());
62
        }
63
64 1
        if (file_exists(OPENPSA_PROJECT_BASEDIR . 'config.inc.php')) {
65
            include_once OPENPSA_PROJECT_BASEDIR . 'config.inc.php';
66
        }
67
68 1
        $GLOBALS['midcom_config_local']['cache_module_content_uncached'] = true;
69 1
        if (!defined('MIDCOM_ROOT')) {
70
            if (file_exists(OPENPSA_PROJECT_BASEDIR . 'lib/midcom.php')) {
71
                define('MIDCOM_ROOT', OPENPSA_PROJECT_BASEDIR . 'lib');
72
            } elseif (file_exists(OPENPSA_PROJECT_BASEDIR . 'vendor/openpsa/midcom/lib/midcom.php')) {
73
                define('MIDCOM_ROOT', OPENPSA_PROJECT_BASEDIR . 'vendor/openpsa/midcom/lib');
74
            } else {
75
                throw new \Exception('Could not find midcom root');
76
            }
77
        }
78
79 1
        $port = $input->getParameterOption(['--port', '-p'], '80');
80 1
        $servername = $input->getParameterOption(['--servername', '-s'], md5(__FILE__));
81
82
        $server_defaults = [
83 1
            'HTTP_HOST' => $servername,
84 1
            'SERVER_NAME' => $servername,
85
            'SERVER_SOFTWARE' => __CLASS__,
86 1
            'HTTP_USER_AGENT' => $this->getName(),
87 1
            'SERVER_PORT' => $port,
88 1
            'REMOTE_ADDR' => '127.0.0.1',
89 1
            'REQUEST_URI' => '/',
90 1
            'REQUEST_TIME' => time(),
91 1
            'REMOTE_PORT' => $port
92
        ];
93 1
        $_SERVER = array_merge($server_defaults, $_SERVER);
94
95 1
        if ($_SERVER['SERVER_PORT'] == 443) {
96
            $_SERVER['HTTPS'] = 'on';
97
        }
98
99
        // This makes sure that existing auth and cache instances get overridden
100 1
        midcom::init();
101 1
        midcom::get()->componentloader->load_all_manifests();
102
103 1
        parent::doRun($input, $output);
104 1
    }
105
}
106