function init() { $availableAdapters = Piwik_Db_Adapter::getAdapters(); $adapters = array(); foreach ($availableAdapters as $adapter => $port) { $adapters[$adapter] = $adapter; } $this->addElement('text', 'host')->setLabel(Piwik_Translate('Installation_DatabaseSetupServer'))->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupServer'))); $this->addElement('text', 'username')->setLabel(Piwik_Translate('Installation_DatabaseSetupLogin'))->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupLogin'))); $this->addElement('password', 'password')->setLabel(Piwik_Translate('Installation_DatabaseSetupPassword')); $this->addElement('text', 'dbname')->setLabel(Piwik_Translate('Installation_DatabaseSetupDatabaseName'))->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupDatabaseName'))); $this->addElement('text', 'tables_prefix')->setLabel(Piwik_Translate('Installation_DatabaseSetupTablePrefix')); $this->addElement('select', 'adapter')->setLabel(Piwik_Translate('Installation_DatabaseSetupAdapter'))->loadOptions($adapters)->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupAdapter'))); $this->addElement('submit', 'submit', array('value' => Piwik_Translate('General_Next') . ' »', 'class' => 'submit')); // default values $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('host' => '127.0.0.1', 'tables_prefix' => 'piwik_'))); }
/** * Creates database object based on form data. * * @return array The database connection info. Can be passed into Piwik::createDatabaseObject. */ public function createDatabaseObject() { $dbname = $this->getSubmitValue('dbname'); if (empty($dbname)) { throw new Exception("No database name"); } $adapter = $this->getSubmitValue('adapter'); $port = Piwik_Db_Adapter::getDefaultPortForAdapter($adapter); $dbInfos = array('host' => $this->getSubmitValue('host'), 'username' => $this->getSubmitValue('username'), 'password' => $this->getSubmitValue('password'), 'dbname' => $dbname, 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port); if (($portIndex = strpos($dbInfos['host'], '/')) !== false) { // unix_socket=/path/sock.n $dbInfos['port'] = substr($dbInfos['host'], $portIndex); $dbInfos['host'] = ''; } else { if (($portIndex = strpos($dbInfos['host'], ':')) !== false) { // host:port $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1); $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex); } } try { @Piwik::createDatabaseObject($dbInfos); } catch (Zend_Db_Adapter_Exception $e) { $db = Piwik_Db_Adapter::factory($adapter, $dbInfos, $connect = false); // database not found, we try to create it if ($db->isErrNo($e, '1049')) { $dbInfosConnectOnly = $dbInfos; $dbInfosConnectOnly['dbname'] = null; @Piwik::createDatabaseObject($dbInfosConnectOnly); @Piwik::createDatabase($dbInfos['dbname']); // select the newly created database @Piwik::createDatabaseObject($dbInfos); } else { throw $e; } } return $dbInfos; }
/** * Get system information */ public static function getSystemInformation() { global $piwik_minimumPHPVersion; $minimumMemoryLimit = Zend_Registry::get('config')->General->minimum_memory_limit; $infos = array(); $infos['general_infos'] = array(); $infos['directories'] = Piwik::checkDirectoriesWritable(); $infos['can_auto_update'] = Piwik::canAutoUpdate(); if(Piwik_Common::isIIS()) { Piwik::createWebConfigFiles(); } else { Piwik::createHtAccessFiles(); } Piwik::createWebRootFiles(); $infos['phpVersion_minimum'] = $piwik_minimumPHPVersion; $infos['phpVersion'] = PHP_VERSION; $infos['phpVersion_ok'] = version_compare( $piwik_minimumPHPVersion, $infos['phpVersion']) === -1; // critical errors $extensions = @get_loaded_extensions(); $needed_extensions = array( 'zlib', 'SPL', 'iconv', 'Reflection', ); $infos['needed_extensions'] = $needed_extensions; $infos['missing_extensions'] = array(); foreach($needed_extensions as $needed_extension) { if(!in_array($needed_extension, $extensions)) { $infos['missing_extensions'][] = $needed_extension; } } $infos['pdo_ok'] = false; if(in_array('PDO', $extensions)) { $infos['pdo_ok'] = true; } $infos['adapters'] = Piwik_Db_Adapter::getAdapters(); $needed_functions = array( 'debug_backtrace', 'create_function', 'eval', 'gzcompress', 'gzuncompress', 'pack', ); $infos['needed_functions'] = $needed_functions; $infos['missing_functions'] = array(); foreach($needed_functions as $needed_function) { if(!self::functionExists($needed_function)) { $infos['missing_functions'][] = $needed_function; } } // warnings $desired_extensions = array( 'json', 'libxml', 'dom', 'SimpleXML', ); $infos['desired_extensions'] = $desired_extensions; $infos['missing_desired_extensions'] = array(); foreach($desired_extensions as $desired_extension) { if(!in_array($desired_extension, $extensions)) { $infos['missing_desired_extensions'][] = $desired_extension; } } $desired_functions = array( 'set_time_limit', 'mail', 'parse_ini_file', 'glob', ); $infos['desired_functions'] = $desired_functions; $infos['missing_desired_functions'] = array(); foreach($desired_functions as $desired_function) { if(!self::functionExists($desired_function)) { $infos['missing_desired_functions'][] = $desired_function; } } $infos['openurl'] = Piwik_Http::getTransportMethod(); $infos['gd_ok'] = false; if (in_array('gd', $extensions)) { $gdInfo = gd_info(); $infos['gd_version'] = $gdInfo['GD Version']; preg_match('/([0-9]{1})/', $gdInfo['GD Version'], $gdVersion); if($gdVersion[0] >= 2) { $infos['gd_ok'] = true; } } $infos['hasMbstring'] = false; $infos['multibyte_ok'] = true; if(function_exists('mb_internal_encoding')) { $infos['hasMbstring'] = true; if (((int) ini_get('mbstring.func_overload')) != 0) { $infos['multibyte_ok'] = false; } } $serverSoftware = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''; $infos['serverVersion'] = addslashes($serverSoftware); $infos['serverOs'] = @php_uname(); $infos['serverTime'] = date('H:i:s'); $infos['registerGlobals_ok'] = ini_get('register_globals') == 0; $infos['memoryMinimum'] = $minimumMemoryLimit; $infos['memory_ok'] = true; $infos['memoryCurrent'] = ''; $raised = Piwik::raiseMemoryLimitIfNecessary(); if(($memoryValue = Piwik::getMemoryLimitValue()) > 0) { $infos['memoryCurrent'] = $memoryValue.'M'; $infos['memory_ok'] = $memoryValue >= $minimumMemoryLimit; } $infos['isWindows'] = Piwik_Common::isWindows(); $integrityInfo = Piwik::getFileIntegrityInformation(); $infos['integrity'] = $integrityInfo[0]; $infos['integrityErrorMessages'] = array(); if(isset($integrityInfo[1])) { if($infos['integrity'] == false) { $infos['integrityErrorMessages'][] = '<b>'.Piwik_Translate('General_FileIntegrityWarningExplanation').'</b>'; } $infos['integrityErrorMessages'] = array_merge($infos['integrityErrorMessages'], array_slice($integrityInfo, 1)); } $infos['timezone'] = Piwik::isTimezoneSupportEnabled(); $infos['tracker_status'] = Piwik_Common::getRequestVar('trackerStatus', 0, 'int'); $infos['protocol'] = Piwik_ProxyHeaders::getProtocolInformation(); if(Piwik_Url::getCurrentScheme() == 'http' && $infos['protocol'] !== null) { $infos['general_infos']['secure_protocol'] = '1'; } if(count($headers = Piwik_ProxyHeaders::getProxyClientHeaders()) > 0) { $infos['general_infos']['proxy_client_headers'] = $headers; } if(count($headers = Piwik_ProxyHeaders::getProxyHostHeaders()) > 0) { $infos['general_infos']['proxy_host_headers'] = $headers; } return $infos; }
/** * Create database object and connect to database */ public static function createDatabaseObject($dbInfos = null) { $config = Zend_Registry::get('config'); if (is_null($dbInfos)) { $dbInfos = $config->database->toArray(); } Piwik_PostEvent('Reporting.getDatabaseConfig', $dbInfos); $dbInfos['profiler'] = $config->Debug->enable_sql_profiler; $db = null; Piwik_PostEvent('Reporting.createDatabase', $db); if (is_null($db)) { $adapter = $dbInfos['adapter']; $db = @Piwik_Db_Adapter::factory($adapter, $dbInfos); } Zend_Registry::set('db', $db); }