コード例 #1
0
ファイル: dbprofile.page.php プロジェクト: mdouchin/jelix
 protected function loadProfiles()
 {
     $file = jApp::configPath('profiles.ini.php');
     if (file_exists($file)) {
     } elseif (file_exists(jApp::configPath('profiles.ini.php.dist'))) {
         copy(jApp::configPath('profiles.ini.php.dist'), $file);
     } else {
         file_put_contents($file, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line\n\n[jdb:default]\ndriver=mysqli\ndatabase=\nhost=localhost\nuser=\npassword=\npersistent = on\nforce_encoding = on\ntable_prefix=\n");
     }
     $ini = new \Jelix\IniFile\IniModifier($file);
     $data = array('dbtype' => array(), 'driver' => array(), 'database' => array(), 'host' => array(), 'port' => array(), 'user' => array(), 'password' => array(), 'passwordconfirm' => array(), 'persistent' => array(), 'table_prefix' => array(), 'force_encoding' => array(), 'search_path' => array(), 'errors' => array());
     $profiles = $ini->getSectionList();
     $dbprofileslist = array();
     foreach ($profiles as $profile) {
         if (strpos($profile, 'jdb:') !== 0) {
             continue;
         }
         $dbprofileslist[] = $profile;
         $options = $ini->getValues($profile);
         $dbparam = new jDbParameters($options);
         $options = $dbparam->getParameters();
         $data['dbtype'][$profile] = $options['dbtype'];
         $driver = $options['driver'];
         if ($options['usepdo']) {
             $dsn = $ini->getValue('dsn', $profile);
             $data['driver'][$profile] = $driver . ':pdo';
             if (preg_match("/host=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['host'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('host', $profile);
                 $data['host'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/dbname=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['database'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('database', $profile);
                 $data['database'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/port=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['port'][$profile] = $m[1];
             } else {
                 $port = $ini->getValue('port', $profile);
                 $data['port'][$profile] = $port === null ? '' : $port;
             }
         } else {
             $data['driver'][$profile] = $driver . ($options['usepdo'] ? ':pdo' : '');
             $data['database'][$profile] = $ini->getValue('database', $profile);
             $data['host'][$profile] = $ini->getValue('host', $profile);
             $data['port'][$profile] = $ini->getValue('port', $profile);
         }
         $data['user'][$profile] = $ini->getValue('user', $profile);
         $data['password'][$profile] = $ini->getValue('password', $profile);
         $data['passwordconfirm'][$profile] = $data['password'][$profile];
         $data['persistent'][$profile] = $options['persistent'];
         $data['force_encoding'][$profile] = $options['force_encoding'];
         $data['table_prefix'][$profile] = $ini->getValue('table_prefix', $profile);
         $data['search_path'][$profile] = $ini->getValue('search_path', $profile);
         $data['errors'][$profile] = array();
     }
     $_SESSION['dbprofiles']['profiles'] = $dbprofileslist;
     $_SESSION['dbprofiles']['data'] = $data;
 }
コード例 #2
0
 function checkPhpExtensions()
 {
     $ok = true;
     if (!version_compare($this->buildProperties['PHP_VERSION_TARGET'], phpversion(), '<=')) {
         $this->error('php.bad.version');
         $notice = $this->messages->get('php.version.required', $this->buildProperties['PHP_VERSION_TARGET']);
         $notice .= '. ' . $this->messages->get('php.version.current', phpversion());
         $this->reporter->showNotice($notice);
         $ok = false;
     } else {
         if ($this->verbose) {
             $this->ok('php.ok.version', phpversion());
         }
     }
     $extensions = array('dom', 'SPL', 'SimpleXML', 'pcre', 'session', 'tokenizer', 'iconv', 'filter', 'json');
     foreach ($extensions as $name) {
         if (!extension_loaded($name)) {
             $this->error('extension.required.not.installed', $name);
             $ok = false;
         } else {
             if ($this->verbose) {
                 $this->ok('extension.required.installed', $name);
             }
         }
     }
     if (count($this->databases)) {
         $driversInfos = jDbParameters::getDriversInfosList();
         $req = $this->dbRequired ? 'required' : 'optional';
         $okdb = false;
         array_combine($this->databases, array_fill(0, count($this->databases), false));
         $alreadyExtensionsChecked = array();
         $okdatabases = array();
         foreach ($this->databases as $name) {
             foreach ($driversInfos as $driverInfo) {
                 list($dbType, $nativeExt, $pdoExt, $jdbDriver, $pdoDriver) = $driverInfo;
                 if ($name == $dbType || $name == $nativeExt || $name == $pdoDriver) {
                     if (extension_loaded($nativeExt)) {
                         if (!isset($alreadyExtensionsChecked[$nativeExt])) {
                             if ($this->verbose) {
                                 $this->ok('extension.installed', $nativeExt);
                             }
                             $alreadyExtensionsChecked[$nativeExt] = true;
                             $okdb = true;
                             $okdatabases[$name] = true;
                         }
                     } else {
                         if (!isset($alreadyExtensionsChecked[$nativeExt])) {
                             if ($this->verbose) {
                                 $this->notice('extension.not.installed', $nativeExt);
                             }
                             $alreadyExtensionsChecked[$nativeExt] = false;
                         }
                     }
                     if (extension_loaded($pdoExt)) {
                         if (!isset($alreadyExtensionsChecked[$pdoExt])) {
                             if ($this->verbose) {
                                 $this->ok('extension.installed', $pdoExt);
                             }
                             $alreadyExtensionsChecked[$pdoExt] = true;
                             $okdb = true;
                             $okdatabases[$name] = true;
                         }
                     } else {
                         if (!isset($alreadyExtensionsChecked[$pdoExt])) {
                             if ($this->verbose) {
                                 $this->notice('extension.not.installed', $pdoExt);
                             }
                             $alreadyExtensionsChecked[$pdoExt] = false;
                         }
                     }
                 }
             }
         }
         if ($this->dbRequired) {
             if ($okdb) {
                 $this->ok('extension.database.ok', implode(',', array_keys($okdatabases)));
             } else {
                 $this->error('extension.database.missing');
                 $ok = false;
             }
         } else {
             if ($okdb) {
                 $this->ok('extension.database.ok2', implode(',', array_keys($okdatabases)));
             } else {
                 $this->notice('extension.database.missing2');
             }
         }
     }
     foreach ($this->otherExtensions as $name => $required) {
         $req = $required ? 'required' : 'optional';
         if (!extension_loaded($name)) {
             if ($required) {
                 $this->error('extension.' . $req . '.not.installed', $name);
                 $ok = false;
             } else {
                 $this->notice('extension.' . $req . '.not.installed', $name);
             }
         } else {
             if ($this->verbose) {
                 $this->ok('extension.' . $req . '.installed', $name);
             }
         }
     }
     if ($ok) {
         $this->ok('extensions.required.ok');
     }
     return $ok;
 }
コード例 #3
0
ファイル: jdb.profiles.php プロジェクト: mdouchin/jelix
 protected function consolidate($profile)
 {
     $parameters = new jDbParameters($profile);
     return $parameters->getParameters();
 }