Exemplo n.º 1
0
 public function _initDatabase()
 {
     $params = array('host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'logs');
     $db = Zend_db::factory('Pdo_Mysql', $params);
     Zend_Db_Table::setDefaultAdapter($db);
     Zend_Registry::set('db_params', $params);
     Zend_Registry::set('db', $db);
 }
Exemplo n.º 2
0
 /**
  * Return the module ID.
  *
  * @param string $module The name of the module.
  *
  * @return integer The module ID in P6.
  */
 private function _getModuleId($module)
 {
     if (isset($this->_modules[$module])) {
         return $this->_modules[$module];
     } else {
         // Global modules
         $select = $this->_db->select()->from('module')->where('name = ?', (string) $module);
         $stmt = $this->_db->query($select);
         $rows = $stmt->fetchAll();
         if (isset($rows[0])) {
             $this->_modules[$rows[0]['name']] = $rows[0]['id'];
             return $rows[0]['id'];
         } else {
             return 0;
         }
     }
 }
 protected function _setupVersion3($fromPath, $toPath)
 {
     // Check from path exists
     if (!is_dir($fromPath)) {
         throw new Engine_Exception('Specified path is not a version 3 installation');
     }
     // Check to path exists
     if (!is_dir($toPath)) {
         throw new Engine_Exception('Specified path is not a version 4 installation');
     }
     // Check from database config file
     $fromDbConfigFile = $fromPath . '/include/database_config.php';
     if (!is_file($fromDbConfigFile)) {
         throw new Engine_Exception('Version 3 database config was not found.');
     }
     // Check to database config file
     $toDbConfigFile = $toPath . '/application/settings/database.php';
     if (!is_file($toDbConfigFile)) {
         throw new Engine_Exception('Version 4 database config was not found.');
     }
     // Get from database config
     $fromDbConfig = $this->_importValues($fromDbConfigFile);
     if (!$fromDbConfig || !is_array($fromDbConfig) || empty($fromDbConfig['database_host']) || empty($fromDbConfig['database_username']) || empty($fromDbConfig['database_password']) || empty($fromDbConfig['database_name'])) {
         throw new Engine_Exception('Invalid version 3 database configuration.');
     }
     // Get to database config
     $toDbConfig = (include $toDbConfigFile);
     if (!is_array($toDbConfig) || empty($toDbConfig['adapter']) || empty($toDbConfig['params'])) {
         throw new Engine_Exception('Invalid version 4 database configuration.');
     }
     // Make from adapter and check connection
     $fromDbConfig = array('adapter' => $toDbConfig['adapter'], 'params' => array('host' => $fromDbConfig['database_host'], 'username' => $fromDbConfig['database_username'], 'password' => $fromDbConfig['database_password'], 'dbname' => $fromDbConfig['database_name'], 'charset' => $toDbConfig['params']['charset'], 'adapterNamespace' => $toDbConfig['params']['adapterNamespace']));
     try {
         $fromDb = Zend_db::factory($fromDbConfig['adapter'], $fromDbConfig['params']);
         $fromDb->getServerVersion();
         // Forces connection
     } catch (Exception $e) {
         throw new Engine_Exception('Database connection error: ' . $e->getMessage());
     }
     // Make to adapter and check connection
     try {
         $toDb = Zend_db::factory($toDbConfig['adapter'], $toDbConfig['params']);
         $toDb->getServerVersion();
         // Forces connection
     } catch (Exception $e) {
         throw new Engine_Exception('Database connection error: ' . $e->getMessage());
     }
     // Save all info for later
     $this->_fromDb = $fromDb;
     $this->_fromPath = $fromPath;
     $this->_toDb = $toDb;
     $this->_toPath = $toPath;
 }