Passed
Push — master ( 018ad3...689ead )
by Andreas
20:46
created

application   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 43
dl 0
loc 73
ccs 34
cts 42
cp 0.8095
rs 10
c 3
b 0
f 0
wmc 9

2 Methods

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