/** */ public function step2Action() { if (file_exists(LOCAL_CONFIGS_PATH . '/database.local.ini')) { $this->redirect('/install/step3'); } $this->view->header = 'Step 2: Database Configuration'; $databases = array('mysql', 'pgsql', 'sqlite'); $this->view->databaseType = array(); foreach ($databases as $database) { if (!extension_loaded('pdo_' . $database) || !file_exists(BASE_PATH . '/core/database/' . $database)) { unset($database); } else { $form = $this->Form->Install->createDBForm(); $host = $form->getElement('host'); $port = $form->getElement('port'); $username = $form->getElement('username'); switch ($database) { case 'mysql': $port->setValue('3306'); $username->setValue('root'); break; case 'pgsql': $port->setValue('5432'); $username->setValue('postgres'); break; case 'sqlite': $host->setValue(''); $port->setValue(''); $username->setValue(''); break; default: break; } $this->view->databaseType[$database] = $this->getFormAsArray($form); } } $this->view->basePath = BASE_PATH; if ($this->_request->isPost()) { $type = $this->getParam('type'); $form = $this->Form->Install->createDBForm(); if ($form->isValid($this->getRequest()->getPost())) { require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php'; $upgradeComponent = new UpgradeComponent(); $upgradeComponent->dir = BASE_PATH . '/core/database/' . $type; $upgradeComponent->init = true; $sqlFile = $upgradeComponent->getNewestVersion(true); $sqlFile = BASE_PATH . '/core/database/' . $type . '/' . $sqlFile . '.sql'; if (!isset($sqlFile) || !file_exists($sqlFile)) { throw new Zend_Exception('Unable to find sql file'); } $dbtype = 'PDO_' . strtoupper($type); $version = str_replace('.sql', '', basename($sqlFile)); $options = array('allowModifications' => true); $databaseConfig = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/database.ini', null, $options); $databaseConfig->production->database->adapter = $dbtype; $databaseConfig->production->database->params->host = $form->getValue('host'); $databaseConfig->production->database->params->port = $form->getValue('port'); $databaseConfig->production->database->params->unix_socket = $form->getValue('unix_socket'); $databaseConfig->production->database->params->dbname = $form->getValue('dbname'); $databaseConfig->production->database->params->username = $form->getValue('username'); $databaseConfig->production->database->params->password = $form->getValue('password'); $databaseConfig->production->version = $version; $databaseConfig->development->database->adapter = $dbtype; $databaseConfig->development->database->params->host = $form->getValue('host'); $databaseConfig->development->database->params->port = $form->getValue('port'); $databaseConfig->development->database->params->unix_socket = $form->getValue('unix_socket'); $databaseConfig->development->database->params->dbname = $form->getValue('dbname'); $databaseConfig->development->database->params->username = $form->getValue('username'); $databaseConfig->development->database->params->password = $form->getValue('password'); $databaseConfig->development->version = $version; $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($databaseConfig); $writer->setFilename(LOCAL_CONFIGS_PATH . '/database.local.ini'); $writer->write(); $driverOptions = array(); $params = array('dbname' => $form->getValue('dbname'), 'driver_options' => $driverOptions); if ($dbtype != 'PDO_SQLITE') { $params['username'] = $form->getValue('username'); $params['password'] = $form->getValue('password'); $unixsocket = $form->getValue('unix_socket'); if ($unixsocket) { $params['unix_socket'] = $unixsocket; } else { $params['host'] = $form->getValue('host'); $params['port'] = $form->getValue('port'); } } $db = Zend_Db::factory($dbtype, $params); Zend_Db_Table::setDefaultAdapter($db); Zend_Registry::set('dbAdapter', $db); $this->Component->Utility->run_sql_from_file($db, $sqlFile); // Must generate and store our password salt before we create our first user $options = array('allowModifications' => true); $applicationConfig = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/application.ini', null, $options); $prefix = $this->Component->Random->generateString(32); $applicationConfig->global->password->prefix = $prefix; $applicationConfig->global->gravatar = $form->getValue('gravatar'); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($applicationConfig); $writer->setFilename(LOCAL_CONFIGS_PATH . '/application.local.ini'); $writer->write(); $configGlobal = new Zend_Config_Ini(LOCAL_CONFIGS_PATH . '/application.local.ini', 'global'); Zend_Registry::set('configGlobal', $configGlobal); $configDatabase = new Zend_Config_Ini(LOCAL_CONFIGS_PATH . '/database.local.ini', 'production'); Zend_Registry::set('configDatabase', $configDatabase); require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php'; $upgradeComponent = new UpgradeComponent(); $upgradeComponent->initUpgrade('core', $db, $dbtype); $upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile))); session_start(); require_once BASE_PATH . '/core/models/pdo/UserModel.php'; $userModel = new UserModel(); $this->userSession->Dao = $userModel->createUser($form->getValue('email'), $form->getValue('userpassword1'), $form->getValue('firstname'), $form->getValue('lastname'), 1); // create default assetstore $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName('Local'); $assetstoreDao->setPath($this->getDataDirectory('assetstore')); $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL); $this->Assetstore = new AssetstoreModel(); // reset Database adapter $this->Assetstore->save($assetstoreDao); $this->redirect('/install/step3'); } } }
/** * Install and upgrade core. * * @param Zend_Db_Adapter_Abstract $db * @param string $dbType * @param UtilityComponent $utilityComponent * @throws Zend_Exception */ function installCore($db, $dbType, $utilityComponent) { require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php'; $upgradeComponent = new UpgradeComponent(); $upgradeComponent->dir = BASE_PATH . '/core/database/' . $dbType; $upgradeComponent->init = true; $newestVersion = $upgradeComponent->getNewestVersion(true); $sqlFile = BASE_PATH . '/core/database/' . $dbType . '/' . $newestVersion . '.sql'; if (!isset($sqlFile) || !file_exists($sqlFile)) { throw new Zend_Exception('Unable to find SQL file: ' . $sqlFile); } switch ($dbType) { case 'mysql': $utilityComponent->run_sql_from_file($db, $sqlFile); $upgradeDbType = 'PDO_MYSQL'; break; case 'pgsql': $utilityComponent->run_sql_from_file($db, $sqlFile); $upgradeDbType = 'PDO_PGSQL'; break; case 'sqlite': $utilityComponent->run_sql_from_file($db, $sqlFile); $upgradeDbType = 'PDO_SQLITE'; break; default: throw new Zend_Exception('Unknown database type: ' . $dbType); break; } $options = array('allowModifications' => true); $databaseConfig = new Zend_Config_Ini(BASE_PATH . '/tests/configs/lock.' . $dbType . '.ini', null, $options); $databaseConfig->testing->version = $newestVersion; $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($databaseConfig); $writer->setFilename(BASE_PATH . '/tests/configs/lock.' . $dbType . '.ini'); $writer->write(); $upgradeComponent->initUpgrade('core', $db, $upgradeDbType); $upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile)), true); }