From: <al...@us...> - 2008-08-19 22:36:51
|
Revision: 615 http://sciret.svn.sourceforge.net/sciret/?rev=615&view=rev Author: alpeb Date: 2008-08-19 22:36:48 +0000 (Tue, 19 Aug 2008) Log Message: ----------- More changes to use the Zend_Db abstraction, and updated the Zend Framework. Also added a logging facility. Modified Paths: -------------- trunk/actions/Install.php trunk/index.php Property Changed: ---------------- trunk/libs/ Modified: trunk/actions/Install.php =================================================================== --- trunk/actions/Install.php 2008-08-19 22:35:40 UTC (rev 614) +++ trunk/actions/Install.php 2008-08-19 22:36:48 UTC (rev 615) @@ -12,6 +12,7 @@ class Install extends Action { var $db; + var $config; function dispatch() { @@ -19,32 +20,49 @@ $_GET['step'] = 0; } + $this->config = Zend_Registry::get('config'); + switch ($_GET['step']) { case 0: Library::redirect(Library::getLink(array('view' => 'InstallEnterCredentials'))); break; case 1: - $this->db =& DB::DBFactory(DB_ENGINE, $_POST['host'], $_POST['username'], $_POST['password'], true); - if (!$this->db->connect()) { + $this->config->database->params->driver_options = array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true); + $this->config->database->params->host = $_POST['host']; + $this->config->database->params->dbname = null; + $this->config->database->params->username = $_POST['username']; + $this->config->database->params->password = $_POST['password']; + $this->db = Zend_Db::factory($this->config->database); + try { + $this->db->getConnection(); + } catch (Zend_Db_Adapter_Exception $e) { Library::redirect(Library::getLink(array('view' => 'InstallEnterCredentials', 'error' => urlencode($this->user->lang('Couldn\'t connect to database, please check your credentials.'))))); } $errors = array(); if (!$this->_isConfigWritable()) { - $errors[] = $this->user->lang('The config.php file must be writable'); + $errors[] = $this->user->lang('The config.ini.php file must be writable'); } if (!$this->_areUploadDirsWritable()) { $errors[] = $this->user->lang('All directories under the "uploads" and "uploads/editor" directories must be writable'); } - if ($this->db->isLowerThan41()) { + if ($this->_DBIsLowerThan41()) { $errors[] = $this->user->lang('You need a MySQL version no lower than 4.1'); } - if (!$this->db->selectDb($_POST['database'])) { - if (!$result = $this->db->createDB($_POST['database'])) { + $this->config->database->params->dbname = $_POST['database']; + $this->db = Zend_Db::factory($this->config->database); + try { + $this->db->getConnection(); + } catch (Zend_Db_Adapter_Exception $e) { + try { + $this->config->database->params->dbname = null; + // it looks like the following call attempts to create the DB + $this->db = Zend_Db::factory($this->config->database); + $this->db->getConnection(); + $stmt = $this->db->query("CREATE DATABASE `".$_POST['database']."`"); + } catch (Zend_Db_Adapter_Exception $e) { $errors[] = $this->user->lang('Couldn\'t create database. Please create it manually and try again.'); - } else { - $this->db->selectDb($_POST['database']); } } @@ -52,7 +70,14 @@ Library::redirect(Library::getLink(array('view' => 'InstallEnterCredentials', 'error' => urlencode(implode('<br />', $errors))))); } - $this->_writeConfig(DB_ENGINE, $_POST['host'], $_POST['database'], $_POST['username'], $_POST['password']); + $this->_writeConfig( $this->config, + $_POST['host'], + $_POST['database'], + $_POST['username'], + $_POST['password']); + + // finally, connect with all the parameters set + $this->db = Zend_Db::factory($this->config->database); $this->_runSQLFILE('final.sql'); if (isset($_POST['demodata']) && $_POST['demodata']) { $this->_runSQLFILE('sampleData.sql'); @@ -63,28 +88,17 @@ } // @access private - function _writeConfig($dbEngine, $dbHost, $dbName, $dbUserName, $dbPassword) { - $dbEngine = addslashes($dbEngine); - $dbHost = addslashes($dbHost); - $dbUserName = addslashes($dbUserName); - $dbPassword = addslashes($dbPassword); - $configStr = <<<ALP -<?php + function _writeConfig($config, $dbHost, $dbName, $dbUserName, $dbPassword) { + $config->database->params->host = $dbHost; + $config->database->params->dbname = $dbName; + $config->database->params->username = $dbUserName; + $config->database->params->password = $dbPassword; + $this->config = clone $config; + unset($config->database->params->driver_options); -define('DB_ENGINE', '$dbEngine'); -define('DB_HOST', '$dbHost'); -define('DB_NAME', '$dbName'); -define('DB_USER', '$dbUserName'); -define('DB_PASSWORD', '$dbPassword'); + $configStr = "<?php\n\n return " . var_export($config->toArray(), true) . ";\n\n?>"; -define('LANGUAGE_DEFAULT', 'English'); - -// set to > 0 to simulate latency -define('SLOWDOWN_SECS', 0); - -?> -ALP; - $fp = fopen(dirname(__FILE__).'/../config.php', 'w'); + $fp = fopen(dirname(__FILE__).'/../config.ini.php', 'w'); fwrite($fp, $configStr); fclose($fp); } @@ -104,7 +118,10 @@ $query .= $line; if ((substr($line, -1, 1) == ';' || feof($fp)) && $query != '') { - $this->db->query($query); + // I had to resort to a direct call because regexes inside the Zend Framework are segfaulting with the long queries in sampleData.sql + //$this->db->query($query); + $this->db->getConnection()->query($query); + $query = ''; } } @@ -113,7 +130,7 @@ function _isConfigWritable() { // is_writable() not working under windows - if (!$fp = @fopen(dirname(__FILE__).'/../config.php', 'a')) { + if (!$fp = @fopen(dirname(__FILE__).'/../config.ini.php', 'a')) { return false; } fclose($fp); @@ -135,6 +152,12 @@ return true; } + + private function _DBIsLowerThan41() { + $stmt = $this->db->query("SHOW VARIABLES LIKE 'version'"); + $row = $stmt->fetch(); + return (!$row['Value'] || preg_match('/^([0-3]\.|4\.0)/',$row['Value'])); + } } ?> Modified: trunk/index.php =================================================================== --- trunk/index.php 2008-08-19 22:35:40 UTC (rev 614) +++ trunk/index.php 2008-08-19 22:36:48 UTC (rev 615) @@ -9,6 +9,8 @@ * @packager TheGang */ +define('APP_DIR', dirname(__FILE__)); + // ERROR HANDLING error_reporting(E_ALL); ini_set('display_errors', 1); @@ -29,9 +31,27 @@ $times = explode(' ', microtime()); $GLOBALS['startTime'] = $times[0] + $times[1]; -$config = new Zend_Config_Ini(dirname(__FILE__). '/config.ini', null, array('allowModifications' => true)); +// use a config.ini.php with an array instead of a cleaner .ini file, because for an easy installation all files +// go under the web root, and a .ini file would be browsable +$config = new Zend_Config(require dirname(__FILE__). '/config.ini.php', array('allowModifications' => true)); Zend_Registry::set('config', $config); +/************************** +/* LOGGER +/**************************/ +$logger = new Zend_Log(); +if ($config->environment->loglevel > 0) { + $logger->addWriter(new Zend_Log_Writer_Stream(APP_DIR . '/log.txt')); + $logger->addFilter(new Zend_Log_Filter_Priority((int)$config->environment->loglevel)); +} +Zend_Registry::set('logger', $logger); + +$logger->log('REQUESTED URI: ' . $_SERVER['REQUEST_URI'], Zend_Log::INFO); + +if (isset($_POST) && $_POST) { + $logger->log('POST payload: ' . print_r($_POST, 1), Zend_Log::INFO); +} + require 'flowMap.php'; // MAGIC_QUOTES HANDLING Property changes on: trunk/libs ___________________________________________________________________ Modified: svn:externals - Zend http://framework.zend.com/svn/framework/standard/tags/release-1.5.2/library/Zend + Zend http://framework.zend.com/svn/framework/standard/tags/release-1.5.3/library/Zend This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |