function init() { $this->Error = array('errors' => array()); set_time_limit(10 * 60); $siteType = $this->chosenSiteType(); // If we are installing a package without extension packages we // generate the autoload array for extensions. // For the time being we only do this for the plain_site package. if ($siteType['identifier'] == 'plain_site') { ezpAutoloader::updateExtensionAutoloadArray(); } $saveData = true; // set to true to save data //$ini = eZINI::create(); $accessMap = array('url' => array(), 'hostname' => array(), 'port' => array(), 'accesses' => array()); $primaryLanguage = null; $allLanguages = array(); $allLanguageCodes = array(); $variationsLanguages = array(); $primaryLanguageCode = $this->PersistenceList['regional_info']['primary_language']; $extraLanguageCodes = isset($this->PersistenceList['regional_info']['languages']) ? $this->PersistenceList['regional_info']['languages'] : array(); $extraLanguageCodes = array_diff($extraLanguageCodes, array($primaryLanguageCode)); /* if ( isset( $this->PersistenceList['regional_info']['variations'] ) ) { $variations = $this->PersistenceList['regional_info']['variations']; foreach ( $variations as $variation ) { $locale = eZLocale::create( $variation ); if ( $locale->localeCode() == $primaryLanguageCode ) { $primaryLanguage = $locale; } else { $variationsLanguages[] = $locale; } } } */ if ($primaryLanguage === null) { $primaryLanguage = eZLocale::create($primaryLanguageCode); } $allLanguages[] = $primaryLanguage; foreach ($extraLanguageCodes as $extraLanguageCode) { $allLanguages[] = eZLocale::create($extraLanguageCode); $allLanguageCodes[] = $extraLanguageCode; } // If we have already figured out charset we used that if (isset($this->PersistenceList['regional_info']['site_charset']) and strlen($this->PersistenceList['regional_info']['site_charset']) > 0) { $charset = $this->PersistenceList['regional_info']['site_charset']; } else { // Figure out charset automatically if it is not set yet $canUseUnicode = $this->PersistenceList['database_info']['use_unicode']; $charset = $this->findAppropriateCharset($primaryLanguage, $allLanguages, $canUseUnicode); } if (!$charset) { // Make sure kickstart functionality stops $this->setAllowKickstart(false); return 'LanguageOptions'; } else { $i18nINI = eZINI::create('i18n.ini'); // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $i18nINI->setReadOnlySettingsCheck(false); $i18nINI->setVariable('CharacterSettings', 'Charset', $charset); $i18nINI->save(false, '.php', 'append', true); } $siteINISettings = array(); $result = true; $accessType = $siteType['access_type']; $resultArray = array('errors' => array()); $result = $this->initializePackage($siteType, $accessMap, $charset, $allLanguageCodes, $allLanguages, $primaryLanguage, $this->PersistenceList['admin'], $resultArray); if (!$result) { $this->Error['errors'] = array_merge($this->Error['errors'], $resultArray['errors']); $this->Error['errors'][] = array('code' => 'EZSW-040', 'text' => "Failed to initialize site package '" . $siteType['identifier'] . "'"); //$result = false; return false; } if ($resultArray['common_settings']) { $extraCommonSettings = $resultArray['common_settings']; foreach ($extraCommonSettings as $extraSetting) { if ($extraSetting === false) { continue; } $iniName = $extraSetting['name']; $settings = $extraSetting['settings']; $resetArray = false; if (isset($extraSetting['reset_arrays'])) { $resetArray = $extraSetting['reset_arrays']; } if ($iniName == 'site.ini') { $siteINISettings[] = $settings; continue; } if (file_exists('settings/override/' . $iniName . '.append') || file_exists('settings/override/' . $iniName . '.append.php')) { $tmpINI = eZINI::instance($iniName, 'settings/override', null, null, false, true); } else { $tmpINI = eZINI::create($iniName); } // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $tmpINI->setReadOnlySettingsCheck(false); $tmpINI->setVariables($settings); $tmpINI->save(false, '.append.php', false, true, "settings/override", $resetArray); } } if (!$result) { // Display errors return false; } $ini = eZINI::instance(); // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $ini->setReadOnlySettingsCheck(false); $regionalInfo = $this->PersistenceList['regional_info']; $emailInfo = $this->PersistenceList['email_info']; $imageINI = eZINI::create('image.ini'); // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $imageINI->setReadOnlySettingsCheck(false); $imageINI->setVariable('ImageMagick', 'IsEnabled', 'false'); if ($this->PersistenceList['imagemagick_program']['result']) { $imageINI->setVariable('ImageMagick', 'ExecutablePath', $this->PersistenceList['imagemagick_program']['path']); $imageINI->setVariable('ImageMagick', 'Executable', $this->PersistenceList['imagemagick_program']['program']); $imageINI->setVariable('ImageMagick', 'IsEnabled', 'true'); } $saveResult = false; if (!$saveData) { $saveResult = true; } if ($saveData) { $saveResult = $imageINI->save(false, '.php', 'append', true); } if ($saveResult and $charset !== false) { /*$i18nINI = eZINI::create( 'i18n.ini' ); // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $i18nINI->setReadOnlySettingsCheck( false ); $i18nINI->setVariable( 'CharacterSettings', 'Charset', $charset ); if ( $saveData ) $saveResult = $i18nINI->save( false, '.php', 'append', true ); */ } switch ($accessType) { case 'port': $matchOrder = 'port'; break; case 'hostname': $matchOrder = 'host'; break; case 'url': default: $matchOrder = 'uri'; break; } $hostMatchMapItems = array(); foreach ($accessMap['hostname'] as $hostName => $siteAccessName) { $hostMatchMapItems[] = $hostName . ';' . $siteAccessName; } $portMatchMapItems = array(); foreach ($accessMap['port'] as $port => $siteAccessName) { $portMatchMapItems[$port] = $siteAccessName; } $ini->setVariable('SiteAccessSettings', 'MatchOrder', $matchOrder); $ini->setVariable('SiteAccessSettings', 'HostMatchMapItems', $hostMatchMapItems); foreach ($portMatchMapItems as $port => $siteAccessName) { $ini->setVariable('PortAccessSettings', $port, $siteAccessName); } $ini->setVariable('SiteSettings', 'SiteList', $accessMap['sites']); $ini->setVariable('SiteAccessSettings', 'AvailableSiteAccessList', $accessMap['accesses']); $ini->setVariable("SiteAccessSettings", "CheckValidity", "false"); $ini->setVariable('Session', 'SessionNameHandler', 'custom'); $ini->setVariable('MailSettings', 'AdminEmail', $this->PersistenceList['admin']['email']); $ini->setVariable('MailSettings', 'EmailSender', false); $defaultAccess = 'admin'; if (isset($accessMap['accesses'][0])) { $defaultAccess = $accessMap['accesses'][0]; } $ini->setVariable('SiteSettings', 'DefaultAccess', $defaultAccess); if ($emailInfo['type'] == 1) { $ini->setVariable('MailSettings', 'Transport', 'sendmail'); } else { $ini->setVariable('MailSettings', 'Transport', 'SMTP'); $ini->setVariable('MailSettings', 'TransportServer', $emailInfo['server']); $ini->setVariable('MailSettings', 'TransportUser', $emailInfo['user']); $ini->setVariable('MailSettings', 'TransportPassword', $emailInfo['password']); } // Enable design location cache $ini->setVariable('DesignSettings', 'DesignLocationCache', 'enabled'); if ($saveData) { foreach ($siteINISettings as $siteINISetting) { $ini->setVariables($siteINISetting); } } if ($saveData) { $saveResult = $ini->save(false, '.php', 'append', true, true, true); } return true; // Never show, generate sites }
/** * @param string|bool $dbCharset Default charset used if false * @param array $overrideDBParameters * @return array */ function checkDatabaseRequirements($dbCharset = false, $overrideDBParameters = array()) { $result = array('error_code' => false, 'use_unicode' => false, 'db_version' => false, 'db_require_version' => false, 'site_charset' => false, 'status' => false); $databaseMap = eZSetupDatabaseMap(); $databaseInfo = $this->PersistenceList['database_info']; $databaseInfo['info'] = $databaseMap[$databaseInfo['type']]; $dbDriver = $databaseInfo['info']['driver']; if ($dbCharset === false) { $dbCharset = 'iso-8859-1'; } $dbParameters = array('server' => $databaseInfo['server'], 'port' => $databaseInfo['port'], 'user' => $databaseInfo['user'], 'password' => $databaseInfo['password'], 'socket' => trim($databaseInfo['socket']) == '' ? false : $databaseInfo['socket'], 'database' => $databaseInfo['database'], 'charset' => $dbCharset); $dbParameters = array_merge($dbParameters, $overrideDBParameters); // PostgreSQL requires us to specify database name. // We use template1 here since it exists on all PostgreSQL installations. if ($dbParameters['database'] == '' and $this->PersistenceList['database_info']['type'] == 'pgsql') { $dbParameters['database'] = 'template1'; } try { $db = eZDB::instance($dbDriver, $dbParameters, true); $result['db_instance'] = $db; $result['connected'] = $db->isConnected(); } catch (eZDBNoConnectionException $e) { $result['error_code'] = self::DB_ERROR_CONNECTION_FAILED; return $result; } // Check if the version of the database fits the minimum required $dbVersion = $db->databaseServerVersion(); $result['db_version'] = $dbVersion['string']; $result['db_required_version'] = $databaseInfo['info']['required_version']; if ($dbVersion != null) { if (version_compare($result['db_version'], $databaseInfo['info']['required_version']) == -1) { $result['connected'] = false; $result['error_code'] = self::DB_ERROR_VERSION_INVALID; return $result; } } // If we have PostgreSQL we need to make sure we have the 'digest' procedure available. if ($db->databaseName() == 'postgresql' and $dbParameters['database'] != 'template1') { $sql = "SELECT count(*) AS count FROM pg_proc WHERE proname='digest'"; $rows = $db->arrayQuery($sql); $count = $rows[0]['count']; // If it is 0 we don't have it if ($count == 0) { $result['error_code'] = self::DB_ERROR_NO_DIGEST_PROC; return $result; } } $result['use_unicode'] = false; if ($db->isCharsetSupported('utf-8')) { $result['use_unicode'] = true; } // If we regional info we can start checking the charset if (isset($this->PersistenceList['regional_info'])) { if (isset($this->PersistenceList['regional_info']['site_charset']) and strlen($this->PersistenceList['regional_info']['site_charset']) > 0) { $charsetsList = array($this->PersistenceList['regional_info']['site_charset']); } else { // Figure out charset automatically if it is not set yet $primaryLanguage = null; $allLanguages = array(); $allLanguageCodes = array(); $variationsLanguages = array(); $primaryLanguageCode = $this->PersistenceList['regional_info']['primary_language']; $extraLanguageCodes = isset($this->PersistenceList['regional_info']['languages']) ? $this->PersistenceList['regional_info']['languages'] : array(); $extraLanguageCodes = array_diff($extraLanguageCodes, array($primaryLanguageCode)); /* if ( isset( $this->PersistenceList['regional_info']['variations'] ) ) { $variations = $this->PersistenceList['regional_info']['variations']; foreach ( $variations as $variation ) { $locale = eZLocale::create( $variation ); if ( $locale->localeCode() == $primaryLanguageCode ) { $primaryLanguage = $locale; } else { $variationsLanguages[] = $locale; } } } */ if ($primaryLanguage === null) { $primaryLanguage = eZLocale::create($primaryLanguageCode); } $allLanguages[] = $primaryLanguage; foreach ($extraLanguageCodes as $extraLanguageCode) { $allLanguages[] = eZLocale::create($extraLanguageCode); $allLanguageCodes[] = $extraLanguageCode; } $charsetsList = $this->findAppropriateCharsetsList($primaryLanguage, $allLanguages, $result['use_unicode']); } $checkedCharset = $db->checkCharset($charsetsList, $currentCharset); if ($checkedCharset === false) { // If the current charset is utf-8 we use that instead // since it can represent any character possible in the chosen languages if ($currentCharset == 'utf-8') { $charset = 'utf-8'; $result['site_charset'] = $charset; } else { $result['connected'] = false; $this->PersistenceList['database_info']['requested_charset'] = implode(", ", $charsetsList); $this->PersistenceList['database_info']['current_charset'] = $currentCharset; $result['error_code'] = self::DB_ERROR_CHARSET_DIFFERS; return $result; } } else { if ($checkedCharset === true) { $result['site_charset'] = $charsetsList[0]; } else { $result['site_charset'] = $checkedCharset; } } } $result['status'] = true; return $result; }
function processPostData() { $primaryLanguage = $this->Http->postVariable('eZSetupDefaultLanguage'); $languages = $this->Http->hasPostVariable('eZSetupLanguages') ? $this->Http->postVariable('eZSetupLanguages') : array(); if (!in_array($primaryLanguage, $languages)) { $languages[] = $primaryLanguage; } $regionalInfo = array(); $regionalInfo['language_type'] = 1; $regionalInfo['primary_language'] = $primaryLanguage; $regionalInfo['languages'] = $languages; $regionalInfo['enable_unicode'] = true; $regionalInfo['site_charset'] = 'utf-8'; $this->PersistenceList['regional_info'] = $regionalInfo; $charset = false; //SP experimental code 26.04.2007 commented "if" // if ( !isset( $this->PersistenceList['database_info']['use_unicode'] ) || // $this->PersistenceList['database_info']['use_unicode'] == false ) // { // If we have already figured out charset and it is utf-8 // we don't have to check the new languages if (isset($this->PersistenceList['regional_info']['site_charset']) and $this->PersistenceList['regional_info']['site_charset'] == 'utf-8') { $charset = 'utf-8'; } else { $primaryLanguage = null; $allLanguages = array(); $allLanguageCodes = array(); $variationsLanguages = array(); $primaryLanguageCode = $this->PersistenceList['regional_info']['primary_language']; $extraLanguageCodes = isset($this->PersistenceList['regional_info']['languages']) ? $this->PersistenceList['regional_info']['languages'] : array(); $extraLanguageCodes = array_diff($extraLanguageCodes, array($primaryLanguageCode)); /* if ( isset( $this->PersistenceList['regional_info']['variations'] ) ) { $variations = $this->PersistenceList['regional_info']['variations']; foreach ( $variations as $variation ) { $locale = eZLocale::create( $variation ); if ( $locale->localeCode() == $primaryLanguageCode ) { $primaryLanguage = $locale; } else { $variationsLanguages[] = $locale; } } } */ if ($primaryLanguage === null) { $primaryLanguage = eZLocale::create($primaryLanguageCode); } $allLanguages[] = $primaryLanguage; foreach ($extraLanguageCodes as $extraLanguageCode) { $allLanguages[] = eZLocale::create($extraLanguageCode); $allLanguageCodes[] = $extraLanguageCode; } $canUseUnicode = isset($this->PersistenceList['database_info']['use_unicode']) ? $this->PersistenceList['database_info']['use_unicode'] : false; $charset = $this->findAppropriateCharset($primaryLanguage, $allLanguages, $canUseUnicode); if (!$charset) { $this->Error = 1; return false; } } // Store the charset for later handling $this->PersistenceList['regional_info']['site_charset'] = $charset; //SP experimental code 26.04.2007 commented "if" // } if ($this->PersistenceList['regional_info']['site_charset']) { $i18nINI = eZINI::create('i18n.ini'); // Set ReadOnlySettingsCheck to false: towards // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables. $i18nINI->setReadOnlySettingsCheck(false); $i18nINI->setVariable('CharacterSettings', 'Charset', $this->PersistenceList['regional_info']['site_charset']); $i18nINI->save(false, '.php', 'append', true); } return true; }