Beispiel #1
0
 public static function installWithoutDemo(JO_Db_Adapter_Abstract $db)
 {
     mysql_connect($db->getConfig('host'), $db->getConfig('username'), $db->getConfig('password'));
     mysql_select_db($db->getConfig('dbname'));
     mysql_set_charset('utf8');
     $structure = APPLICATION_PATH . '/modules/install/structure.sql';
     if (!file_exists($structure)) {
         return false;
     }
     $queryes = self::getQueryes(file($structure));
     $results = array();
     foreach ($queryes as $query) {
         if (trim($query)) {
             try {
                 /*$results[] = */
                 (bool) mysql_query($query);
             } catch (JO_Exception $e) {
                 /*$results[] = false;*/
             }
         }
     }
     $request = JO_Request::getInstance();
     $results[] = $db->insert('users', array('user_id' => 1, 'username' => $request->getPost('username'), 'password' => md5(md5($request->getPost('password'))), 'register_datetime' => new JO_Db_Expr('NOW()'), 'status' => 'activate', 'groups' => 'a:1:{i:2;s:2:"on";}'));
     /*$results[] = */
     $db->update('system', array('value' => $request->getPost('admin_mail')), array('`key` = ?' => 'admin_mail'));
     /*$results[] = */
     $db->update('system', array('value' => $request->getPost('report_mail')), array('`key` = ?' => 'report_mail'));
     if (!in_array(false, $results)) {
         $db_set = "\r\r\n\tdb.adapter = \"MYSQLi\"\r\r\n\tdb.params.host = \"" . $db->getConfig('host') . "\"\r\r\n\tdb.params.username = \"" . $db->getConfig('username') . "\"\r\r\n\tdb.params.password = \"" . $db->getConfig('password') . "\"\r\r\n\tdb.params.dbname = \"" . $db->getConfig('dbname') . "\"\r\r\n\tdb.params.charset =\"utf8\"";
         $results[] = (bool) @file_put_contents(APPLICATION_PATH . '/config/config_db.ini', $db_set);
     }
     return !in_array(false, $results);
 }
Beispiel #2
0
 /**
  * Initializes metadata.
  *
  * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
  * information. Returns true if and only if the metadata are loaded from cache.
  *
  * @return boolean
  * @throws JO_Db_Table_Exception
  */
 protected function _setupMetadata()
 {
     if ($this->metadataCacheInClass() && count($this->_metadata) > 0) {
         return true;
     }
     // Assume that metadata will be loaded from cache
     $isMetadataFromCache = true;
     // If $this has no metadata cache but the class has a default metadata cache
     if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) {
         // Make $this use the default metadata cache of the class
         $this->_setMetadataCache(self::$_defaultMetadataCache);
     }
     // If $this has a metadata cache
     if (null !== $this->_metadataCache) {
         // Define the cache identifier where the metadata are saved
         //get db configuration
         $dbConfig = $this->_db->getConfig();
         // Define the cache identifier where the metadata are saved
         $cacheId = md5((isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : null) . (isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : null) . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name);
     }
     // If $this has no metadata cache or metadata cache misses
     if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->get($cacheId))) {
         // Metadata are not loaded from cache
         $isMetadataFromCache = false;
         // Fetch metadata from the adapter's describeTable() method
         $metadata = $this->_db->describeTable($this->_name, $this->_schema);
         // If $this has a metadata cache, then cache the metadata
         if (null !== $this->_metadataCache && !$this->_metadataCache->add($cacheId)) {
             trigger_error('Failed saving metadata to metadataCache', E_USER_NOTICE);
         }
     }
     // Assign the metadata to $this
     $this->_metadata = $metadata;
     // Return whether the metadata were loaded from cache
     return $isMetadataFromCache;
 }