diff options
-rw-r--r-- | config/config.ini.sample.php | 1 | ||||
-rw-r--r-- | core/Db/Mysqli.php | 8 | ||||
-rw-r--r-- | core/Piwik.php | 4 | ||||
-rw-r--r-- | index.php | 11 | ||||
-rw-r--r-- | lang/en.php | 12 | ||||
-rw-r--r-- | plugins/Dashboard/Dashboard.php | 2 | ||||
-rw-r--r-- | plugins/ExampleFeedburner/ExampleFeedburner.php | 2 | ||||
-rw-r--r-- | plugins/Installation/Controller.php | 102 | ||||
-rw-r--r-- | plugins/Installation/FormDatabaseSetup.php | 12 | ||||
-rw-r--r-- | plugins/Installation/FormFirstWebsiteSetup.php | 4 | ||||
-rw-r--r-- | plugins/Installation/templates/databaseCheck.tpl | 34 | ||||
-rw-r--r-- | plugins/Installation/templates/tablesCreation.tpl | 13 | ||||
-rw-r--r-- | plugins/LanguagesManager/LanguagesManager.php | 6 |
13 files changed, 150 insertions, 61 deletions
diff --git a/config/config.ini.sample.php b/config/config.ini.sample.php index 1195f55753..f2604435ce 100644 --- a/config/config.ini.sample.php +++ b/config/config.ini.sample.php @@ -17,3 +17,4 @@ password = datatabasePassword dbname = databaseName adapter = PDO_MYSQL ; PDO_MYSQL, MYSQLI, or PDO_PGSQL tables_prefix = piwik_ +;charset = utf8 diff --git a/core/Db/Mysqli.php b/core/Db/Mysqli.php index 6cada84ac5..2bb885f4cc 100644 --- a/core/Db/Mysqli.php +++ b/core/Db/Mysqli.php @@ -81,9 +81,13 @@ class Piwik_Db_Mysqli extends Zend_Db_Adapter_Mysqli implements Piwik_Db_iAdapte */ public function isErrNo($e, $errno) { - if(is_null($this->_connection) && preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) + if(is_null($this->_connection)) { - return $match[1] == $errno; + if(preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) + { + return $match[1] == $errno; + } + return mysqli_connect_errno() == $errno; } return mysqli_errno($this->_connection) == $errno; diff --git a/core/Piwik.php b/core/Piwik.php index af7c5f083c..ed700b74d0 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -1469,11 +1469,13 @@ class Piwik unset($dbInfos['port']); } + $adapter = $dbInfos['adapter']; + // not used by Zend Framework unset($dbInfos['tables_prefix']); unset($dbInfos['adapter']); - $db = Piwik_Db::factory($config->database->adapter, $dbInfos); + $db = Piwik_Db::factory($adapter, $dbInfos); $db->getConnection(); Zend_Db_Table::setDefaultAdapter($db); @@ -52,13 +52,22 @@ if(ini_get('session.save_handler') == 'user') } if(ini_get('session.save_handler') == 'files') { - if(ini_get('safe_mode') || ini_get('open_basedir') || !@is_writable(ini_get('session.save_path'))) + $sessionPath = ini_get('session.save_path'); + if(ini_get('safe_mode') || ini_get('open_basedir') || empty($sessionPath) || !@is_writable($sessionPath)) { $sessionPath = PIWIK_USER_PATH . '/tmp/sessions'; @ini_set('session.save_path', $sessionPath); if(!is_dir($sessionPath)) { @mkdir($sessionPath, 0755, true); + if(!is_dir($sessionPath)) + { + die("Error: Unable to mkdir $sessionPath"); + } + } + else if(!@is_writable($sessionPath)) + { + die("Error: $sessionPath is not writable"); } } } diff --git a/lang/en.php b/lang/en.php index f4dea525b9..57823652d7 100644 --- a/lang/en.php +++ b/lang/en.php @@ -706,7 +706,17 @@ $translations = array( 'Installation_PercentDone' => '%s %% Done', 'Installation_NoConfigFound' => 'The Piwik configuration file couldn\'t be found and you are trying to access a Piwik page.<br /><b> » You can <a href=\'index.php\'>install Piwik now</a></b><br /><small>If you installed Piwik before and have some tables in your DB, don\'t worry, you can reuse the same tables and keep your existing data!</small>', 'Installation_DatabaseSetup' => 'Database setup', + 'Installation_DatabaseSetupServer' => 'database server', + 'Installation_DatabaseSetupLogin' => 'login', + 'Installation_DatabaseSetupPassword' => 'password', + 'Installation_DatabaseSetupDatabaseName' => 'database name', + 'Installation_DatabaseSetupTablePrefix' => 'table prefix', + 'Installation_DatabaseSetupAdapter' => 'adapter', 'Installation_DatabaseErrorConnect' => 'Error while trying to connect to the database server', + 'Installation_DatabaseCheck' => 'Database check', + 'Installation_DatabaseServerVersion' => 'Database server version', + 'Installation_DatabaseCreation' => 'Database creation', + 'Installation_DatabaseClientCharset' => 'Database client character set', 'Installation_ConnectionCharacterSetNotUtf8' => 'Client connection to the database server is not UTF8', 'Installation_JsTag' => 'JavaScript tag', 'Installation_JsTagHelp' => '<p>To count all visitors, you must insert the JavaScript code on all of your pages.</p><p>Your pages do not have to be made with PHP, Piwik will work on all kinds of pages (whether it is HTML, ASP, Perl or any other languages).</p><p>Here is the code you have to insert: (copy and paste on all your pages) </p>', @@ -716,6 +726,8 @@ $translations = array( 'Installation_CongratulationsHelp' => '<p>Congratulations! Your Piwik installation is complete.</p><p>Make sure your JavaScript code is entered on your pages, and wait for your first visitors!</p>', 'Installation_ContinueToPiwik' => 'Continue to Piwik', 'Installation_SetupWebsite' => 'Setup a website', + 'Installation_SetupWebSiteName' => 'website name', + 'Installation_SetupWebSiteURL' => 'website URL', 'Installation_SetupWebsiteError' => 'There was an error when adding the website', 'Installation_SetupWebsiteSetupSuccess' => 'Website %s created with success!', 'Installation_GeneralSetup' => 'General Setup', diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 5e977160ea..bfa72af4bc 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -60,7 +60,7 @@ class Piwik_Dashboard extends Piwik_Plugin PRIMARY KEY ( login , iddashboard ) ) DEFAULT CHARSET=utf8 " ; Piwik_Exec($sql); - } catch(Zend_Db_Statement_Exception $e){ + } catch(Exception $e){ // mysql code error 1050:table already exists // see bug #153 http://dev.piwik.org/trac/ticket/153 if(!Zend_Registry::get('db')->isErrNo($e, '1050')) diff --git a/plugins/ExampleFeedburner/ExampleFeedburner.php b/plugins/ExampleFeedburner/ExampleFeedburner.php index 5a1458e13f..2f8adbd3e2 100644 --- a/plugins/ExampleFeedburner/ExampleFeedburner.php +++ b/plugins/ExampleFeedburner/ExampleFeedburner.php @@ -31,7 +31,7 @@ class Piwik_ExampleFeedburner extends Piwik_Plugin { try{ Piwik_Exec('ALTER TABLE '.Piwik::prefixTable('site'). " ADD `feedburnerName` VARCHAR( 100 ) DEFAULT NULL"); - } catch(Zend_Db_Statement_Exception $e){ + } catch(Exception $e){ // mysql code error 1060: column already exists // if there is another error we throw the exception, otherwise it is OK as we are simply reinstalling the plugin if(!Zend_Registry::get('db')->isErrNo($e, '1060')) diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index 659dc6a673..cf7eb86a94 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -21,6 +21,7 @@ class Piwik_Installation_Controller extends Piwik_Controller 'welcome' => 'Installation_Welcome', 'systemCheck' => 'Installation_SystemCheck', 'databaseSetup' => 'Installation_DatabaseSetup', + 'databaseCheck' => 'Installation_DatabaseCheck', 'tablesCreation' => 'Installation_Tables', 'generalSetup' => 'Installation_GeneralSetup', 'firstWebsiteSetup' => 'Installation_SetupWebsite', @@ -153,6 +154,7 @@ class Piwik_Installation_Controller extends Piwik_Controller try{ try { Piwik::createDatabaseObject($dbInfos); + $this->session->databaseCreated = true; } catch (Zend_Db_Adapter_Exception $e) { $db = Piwik_Db::factory($adapter, $dbInfos); @@ -167,11 +169,12 @@ class Piwik_Installation_Controller extends Piwik_Controller } else { - throw $e; + throw $e; } } Piwik::checkDatabaseVersion(); + $this->session->databaseVersionOk = true; $this->session->db_infos = $dbInfos; $this->redirectToNextStep( __FUNCTION__ ); @@ -186,6 +189,42 @@ class Piwik_Installation_Controller extends Piwik_Controller echo $view->render(); } + function databaseCheck() + { + $this->checkPreviousStepIsValid( __FUNCTION__ ); + + $view = new Piwik_Installation_View( + $this->pathView . 'databaseCheck.tpl', + $this->getInstallationSteps(), + __FUNCTION__ + ); + $this->skipThisStep( __FUNCTION__ ); + + if(isset($this->session->databaseVersionOk) + && $this->session->databaseVersionOk === true) + { + $view->databaseVersionOk = true; + } + + if(isset($this->session->databaseCreated) + && $this->session->databaseCreated === true) + { + $view->databaseName = $this->session->db_infos['dbname']; + $view->databaseCreated = true; + } + + $this->createDbFromSessionInformation(); + if(!Piwik::isDatabaseConnectionUTF8()) + { + $view->charsetWarning = true; + } + + $view->showNextStep = true; + $this->session->currentStepDone = __FUNCTION__; + + echo $view->render(); + } + function tablesCreation() { $this->checkPreviousStepIsValid( __FUNCTION__ ); @@ -211,11 +250,6 @@ class Piwik_Installation_Controller extends Piwik_Controller $this->session->skipThisStep = $tmp; } - if(!Piwik::isDatabaseConnectionUTF8()) - { -// $view->charsetWarning = true; - } - $tablesInstalled = Piwik::getTablesInstalled(); $tablesToInstall = Piwik::getTablesNames(); $view->tablesInstalled = ''; @@ -226,14 +260,20 @@ class Piwik_Installation_Controller extends Piwik_Controller $minimumCountPiwikTables = 12; $baseTablesInstalled = preg_grep('/archive_numeric|archive_blob/', $tablesInstalled, PREG_GREP_INVERT); - if(count($baseTablesInstalled) >= $minimumCountPiwikTables ) + + Piwik::createAccessObject(); + Piwik::setUserIsSuperUser(); + + if(count($baseTablesInstalled) >= $minimumCountPiwikTables && + count(Piwik_SitesManager_API::getAllSitesId()) > 0 && + count(Piwik_UsersManager_API::getUsers()) > 0) { $view->showReuseExistingTables = true; // when the user reuses the same tables we skip the website creation step // workaround ZF-1743 $tmp = $this->session->skipThisStep; $tmp['firstWebsiteSetup'] = true; - $tmp['displayJavascriptCode'] = true; + $tmp['displayJavascriptCode'] = true; $this->session->skipThisStep = $tmp; } } @@ -248,14 +288,6 @@ class Piwik_Installation_Controller extends Piwik_Controller $view->showNextStep = true; } - if(isset($this->session->databaseCreated) - && $this->session->databaseCreated === true) - { - $view->databaseName = $this->session->db_infos['dbname']; - $view->databaseCreated = true; - unset($this->session->databaseCreated); - } - $this->session->currentStepDone = __FUNCTION__; echo $view->render(); } @@ -375,7 +407,6 @@ class Piwik_Installation_Controller extends Piwik_Controller $this->session->firstWebsiteSetupSuccessMessage = true; } - $view->websiteName = urldecode($this->session->site_name); $jsTag = Piwik::getJavascriptCode($this->session->site_idSite, Piwik_Url::getCurrentUrlWithoutFileName()); @@ -397,11 +428,15 @@ class Piwik_Installation_Controller extends Piwik_Controller __FUNCTION__ ); $this->skipThisStep( __FUNCTION__ ); - $this->writeConfigFileFromSession(); - $this->session->currentStepDone = __FUNCTION__; + if(!file_exists(Piwik_Config::getDefaultUserConfigPath())) + { + $this->writeConfigFileFromSession(); + } + $view->showNextStep = false; + $this->session->currentStepDone = __FUNCTION__; echo $view->render(); } @@ -425,6 +460,8 @@ class Piwik_Installation_Controller extends Piwik_Controller $config = Zend_Registry::get('config'); $config->superuser = $this->session->superuser_infos; $config->database = $this->session->db_infos; + unset($this->session->superuser_infos); + unset($this->session->db_infos); } /** @@ -436,20 +473,21 @@ class Piwik_Installation_Controller extends Piwik_Controller { $error = false; - // first we make sure that the config file is not present, ie. Installation state is expected - try { - $config = new Piwik_Config(); - $config->init(); - $error = true; - } catch(Exception $e) { - } - if(empty($this->session->currentStepDone)) { $error = true; } + else if($currentStep == 'finished' && $this->session->currentStepDone == 'finished') + { + // ok to refresh this page or use language selector + } else { + if(file_exists(Piwik_Config::getDefaultUserConfigPath())) + { + $error = true; + } + $steps = array_keys($this->steps); // the currentStep @@ -562,13 +600,13 @@ class Piwik_Installation_Controller extends Piwik_Controller $infos['gd_ok'] = false; if (in_array('gd', $extensions)) { - $gdInfo = gd_info(); + $gdInfo = gd_info(); $infos['gd_version'] = $gdInfo['GD Version']; - preg_match('/([0-9]{1})/', $gdInfo['GD Version'], $gdVersion); - if($gdVersion[0] >= 2) - { + preg_match('/([0-9]{1})/', $gdInfo['GD Version'], $gdVersion); + if($gdVersion[0] >= 2) + { $infos['gd_ok'] = true; - } + } } $infos['serverVersion'] = addslashes($_SERVER['SERVER_SOFTWARE']); diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php index 2669cbcc5f..9185954ce9 100644 --- a/plugins/Installation/FormDatabaseSetup.php +++ b/plugins/Installation/FormDatabaseSetup.php @@ -26,12 +26,12 @@ class Piwik_Installation_FormDatabaseSetup extends Piwik_Form } $formElements = array( - array('text', 'host', 'mysql server', 'value='.'localhost'), - array('text', 'username', 'login'), - array('password', 'password', 'password'), - array('text', 'dbname', 'database name'), - array('text', 'tables_prefix', 'table prefix', 'value='.'piwik_'), - array('select', 'adapter', 'adapter', $adapters), + array('text', 'host', Piwik_Translate('Installation_DatabaseSetupServer'), 'value='.'localhost'), + array('text', 'username', Piwik_Translate('Installation_DatabaseSetupLogin')), + array('password', 'password', Piwik_Translate('Installation_DatabaseSetupPassword')), + array('text', 'dbname', Piwik_Translate('Installation_DatabaseSetupDatabaseName')), + array('text', 'tables_prefix', Piwik_Translate('Installation_DatabaseSetupTablePrefix'), 'value='.'piwik_'), + array('select', 'adapter', Piwik_Translate('Installation_DatabaseSetupAdapter'), $adapters), ); $this->addElements( $formElements ); diff --git a/plugins/Installation/FormFirstWebsiteSetup.php b/plugins/Installation/FormFirstWebsiteSetup.php index 65f2666263..a38eae728a 100644 --- a/plugins/Installation/FormFirstWebsiteSetup.php +++ b/plugins/Installation/FormFirstWebsiteSetup.php @@ -24,8 +24,8 @@ class Piwik_Installation_FormFirstWebsiteSetup extends Piwik_Form $javascriptOnClickUrlExample = "\"javascript:if(this.value=='$urlExample'){this.value='http://';} this.style.color='black';\""; $formElements = array( - array('text', 'siteName', 'website name'), - array('text', 'url', 'website URL', "style='color:rgb(153, 153, 153);' value=$urlExample onfocus=".$javascriptOnClickUrlExample." onclick=".$javascriptOnClickUrlExample), + array('text', 'siteName', Piwik_Translate('Installation_SetupWebSiteName')), + array('text', 'url', Piwik_Translate('Installation_SetupWebSiteURL'), "style='color:rgb(153, 153, 153);' value=$urlExample onfocus=".$javascriptOnClickUrlExample." onclick=".$javascriptOnClickUrlExample), ); $this->addElements( $formElements ); diff --git a/plugins/Installation/templates/databaseCheck.tpl b/plugins/Installation/templates/databaseCheck.tpl new file mode 100644 index 0000000000..3a82e4c5ba --- /dev/null +++ b/plugins/Installation/templates/databaseCheck.tpl @@ -0,0 +1,34 @@ +{assign var=ok value="<img src='themes/default/images/ok.png' />"} +{assign var=error value="<img src='themes/default/images/error.png' />"} +{assign var=warning value="<img src='themes/default/images/warning.png' />"} +{assign var=link value="<img src='themes/default/images/link.gif' />"} + +<h1>{'Installation_DatabaseCheck'|translate}</h1> + +<table class="infosServer"> + <tr> + <td class="label">{'Installation_DatabaseServerVersion'|translate}</td> + <td>{if isset($databaseVersionOk)}{$ok}{else}{$error}{/if}</td> + </tr> + <tr> + <td class="label">{'Installation_DatabaseCreation'|translate}</td> + <td>{if isset($databaseCreated)}{$ok}{else}{$error}{/if}</td> + </tr> + <tr> + <td class="label">{'Installation_DatabaseClientCharset'|translate}</td> + <td>{if isset($charsetWarning)}{$warning}{else}utf8 {$ok}{/if}</td> + </tr> +{if isset($charsetWarning)} + <tr> + <td colspan="2"> + <small> + <span style="color:orange">{'Installation_ConnectionCharacterSetNotUtf8'|translate}</span> + </small> + </td> + </tr> +{/if} +</table> + +<p> +{$link} <a href="http://piwik.org/docs/requirements/" target="_blank">{'Installation_Requirements'|translate}</a> +</p> diff --git a/plugins/Installation/templates/tablesCreation.tpl b/plugins/Installation/templates/tablesCreation.tpl index 8047bef92e..92f434754a 100644 --- a/plugins/Installation/templates/tablesCreation.tpl +++ b/plugins/Installation/templates/tablesCreation.tpl @@ -1,14 +1,8 @@ <h1>{'Installation_Tables'|translate}</h1> -{if isset($charsetWarning)} - <div class="warning">{'Installation_ConnectionCharacterSetNotUtf8'|translate} - <img src="themes/default/images/warning_medium.png"> - </div> -{/if} - {if isset($someTablesInstalled)} <div class="warning">{'Installation_TablesWithSameNamesFound'|translate:"<span id='linkToggle'>":"</span>"} - <img src="themes/default/images/warning_medium.png"> + <img src="themes/default/images/warning_medium.png" /> </div> <div id="toggle" style="display:none;color:#4F2410"><small><i>{'Installation_TablesFound'|translate}: <br />{$tablesInstalled} </i></small></div> @@ -28,11 +22,6 @@ <img src="themes/default/images/success_medium.png"></div> {/if} -{if isset($databaseCreated)} - <div class="success"> {'Installation_DatabaseCreatedSuccess'|translate:"'$databaseName'"} - <img src="themes/default/images/success_medium.png"></div> -{/if} - {if isset($tablesCreated)} <div class="success"> {'Installation_TablesCreatedSuccess'|translate} <img src="themes/default/images/success_medium.png"></div> diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index 8db9f2e353..34112a1caf 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -63,7 +63,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin } /** - * @throws Zend_Db_Statement_Exception if non-recoverable error + * @throws Exception if non-recoverable error */ public function install() { @@ -75,7 +75,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin PRIMARY KEY ( login ) ) DEFAULT CHARSET=utf8 " ; Piwik_Exec($sql); - } catch(Zend_Db_Statement_Exception $e){ + } catch(Exception $e){ // mysql code error 1050:table already exists // see bug #153 http://dev.piwik.org/trac/ticket/153 if(!Zend_Registry::get('db')->isErrNo($e, '1050')) @@ -86,7 +86,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin } /** - * @throws Zend_Db_Statement_Exception if non-recoverable error + * @throws Exception if non-recoverable error */ public function uninstall() { |