Example #1
0
 function install()
 {
     if (!$this->firstDbExec()) {
         return;
     }
     // ---  install table for session storage if needed
     $sessionStorage = $this->config->getValue("storage", "sessions");
     $sessionDao = $this->config->getValue("dao_selector", "sessions");
     $sessionProfile = $this->config->getValue("dao_db_profile", "sessions");
     if ($sessionStorage == "dao" && $sessionDao == "jelix~jsession") {
         $this->execSQLScript('sql/install_jsession.schema');
     }
     // --- install table for jCache if needed
     $cachefile = jApp::configPath('profiles.ini.php');
     if (file_exists($cachefile)) {
         $ini = new jIniFileModifier($cachefile);
         foreach ($ini->getSectionList() as $section) {
             if (substr($section, 0, 7) != 'jcache:') {
                 continue;
             }
             $driver = $ini->getValue('driver', $section);
             $dao = $ini->getValue('dao', $section);
             $this->useDbProfile($ini->getValue('dbprofile', $section));
             if ($driver == 'db' && $dao == 'jelix~jcache' && $this->firstExec('cachedb:' . $this->dbProfile)) {
                 $this->execSQLScript('sql/install_jcache.schema');
             }
         }
     }
 }
Example #2
0
 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=mysql\ndatabase=\nhost=localhost\nuser=\npassword=\npersistent = on\nforce_encoding = on\ntable_prefix=\n");
     }
     $ini = new jIniFileModifier($file);
     $data = 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());
     $profiles = $ini->getSectionList();
     $dbprofileslist = array();
     foreach ($profiles as $profile) {
         if (strpos($profile, 'jdb:') !== 0) {
             continue;
         }
         $dbprofileslist[] = $profile;
         $driver = $ini->getValue('driver', $profile);
         if ($driver == 'pdo') {
             $dsn = $ini->getValue('dsn', $profile);
             $data['driver'][$profile] = substr($dsn, 0, strpos($dsn, ':')) . '_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 {
             $usepdo = (bool) $ini->getValue('usepdo', $profile);
             $data['driver'][$profile] = $ini->getValue('driver', $profile) . ($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] = $ini->getValue('persistent', $profile);
         $force_encoding = $ini->getValue('force_encoding', $profile);
         if ($force_encoding === null) {
             $force_encoding = true;
         }
         $data['force_encoding'][$profile] = $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;
 }