Index: install.php =================================================================== --- install.php (revision 14858) +++ install.php (working copy) @@ -68,14 +68,15 @@ * @var Array */ var $steps = Array ( - 'fresh_install' => Array ('check_paths', 'db_config', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'sys_config', 'select_theme', 'security', 'finish'), - 'clean_reinstall' => Array ('check_paths', 'clean_db', 'db_config', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'sys_config', 'select_theme', 'security', 'finish'), + 'fresh_install' => Array ('sys_requirements', 'check_paths', 'db_config', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'sys_config', 'select_theme', 'security', 'finish'), + 'clean_reinstall' => Array ('initial', 'sys_requirements', 'check_paths', 'clean_db', 'db_config', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'sys_config', 'select_theme', 'security', 'finish'), 'already_installed' => Array ('check_paths', 'install_setup'), 'upgrade' => Array ('check_paths', 'install_setup', 'upgrade_modules', 'skin_upgrade', 'security', 'finish'), 'update_license' => Array ('check_paths', 'install_setup', 'select_license', /*'download_license',*/ 'select_domain', 'security', 'finish'), 'update_config' => Array ('check_paths', 'install_setup', 'sys_config', 'security', 'finish'), 'db_reconfig' => Array ('check_paths', 'install_setup', 'db_reconfig', 'security', 'finish'), + 'sys_requirements' => Array ('check_paths', 'install_setup', 'sys_requirements', 'security', 'finish') ); /** @@ -83,14 +84,14 @@ * * @var Array */ - var $skipLoginSteps = Array ('check_paths', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'select_theme', 'security', 'finish', -1); + var $skipLoginSteps = Array ('sys_requirements', 'check_paths', 'select_license', /*'download_license',*/ 'select_domain', 'root_password', 'choose_modules', 'post_config', 'select_theme', 'security', 'finish', -1); /** * Steps, on which kApplication should not be initialized, because of missing correct db table structure * * @var Array */ - var $skipApplicationSteps = Array ('check_paths', 'clean_db', 'db_config', 'db_reconfig' /*, 'install_setup'*/); // remove install_setup when application will work separately from install + var $skipApplicationSteps = Array ('sys_requirements', 'check_paths', 'clean_db', 'db_config', 'db_reconfig' /*, 'install_setup'*/); // remove install_setup when application will work separately from install /** * Folders that should be writeable to continue installation. $1 - main writeable folder from config.php ("/system" by default) @@ -198,6 +199,7 @@ } $this->InitStep(); + } function SetFirstStep() @@ -277,6 +279,14 @@ } switch ($this->currentStep) { + case 'sys_requirements': + if (!isset($_POST['errors']) || $_POST['refresh_form'] == 'Refresh') { + $this->errorMessage = ' '; + } + if (isset($_POST['errors']) && $_POST['errors']) { + $this->errorMessage = '
Installation can not continue until all required environment parameters are set correctly'; + } + break; case 'check_paths': $writeable_base = $this->toolkit->getSystemConfig('Misc', 'WriteablePath'); foreach ($this->writeableFolders as $folder_path) { @@ -324,6 +334,14 @@ $this->toolkit->setSystemConfig('Database', $field_name, ''); }*/ } + +// if (!isset($_POST['errors']) || $_POST['refresh_form'] == 'Refresh') { +// $this->errorMessage = ' '; +// } +// if (isset($_POST['errors']) && $_POST['errors']) { +// $this->errorMessage = '
Installation can not continue until all required environment parameters are set correctly'; +// } +// break; case 'download_license': @@ -509,6 +527,14 @@ break; } } + + // 2. Check DB requirements + $db_check_results = $this->toolkit->CallPrerequisitesMethod('core/', 'CheckDBRequirements'); + if (!$db_check_results['version'] || !$db_check_results['packet_size']) { + $status = false; + $this->errorMessage = '
Installation can not continue until all required environment parameters are set correctly'; + } + if (!$status) break; // 2. check permissions, that use have in this database @@ -1019,11 +1045,11 @@ return ; } + $this->InitApplication(); + $this->currentStep = $this->GetNextStep(); $this->InitStep(); // init next step (that will be shown now) - $this->InitApplication(); - if ($this->currentStep == -1) { // step after last step -> redirect to admin $this->Application->Redirect('index', Array (), '', 'index.php'); @@ -1267,6 +1293,17 @@ $this->errorMessage = $error_message; } + if ($this->currentStep == 'sys_requirements') { + if (isset($_REQUEST['cookies']) && $_REQUEST['cookies']) { + setcookie('test', $_REQUEST['cookies'], time()+3600); + } else { + $random_number = rand(1000000, 9999999); + setcookie('test', $random_number, time()+3600); + header('Location:'.$_SERVER['PHP_SELF'].'?cookies='.$random_number.'&preset='.$this->stepsPreset.'&step='.$this->currentStep); + exit; + } + } + include_once (FULL_PATH . '/' . REL_PATH . '/install/incs/install.tpl'); if ( isset($this->Application) ) { @@ -1496,6 +1533,7 @@ */ function GetStepBody() { + $step_template = FULL_PATH.'/core/install/step_templates/'.$this->currentStep.'.tpl'; if (file_exists($step_template)) { ob_start(); @@ -1642,6 +1680,9 @@ $step_titles = $this->_getStepTitles($this->steps[$this->stepsPreset]); foreach ($this->steps[$this->stepsPreset] as $step_name) { + if ($step_name == 'initial') { + continue; + } $template = $step_name == $this->currentStep ? $active_tpl : $passive_tpl; $ret .= sprintf($template, $step_titles[$step_name]); } @@ -1691,7 +1732,7 @@ { $button_visibility = Array ( 'continue' => $this->GetNextStep() != -1 || ($this->stepsPreset == 'already_installed'), - 'refresh' => in_array($this->currentStep, Array ('check_paths', 'security')), + 'refresh' => in_array($this->currentStep, Array ('check_paths', 'security', 'sys_requirements')), 'back' => in_array($this->currentStep, Array (/*'select_license',*/ 'download_license', 'select_domain')), ); @@ -1707,4 +1748,39 @@ return array_key_exists($name, $button_visibility) ? $button_visibility[$name] : true; } + + function PrintDBRequirements() + { + $heading_tpl = ' + + %s + '; + + $error_tpl = ' + + %s + %s + '; + + $check_results = $this->toolkit->CallPrerequisitesMethod('core/', 'CheckDBRequirements'); + + $output = sprintf($heading_tpl, 'Server-side requirements'); + + $checks = Array ( + 'version' => 'MySQL version: 5.0+ (required)', + 'packet_size' => 'MySQL Packet Size: 1MB min (required)', + ); + + foreach ($checks AS $key => $label) { + $error = ''; + if (isset($check_results[$key])) { + $error = $check_results[$key] ? '[PASSED]' : '[FAILED]'; + } + $output .= sprintf($error_tpl, $label, $error); + } + + $output .= sprintf($heading_tpl, 'Database configuration', 'text'); + + echo $output; + } } Index: install/install_toolkit.php =================================================================== --- install/install_toolkit.php (revision 14858) +++ install/install_toolkit.php (working copy) @@ -159,6 +159,40 @@ } /** + * Call prerequisites method + * + * @param string $module_path + * @param string $method + * @return array + */ + function CallPrerequisitesMethod($module_path, $method) + { + static $prerequisit_classes = Array (); + + $prerequisites_file = sprintf(PREREQUISITE_FILE, $module_path); + if ( !file_exists($prerequisites_file)) { + return Array (); + } + + if ( !isset($prerequisit_classes[$module_path]) ) { + // save class name, because 2nd time + // (in after call $prerequisite_class variable will not be present) + include_once $prerequisites_file; + $prerequisit_classes[$module_path] = $prerequisite_class; + } + + $prerequisite_object = new $prerequisit_classes[$module_path](); + /* @var $prerequisite_object InPortalPrerequisites */ + + if ( method_exists($prerequisite_object, 'setToolkit') ) { + $prerequisite_object->setToolkit($this); + } + + // some errors possible + return $prerequisite_object->$method(); + } + + /** * Processes one license, received from server * * @param string $file_data Index: install/prerequisites.php =================================================================== --- install/prerequisites.php (revision 14858) +++ install/prerequisites.php (working copy) @@ -20,7 +20,7 @@ * Class, that holds all prerequisite scripts for "In-Portal" module * */ - class InPortalPrerequisites extends kHelper { + class InPortalPrerequisites { /** * Install toolkit instance @@ -30,6 +30,14 @@ var $_toolkit = null; /** + * Connection to database + * + * @var kDBConnection + * @access protected + */ + protected $Conn = null; + + /** * Sets common instance of installator toolkit * * @param kInstallToolkit $instance @@ -42,6 +50,16 @@ /** * Checks minimal version, that could be upgradeable * + * @return kDBConnection + */ + function &getConnection() + { + return $this->_toolkit->Conn; + } + + /** + * Checks minimal version, that could be upgradeable + * * @param Array $versions * @param string $mode when called mode {install, upgrade, standalone) * @return Array @@ -54,8 +72,10 @@ $sql = 'SELECT Version FROM ' . TABLE_PREFIX . 'Modules WHERE Name = "In-Portal"'; - $inportal_version = $this->Conn->GetOne($sql); + $conn =& $this->getConnection(); + $inportal_version = $conn->GetOne($sql); + if ($inportal_version === false) { // only, when In-Portal was installed return $errors; @@ -72,4 +92,79 @@ return $errors; } + + /** + * Returns information about system requirements + * + * @return array + */ + function CheckSystemRequirements() + { + // check PHP version 5.2+ + $ret = Array(); + + $version_parts = explode('.', PHP_VERSION); + $ret['php_version'] = $version_parts[0] > 5 || ($version_parts[0] == 5 && $version_parts[1] > 1); + + $ret['url_rewriting'] = function_exists('apache_get_modules') && in_array('mod_rewrite',apache_get_modules()); + $ret['memcache'] = class_exists('Memcache'); + $ret['curl'] = function_exists('curl_init'); + $ret['freetype'] = function_exists('imagettfbbox'); + + $ret['gd_version'] = 0; + $ret['jpeg'] = 0; + if (function_exists('gd_info')) { + $gd_info = gd_info(); + preg_match_all('/\d+/', $gd_info['GD Version'], $version_parts); + $ret['gd_version'] = $version_parts[0][0] > 1 || ($version_parts[0][0] == 1 && $version_parts[0][1] > 7); + $ret['jpeg'] = isset($gd_info['JPEG Support']) && $gd_info['JPEG Support']; + } + $ret['mysql'] = function_exists('mysql_connect'); + $ret['json'] = function_exists('json_encode'); + + $original_memory_limit = ini_get('memory_limit'); + ini_set('memory_limit', $original_memory_limit == '32M' ? '40M' : '32M'); + $ret['memory_limit'] = 0; + if ($original_memory_limit != ini_get('memory_limit')) { + $ret['memory_limit'] = 1; + ini_set('memory_limit', $original_memory_limit); + } + + $original_timezone = ini_get('date.timezone'); + ini_set('date.timezone', $original_timezone == 'Asia/Delhi' ? 'Europe/London' : 'Asia/Delhi'); + $ret['date.timezone'] = 0; + if ($original_timezone != ini_get('date.timezone')) { + $ret['date.timezone'] = 1; + ini_set('date.timezone', $original_timezone); + } + $ret['variables_order'] = (strpos(ini_get('variables_order'), 'GPC') !== false); + $ret['output_buffering'] = (ini_get('output_buffering') > 0); + + return $ret; + } + + /** + * Returns information about DB requirements + * + * @return array + */ + function CheckDBRequirements() + { + // check PHP version 5.2+ + $ret = Array(); + + $sql = 'SELECT version()'; + $conn =& $this->getConnection(); + + $db_version = $conn->GetOne($sql); + $version_parts = explode('.', $db_version); + $ret['version'] = $version_parts[0] >= 5; + + $sql = 'SHOW VARIABLES LIKE \'max_allowed_packet\''; + $a_db_variables = $conn->Query($sql, 'Variable_name'); + $ret['packet_size'] = $a_db_variables['max_allowed_packet']['Value'] >= 1048576; + + return $ret; + } + } \ No newline at end of file Index: install/step_templates/db_config.tpl =================================================================== --- install/step_templates/db_config.tpl (revision 14858) +++ install/step_templates/db_config.tpl (working copy) @@ -1,3 +1,5 @@ +PrintDBRequirements(); ?> + Database Server Type*: @@ -67,7 +69,7 @@ GetVar('preset') != 'already_installed') { ?> - + Use existing In-Portal installation in this Database: Index: install/step_templates/db_reconfig.tpl =================================================================== --- install/step_templates/db_reconfig.tpl (revision 14858) +++ install/step_templates/db_reconfig.tpl (working copy) @@ -1,3 +1,5 @@ +PrintDBRequirements(); ?> + Database Server Type*: Index: install/step_templates/install_setup.tpl =================================================================== --- install/step_templates/install_setup.tpl (revision 14858) +++ install/step_templates/install_setup.tpl (working copy) @@ -32,6 +32,7 @@ $option_tpl = ob_get_clean(); $options = Array ( + 'sys_requirements' => 'Check System Requirements', 'upgrade' => 'Upgrade In-Portal', 'clean_reinstall' => 'Reinstall In-Portal', 'fresh_install' => 'Install In-Portal to a New Database', Index: install/step_templates/sys_requirements.tpl =================================================================== --- install/step_templates/sys_requirements.tpl (revision 0) +++ install/step_templates/sys_requirements.tpl (revision 0) @@ -0,0 +1,107 @@ + + %s + '; + + $error_tpl = ' + + %s + %s + '; + + $check_results = $this->toolkit->CallPrerequisitesMethod('core/', 'CheckSystemRequirements'); + + $output = sprintf($heading_tpl, 'Server-side requirements'); + + $checks = Array ( + 'php_version' => 'PHP version: 5.2+ (required)', + 'url_rewriting' => 'URL Rewriting Support (optional)', + '' => 'PHP extensions:', + 'memcache' => '- Memcache (optional)', + 'curl' => '- Curl (required)', + 'freetype' => '- Freetype (required)', + 'gd_version' => '- GD 1.8+ (required)', + 'jpeg' => '- jpeg (required)', + 'mysql' => '- MySQL (required)', + 'json' => '- JSON (optional)', + ' ' => 'PHP settings:', + 'memory_limit' => '- ini_set(\'memory_limit\', ...) works (optional)', + 'date.timezone' => '- ini_get(\'date.timezone\') - timezone set (required)', + 'variables_order' => '- ini_get(\'variables_order\') - contains "GPC" string', + 'output_buffering' => '- ini_get(\'output_buffering\') > 0 - buffering works (required)', + ); + + $required_checks = Array ( + 'php_version', + 'curl', + 'freetype', + 'gd_version', + 'jpeg', + 'mysql', + 'date.timezone', + 'output_buffering', + ); + + + $has_error = !$cookies_enabled; + foreach ($checks AS $key => $label) { + $error = ''; + if (isset($check_results[$key])) { + if (!$check_results[$key] && in_array($key, $required_checks)) { + $has_error = 1; + } + $error = $check_results[$key] ? '[PASSED]' : '[FAILED]'; + } + $output .= sprintf($error_tpl, $label, $error); + } + +//PHP version: 5.2+ (required) +//MySQL version: 5.1+ (required) +//MySQL Packet Size: 2MB min (required for large website, optional for small website) +//URL Rewriting Support: yes/no (optional) +//PHP extensions: +//- Memcache (optional); Memcache class +//- Curl (required); curl_init function +//- Freetype (required); imagettfbbox function +//- GD 1.8+ (required) +//- jpeg (required) +//- MySQL; mysql_connect function (required) +//- JSON (optional); json_encode function +//- Java (optional); run "java args" (need to determine args that cause error on incorrectly installed java) +// +//PHP settings: +//- ini_set('memory_limit', ...) - works/don't work (optional) +//- ini_get('date.timezone') - timezone set/not set (required) +//- ini_get('gpc_order') - contains "GPC" string +//- ini_get('output_buffering') > 0 - buffering works (required) +// + + $output .= sprintf($heading_tpl, 'Client-side requirements', 'text'); + + $error = $cookies_enabled ? '[PASSED]': '[FAILED]'; + $output .= sprintf($error_tpl, 'Cookies enabled', $error); + + $output .= ''; + $output .= ''; + $output .= ''; + + $output .= ' + + JavaScript enabled + [FAILED] + + + '; + echo $output; +?> \ No newline at end of file Index: install/steps_db.xml =================================================================== --- install/steps_db.xml (revision 14858) +++ install/steps_db.xml (working copy) @@ -207,4 +207,7 @@ The characters entered in this field are placed before the names of the tables used by In-Portal. For example, if you enter "inp_" into the prefix field, the table named Category will be named inp_Category.

]]> + + System Requirements Check option should be used to ensure proper system behavior in the current environment.]]> + \ No newline at end of file