Exakat\Tasks\Doctor::checkPreRequisite PHP Method

checkPreRequisite() private method

private checkPreRequisite ( )
    private function checkPreRequisite()
    {
        // Compulsory
        $stats['exakat']['version'] = Exakat::VERSION;
        $stats['exakat']['build'] = Exakat::BUILD;
        // check for PHP
        $stats['PHP']['binary'] = $this->config->php;
        $stats['PHP']['version'] = phpversion();
        $stats['PHP']['curl'] = extension_loaded('curl') ? 'Yes' : 'No (Compulsory, please install it with --with-curl)';
        $stats['PHP']['hash'] = extension_loaded('hash') ? 'Yes' : 'No (Compulsory, please install it with --enable-hash)';
        $stats['PHP']['phar'] = extension_loaded('phar') ? 'Yes' : 'No (Needed to run exakat.phar. please install by default)';
        $stats['PHP']['sqlite3'] = extension_loaded('sqlite3') ? 'Yes' : 'No (Compulsory, please install it by default (remove --without-sqlite3))';
        $stats['PHP']['tokenizer'] = extension_loaded('tokenizer') ? 'Yes' : 'No (Compulsory, please install it by default (remove --disable-tokenizer))';
        $stats['PHP']['mbstring'] = extension_loaded('mbstring') ? 'Yes' : 'No (Optional, add --enable-mbstring to configure)';
        $stats['PHP']['exakat.ini'] = implode(",\n                           ", $this->config->configFiles);
        // java
        $res = shell_exec('java -version 2>&1');
        if (preg_match('/command not found/is', $res)) {
            $stats['java']['installed'] = 'No';
            $stats['java']['installation'] = 'No java found. Please, install Java Runtime (SRE) 1.7 or above from java.com web site.';
        } elseif (preg_match('/(java|openjdk) version "(.*)"/is', $res, $r)) {
            $lines = explode("\n", $res);
            $line2 = $lines[1];
            $stats['java']['installed'] = 'Yes';
            $stats['java']['type'] = trim($line2);
            $stats['java']['version'] = $r[1];
        } else {
            $stats['java']['error'] = $res;
            $stats['java']['installation'] = 'No java found. Please, install Java Runtime (SRE) 1.7 or above from java.com web site.';
        }
        $res = getenv('JAVA_HOME');
        $stats['java']['$JAVA_HOME'] = $res;
        // neo4j
        if (empty($this->config->neo4j_folder)) {
            $stats['neo4j']['installed'] = 'Couldn\'t find the path to neo4j from the config/exakat.ini. Please, check it.';
        } elseif (!file_exists($this->config->neo4j_folder)) {
            $stats['neo4j']['installed'] = 'No (folder : ' . $this->config->neo4j_folder . ')';
        } else {
            $file = file($this->config->neo4j_folder . '/README.txt');
            $stats['neo4j']['version'] = trim($file[0]);
            if (isset($stats['java']['version']) && version_compare($stats['java']['version'], '1.8') < 0) {
                $file = file_get_contents($this->config->neo4j_folder . '/conf/neo4j-wrapper.conf');
                if (!preg_match('/wrapper.java.additional=-XX:MaxPermSize=(\\d+\\w)/is', $file, $r)) {
                    $stats['neo4j']['MaxPermSize'] = 'Unset (64M)';
                    $stats['neo4j']['MaxPermSize warning'] = 'Set MaxPermSize to 512 or more in neo4j/conf/neo4j-wrapper.conf, with "wrapper.java.additional=-XX:MaxPermSize=512m" around line 20';
                } else {
                    $stats['neo4j']['MaxPermSize'] = $r[1];
                }
            }
            $file = file_get_contents($this->config->neo4j_folder . '/conf/neo4j-server.properties');
            if (preg_match('/org.neo4j.server.webserver.port *= *(\\d+)/is', $file, $r)) {
                $stats['neo4j']['port'] = $r[1];
            } else {
                $stats['neo4j']['port'] = '7474 (in fact, unset value. Using default : 7474)';
            }
            if ($stats['neo4j']['port'] != $this->config->neo4j_port) {
                $stats['neo4j']['port_alert'] = $this->config->neo4j_port . ' : configured port in config/exakat.ini is not the one in the neo4j installation. Please, sync them.';
            }
            if (preg_match('/dbms.security.auth_enabled\\s*=\\s*false/is', $file, $r)) {
                $stats['neo4j']['authentication'] = 'Not enabled';
            } else {
                $stats['neo4j']['authentication'] = 'Enabled.';
                if (empty($this->config->neo4j_login)) {
                    $stats['neo4j']['login'] = 'Login is not set, but authentication is. Please, set login in config/exakat.ini';
                } elseif (empty($this->config->neo4j_password)) {
                    $stats['neo4j']['password'] = 'Login is set, but not password. Please, set it in config/exakat.ini';
                }
                $res = $this->gremlin->query('"Hello world"');
                if ($res === null) {
                    $stats['neo4j']['credentials'] = 'Server is not running.';
                } elseif (isset($res->success) && $res->success === true) {
                    $stats['neo4j']['credentials'] = 'OK.';
                } else {
                    $stats['neo4j']['credentials'] = 'Login or password are wrong (message : ' . $res->errors[0]->message . ')';
                }
            }
            if (preg_match('#org.neo4j.server.thirdparty_jaxrs_classes=com.thinkaurelius.neo4j.plugins=/tp#is', $file, $r)) {
                $stats['neo4j']['gremlinPlugin'] = 'Configured.';
            } else {
                $stats['neo4j']['gremlinPlugin'] = 'Not found. Make sure that "org.neo4j.server.thirdparty_jaxrs_classes=com.thinkaurelius.neo4j.plugins=/tp" is in the conf/neo4j-server.property.';
            }
            $gremlinPlugin = glob($this->config->neo4j_folder . '/plugins/*/neo4j-gremlin-3.*.jar');
            if (empty($gremlinPlugin)) {
                $stats['neo4j']['gremlinJar'] = 'neo4j-gremlin-3.*.jar coudln\'t be found in the ' . $this->config->neo4j_folder . '/plugins/* folders. Make sure gremlin is installed, and running gremlin version 3.* (3.2 is recommended).';
            } elseif (count($gremlinPlugin) > 1) {
                $stats['neo4j']['gremlinJar'] = 'Found ' . count($gremlinPlugin) . ' plugins gremlin. Only one neo4j-gremlin-3.*.jar is sufficient. ';
            } else {
                $stats['neo4j']['gremlinJar'] = basename(trim(array_pop($gremlinPlugin)));
            }
            $stats['neo4j']['scriptFolder'] = file_exists($this->config->neo4j_folder . '/scripts/') ? 'Yes' : 'No';
            if ($stats['neo4j']['scriptFolder'] == 'No') {
                mkdir($this->config->neo4j_folder . '/scripts/', 0755);
                $stats['neo4j']['scriptFolder'] = file_exists($this->config->neo4j_folder . '/scripts/') ? 'Yes' : 'No';
            }
            $pidPath = $this->config->neo4j_folder . '/conf/neo4j-service.pid';
            if (file_exists($pidPath)) {
                $stats['neo4j']['pid'] = file_get_contents($pidPath);
            } else {
                $res = shell_exec('ps aux | grep gremlin | grep plugin');
                preg_match('/^\\w+\\s+(\\d+)\\s/is', $res, $r);
                $stats['neo4j']['pid'] = $r[1];
            }
            $json = @file_get_contents('http://' . $this->config->neo4j_host . ':' . $this->config->neo4j_port . '/db/data/');
            if (empty($json)) {
                $stats['neo4j']['running'] = 'No';
            } else {
                $stats['neo4j']['running'] = 'Yes';
                $status = shell_exec('cd ' . $this->config->neo4j_folder . '; ./bin/neo4j status');
                if (strpos($status, 'Neo4j Server is running at pid') !== false) {
                    $stats['neo4j']['running here'] = 'Yes';
                } else {
                    $stats['neo4j']['running here'] = 'No';
                }
                if ('{"success":true}' === file_get_contents('http://' . $this->config->neo4j_host . ':' . $this->config->neo4j_port . '/tp/gremlin/execute')) {
                    $stats['neo4j']['gremlin'] = 'Yes';
                } else {
                    $stats['neo4j']['gremlin'] = 'No';
                    $stats['neo4j']['gremlin-installation'] = 'Install gremlin plugin for neo4j';
                }
            }
            $stats['neo4j']['$NEO4J_HOME'] = getenv('NEO4J_HOME');
            $stats['neo4j']['$NEO4J_HOME / config'] = realpath(getenv('NEO4J_HOME')) === realpath($this->config->neo4j_folder) ? 'Same' : 'Different';
        }
        return $stats;
    }