Passed
Push — master ( 822a0b...93f4bd )
by Andreas
23:15
created

application::doRun()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 23
c 2
b 0
f 0
nc 5
nop 2
dl 0
loc 38
ccs 0
cts 29
cp 0
crap 30
rs 9.2408
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
    public function __construct($name = 'midcom\console', $version = midcom::VERSION)
36
    {
37
        parent::__construct($name, $version);
38
39
        $this->getDefinition()
40
            ->addOption(new InputOption('--servername', '-s', InputOption::VALUE_REQUIRED, 'HTTP server name', 'localhost'));
41
        $this->getDefinition()
42
            ->addOption(new InputOption('--port', '-p', InputOption::VALUE_REQUIRED, 'HTTP server port', '80'));
43
44
        $this->add(new exec);
45
        $this->add(new purgedeleted);
46
        $this->add(new repligard);
47
        $this->add(new blobdircleanup);
48
        $this->add(new rcsdircleanup);
49
        $this->add(new reindex);
50
        $this->add(new cron);
51
        $this->add(new cacheinvalidate);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function doRun(InputInterface $input, OutputInterface $output)
58
    {
59
        // we need the to register the mgdschema classes before starting midcom,
60
        if (!defined('OPENPSA2_UNITTEST_RUN') && !\midcom_connection::setup(OPENPSA_PROJECT_BASEDIR)) {
0 ignored issues
show
Bug introduced by
The constant midcom\console\OPENPSA_PROJECT_BASEDIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
61
            throw new \RuntimeException('Could not open midgard connection: ' . \midcom_connection::get_error_string());
62
        }
63
64
        if (file_exists(OPENPSA_PROJECT_BASEDIR . 'config.inc.php')) {
65
            include_once OPENPSA_PROJECT_BASEDIR . 'config.inc.php';
66
        }
67
68
        $GLOBALS['midcom_config_local']['cache_module_content_uncached'] = true;
69
70
        $port = $input->getParameterOption(['--port', '-p'], '80');
71
        $servername = $input->getParameterOption(['--servername', '-s'], md5(__FILE__));
72
73
        $server_defaults = [
74
            'HTTP_HOST' => $servername,
75
            'SERVER_NAME' => $servername,
76
            'SERVER_SOFTWARE' => __CLASS__,
77
            'HTTP_USER_AGENT' => $this->getName(),
78
            'SERVER_PORT' => $port,
79
            'REMOTE_ADDR' => '127.0.0.1',
80
            'REQUEST_URI' => '/',
81
            'REQUEST_TIME' => time(),
82
            'REMOTE_PORT' => $port
83
        ];
84
        $_SERVER = array_merge($server_defaults, $_SERVER);
85
86
        if ($_SERVER['SERVER_PORT'] == 443) {
87
            $_SERVER['HTTPS'] = 'on';
88
        }
89
90
        // This makes sure that existing auth and cache instances get overridden
91
        midcom::init();
92
        midcom::get()->componentloader->load_all_manifests();
93
94
        parent::doRun($input, $output);
95
    }
96
}
97