Index: trunk/core/install.php =================================================================== diff -u -N -r6685 -r6691 --- trunk/core/install.php (.../install.php) (revision 6685) +++ trunk/core/install.php (.../install.php) (revision 6691) @@ -70,7 +70,11 @@ */ var $steps = Array( 'fresh_install' => Array ('check_paths', 'db_config', 'root_password', 'choose_modules', 'finish'), - 'already_installed' => Array ('installed_select', 'finish'), + 'already_installed' => Array ('install_setup'), + + 'upgrade' => Array ('install_setup',/* ..., */ 'finish'), + 'db_reconfig' => Array ('install_setup',/* ..., */ 'finish'), + 'fix_paths' => Array ('install_setup',/* ..., */ 'finish'), ); @@ -80,7 +84,7 @@ * @var Array */ - var $skipApplicationSteps = Array ('check_paths', 'db_config'); + var $skipApplicationSteps = Array ('check_paths', 'db_config', 'install_setup'); // remove install_setup when application will work separately from install /** * Folders that should be writeable to continue installation @@ -108,33 +112,49 @@ $this->INIFile = FULL_PATH.'/config.php'; $this->StepDBFile = FULL_PATH.'/'.REL_PATH.'/install/steps_db.xml'; + $base_path = rtrim(preg_replace('/'.preg_quote(rtrim(REL_PATH, '/'), '/').'$/', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))), '/'); + $this->baseURL = 'http://'.$_SERVER['HTTP_HOST'].$base_path.'/core/install/'; + set_error_handler( Array(&$this, 'ErrorHandler') ); if (file_exists($this->INIFile)) { // if config.php found, then check his write permission too $this->writeableFolders[] = '/config.php'; } + $this->systemConfig = $this->ParseConfig(true); + $this->systemConfig['Misc']['WriteablePath'] = '/system'; // for development purposes + $this->currentStep = $this->GetVar('step'); - if (!$this->stepsPreset) { - $this->stepsPreset = 'fresh_install'; - } + $this->SelectPreset(); if (!$this->currentStep) { // first step of current preset reset($this->steps[$this->stepsPreset]); $this->currentStep = current($this->steps[$this->stepsPreset]); } - $this->systemConfig = $this->ParseConfig(true); - - $this->systemConfig['Misc']['WriteablePath'] = '/system'; // for development purposes - $this->InitStep(); + } + + /** + * Selects preset to proceed based on various criteria + * + */ + function SelectPreset() + { + $preset = 'fresh_install'; - $base_path = rtrim(preg_replace('/'.preg_quote(rtrim(REL_PATH, '/'), '/').'$/', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))), '/'); - $this->baseURL = 'http://'.$_SERVER['HTTP_HOST'].$base_path.'/core/install/'; + if (file_exists($this->INIFile) && $this->GetVar('step') === false) { + // only at installation first step + $status = $this->CheckDatabase(false); + if ($status && $this->AlreadyInstalled()) { + $preset = 'already_installed'; + } + } + + $this->stepsPreset = $preset; } function GetVar($name) @@ -148,16 +168,13 @@ */ function InitStep() { - $go_next = $this->GetVar('step') === false ? false : true; - $this->InitApplication(); switch ($this->currentStep) { case 'check_paths': foreach ($this->writeableFolders as $folder_path) { $file_path = FULL_PATH.$folder_path; if (!is_writable($file_path)) { - $go_next = false; $this->errorMessage = 'Install cannot write to specified folder in the root directory of your installation'; break; } @@ -184,6 +201,25 @@ } } break; + + case 'choose_modules': + // if no modules found, then proceed to next step + $modules = $this->ScanModules(); + if (!$modules) { + $this->currentStep = $this->GetNextStep(); + } + break; + + case 'install_setup': + $next_preset = $this->GetVar('preset'); + if (!$next_preset) { + // if preset was not choosen, then raise error + $this->errorMessage = 'Please select action to perform'; + } + else { + // if preset was choosen, then check root password entered + } + break; } $this->PerformValidation(); // returns validation status (just in case) @@ -218,7 +254,7 @@ if (!$status) break; // 2. check permissions, that use have in this database - $status = $this->CheckDatabase(true); + $status = $this->CheckDatabase(); break; case 'root_password': @@ -348,8 +384,18 @@ return $this->Conn->errorCode == 0; } - function CheckDatabase($check_installed = false) + /** + * Checks if core is already installed + * + * @return bool + */ + function AlreadyInstalled() { + return $this->TableExists('ConfigurationAdmin'); //,Category,Permissions'); + } + + function CheckDatabase($check_installed = true) + { // perform various check type to database specified // 1. user is allowed to connect to database // 2. user has all types of permissions in database @@ -385,11 +431,8 @@ if ($status) { // if statements work & connection made, then check table existance - $already_installed = $this->TableExists('ConfigurationAdmin,Category,Permissions'); - - if ($check_installed && $already_installed) { - // already installed at that location - $this->errorMessage = 'An In-Portal Database already exists at this location'; // : 'An In-Portal Database was not found at this location'; + if ($check_installed && $this->AlreadyInstalled()) { + $this->errorMessage = 'An In-Portal Database already exists at this location'; return false; } } @@ -483,159 +526,50 @@ } /** + * Returns modules list found in modules folder + * + * @return Array + */ + function ScanModules() + { + static $modules = null; + + if (!isset($modules)) { + $modules = Array(); + $fh = opendir(MODULES_PATH); + while (($sub_folder = readdir($fh))) { + $folder_path = MODULES_PATH.'/'.$sub_folder; + if ($sub_folder != '.' && $sub_folder != '..' && is_dir($folder_path)) { + if ($sub_folder == 'core') { + // skip modules here + continue; + } + // this is folder in MODULES_PATH directory + if (file_exists($folder_path.'/install.php') && file_exists($folder_path.'/install/install_schema.sql')) { + $modules[] = $sub_folder; + } + } + } + } + + return $modules; + } + + /** * Returns content to show for current step * * @return string */ function GetStepBody() { - ob_start(); - switch ($this->currentStep) { - case 'check_paths': - ?> - - %s - %s - - writeableFolders as $folder_path) { - $file_path = FULL_PATH.$folder_path; - $folder_status = is_writable($file_path) ? 'OK' : 'FAILED'; - echo sprintf($folder_tpl, $file_path, $folder_status); - } - break; - - case 'db_config': - ?> - - Server Type*: - - - - - - - Hostname*: - - - - - - - Database Name*: - - - - - - - Database User Name*: - - - - - - - Database User Password: - - - - - - - Table Name Prefix: - - - - - - - - Root Password: - - - - - - - - Confirm Root Password: - - - - - - - - - - - - - - - In-portal has successfully been installed on your server. - Click the button below to log into the site administration - using the root password you just configured.
- - - currentStep.'.tpl'; + if (file_exists($step_template)) { + ob_start(); + include_once ($step_template); + return ob_get_clean(); } - return ob_get_clean(); + return '{step template "'.$this->currentStep.'" missing}'; } /**