From 0a82b6933e42667c2fcf8584c2634bb72fcb6c36 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 10 Jul 2014 13:53:44 +0000 Subject: [PATCH] Use step-by-step installation process --- src/mibew/configs/routing_install.yml | 38 ++ .../AccessControl/Check/CanInstallCheck.php | 31 ++ .../Mibew/Controller/InstallController.php | 485 +++++++++++++++--- src/mibew/libs/classes/Mibew/Installer.php | 251 +++++---- .../styles/pages/default/css/default.css | 4 + .../server_side/install_done.handlebars | 18 + .../server_side/install_password.handlebars | 35 ++ ...dex.handlebars => install_step.handlebars} | 28 +- 8 files changed, 694 insertions(+), 196 deletions(-) create mode 100644 src/mibew/libs/classes/Mibew/AccessControl/Check/CanInstallCheck.php create mode 100644 src/mibew/styles/pages/default/templates_src/server_side/install_done.handlebars create mode 100644 src/mibew/styles/pages/default/templates_src/server_side/install_password.handlebars rename src/mibew/styles/pages/default/templates_src/server_side/{install_index.handlebars => install_step.handlebars} (76%) diff --git a/src/mibew/configs/routing_install.yml b/src/mibew/configs/routing_install.yml index 90ea3289..405182cf 100644 --- a/src/mibew/configs/routing_install.yml +++ b/src/mibew/configs/routing_install.yml @@ -3,7 +3,45 @@ install: defaults: _controller: Mibew\Controller\InstallController::indexAction +install_check_requirements: + path: /install/check-requirements + defaults: + _controller: Mibew\Controller\InstallController::checkRequirementsAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + +install_check_connection: + path: /install/check-connection + defaults: + _controller: Mibew\Controller\InstallController::checkConnectionAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + install_create_tables: path: /install/create-tables defaults: _controller: Mibew\Controller\InstallController::createTablesAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + +install_set_password: + path: /install/set-password + defaults: + _controller: Mibew\Controller\InstallController::showPasswordFormAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + methods: [GET] + +install_set_password_submit: + path: /install/set-password + defaults: + _controller: Mibew\Controller\InstallController::submitPasswordFormAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + methods: [POST] + +install_import_locales: + path: /install/import-locales + defaults: + _controller: Mibew\Controller\InstallController::importLocalesAction + _access_check: Mibew\AccessControl\Check\CanInstallCheck + +install_done: + path: /install/done + defaults: + _controller: Mibew\Controller\InstallController::doneAction diff --git a/src/mibew/libs/classes/Mibew/AccessControl/Check/CanInstallCheck.php b/src/mibew/libs/classes/Mibew/AccessControl/Check/CanInstallCheck.php new file mode 100644 index 00000000..323d278f --- /dev/null +++ b/src/mibew/libs/classes/Mibew/AccessControl/Check/CanInstallCheck.php @@ -0,0 +1,31 @@ + MIBEW_VERSION, - 'localeLinks' => get_locale_links(), - 'fixedwrap' => true, - 'title' => getlocal("Installation"), - ); - - $installer = $this->getInstaller(); - $state = $installer->install($request->getBasePath()); - $installation_error = $state == Installer::STATE_NEED_UPDATE_TABLES - || $state == Installer::STATE_ERROR; - - if ($installation_error) { - $page['title'] = getlocal('Problem'); - $page['no_right_menu'] = true; - - if ($state == Installer::STATE_NEED_UPDATE_TABLES) { - // The installer should not update tables structure. - $page['errors'] = array( - getlocal('Mibew is already installed and must be updated. Use the updater.') + // Check if Mibew is already installed. + $in_progress = !empty($_SESSION[SESSION_PREFIX . 'installation_in_progress']); + if (!$in_progress) { + if ($this->getInstaller()->isInstalled()) { + // The system is already installed. + return new Response( + $this->renderError( + 'install_err', + array('errors' => array(getlocal('The system is already installed!'))) + ), + 403 ); - } else { - // Installer thinks that something went wrong. Believe it and - // use its errors. - $page['errors'] = $installer->getErrors(); } - return $this->render('install_err', $page); + // The system is not installed. Mark the user to know that he starts + // installation. + $_SESSION[SESSION_PREFIX . 'installation_in_progress'] = true; + $this->setCurrentStep(self::STEP_CHECK_REQUIREMENTS); } - $page['done'] = $installer->getLog(); - $page['errors'] = $installer->getErrors(); - - if ($state == Installer::STATE_SUCCESS || $state == Installer::STATE_NEED_CHANGE_PASSWORD) { - // Everything is ok. The installation is completed. - $page['soundcheck'] = true; - $page['done'][] = getlocal("Click to check the sound: {0} and {1}", array( - "" . getlocal("New Visitor") . "", - "" . getlocal("New Message") . "" - )); - $page['done'][] = getlocal("Application installed successfully."); - - if ($state == Installer::STATE_NEED_CHANGE_PASSWORD) { - $notice = getlocal('You can logon as admin with empty password.') - . '

' - . '' - . getlocal( - 'For security reasons please change your password immediately and remove {0} file from your server.', - array(MIBEW_WEB_ROOT . '/install.php') - ) - . ''; - - $page['nextstep'] = getlocal("Proceed to the login page"); - $page['nextnotice'] = $notice; - $page['nextstepurl'] = $this->generateUrl('login', array('login' => 'admin')); - } - } elseif ($state == Installer::STATE_NEED_CREATE_TABLES) { - // There is no tables in the database. We need to create them. - $page['nextstep'] = getlocal("Create required tables."); - $page['nextstepurl'] = $this->generateUrl('install_create_tables'); - } else { - throw new \RuntimeException( - sprintf('Unknown installer state "%s".', $state) - ); - } - - return $this->render('install_index', $page); + // Run an installation step. + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); } /** - * An action that create necessary database tables. + * Renders a page for "Check requirements" installation step. * - * @param Request $request Incoming request - * @return string Rendered page content. + * @param Request $request Incoming request. + * @return Response */ - public function createTablesAction(Request $request) + public function checkRequirementsAction(Request $request) { - $installer = $this->getInstaller(); + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_CHECK_REQUIREMENTS) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_CHECK_REQUIREMENTS) { + $this->setCurrentStep(self::STEP_CHECK_REQUIREMENTS); + } - if (!$installer->createTables()) { - // By some reasons tables cannot be created. Tell it to the user. - return $this->render( + $installer = $this->getInstaller(); + if (!$installer->checkRequirements($request->getBasePath())) { + return $this->renderError( 'install_err', - array( - 'version' => MIBEW_VERSION, - 'localeLinks' => get_locale_links(), - 'title' => getlocal('Problem'), - 'no_right_menu' => true, - 'fixedwrap' => true, - 'errors' => $installer->getErrors(), - ) + array('error' => $installer->getErrors()) ); } - // Tables are successfully created. Go back to the main installation - // page. - return $this->redirect($this->generateUrl('install')); + // Everything is fine. Log the messages and go to the next step + $this->setLog(self::STEP_CHECK_REQUIREMENTS, $installer->getLog()); + $this->setCurrentStep(self::STEP_CHECK_CONNECTION); + + return $this->renderStep( + 'install_step', + array('nextstep' => getlocal('Check database connection')) + ); + } + + /** + * Renders a page for "Check connection" installation step. + * + * @param Request $request Incoming request. + * @return Response + */ + public function checkConnectionAction(Request $request) + { + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_CHECK_CONNECTION) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_CHECK_CONNECTION) { + $this->setCurrentStep(self::STEP_CHECK_CONNECTION); + } + + $installer = $this->getInstaller(); + if (!$installer->checkConnection()) { + return $this->renderError( + 'install_err', + array('error' => $installer->getErrors()) + ); + } + + // Everything is fine. Go to the next step. + $this->setLog(self::STEP_CHECK_CONNECTION, $installer->getLog()); + $this->setCurrentStep(self::STEP_CREATE_TABLES); + + return $this->renderStep( + 'install_step', + array('nextstep' => getlocal('Create necessary tables')) + ); + } + + /** + * Renders a page for "Create tables" installation step. + * + * @param Request $request Incoming request. + * @return Response + */ + public function createTablesAction(Request $request) + { + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_CREATE_TABLES) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_CREATE_TABLES) { + $this->setCurrentStep(self::STEP_CREATE_TABLES); + } + + $installer = $this->getInstaller(); + if (!$installer->createTables()) { + return $this->renderError( + 'install_err', + array('error' => $installer->getErrors()) + ); + } + + $this->setLog(self::STEP_CREATE_TABLES, $installer->getLog()); + $this->setCurrentStep(self::STEP_SET_PASSWORD); + + return $this->renderStep( + 'install_step', + array('nextstep' => getlocal('Set administrator password')) + ); + } + + /** + * Renders a page for "Set password" installation step. + * + * @param Request $request Incoming request. + * @return Response + */ + public function showPasswordFormAction(Request $request) + { + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_SET_PASSWORD) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_SET_PASSWORD) { + $this->setCurrentStep(self::STEP_SET_PASSWORD); + } + + return $this->renderStep( + 'install_password', + array( + 'errors' => $request->attributes->get('errors', array()), + ) + ); + } + + /** + * Processes submitting of password form. + * + * @param Request $request Incoming request. + * @return Response + */ + public function submitPasswordFormAction(Request $request) + { + // Check if the user can run this step + if ($this->getCurrentStep() != self::STEP_SET_PASSWORD) { + $this->redirect($this->generateStepUrl(self::STEP_SET_PASSWORD)); + } + + $password = $request->request->get('password'); + $password_confirm = $request->request->get('password_confirm'); + $errors = array(); + + // Validate passwords + if (!$password) { + $errors[] = no_field('Password'); + } + if (!$password_confirm) { + $errors[] = no_field('Confirmation'); + } + if ($password !== $password_confirm) { + $errors[] = getlocal('Passwords do not match.'); + } + if (!empty($errors)) { + // Something went wrong we should rerender the form. + $request->attributes->set('errors', $errors); + + return $this->showPasswordFormAction($request); + } + + $installer = $this->getInstaller(); + if (!$installer->setPassword($password)) { + return $this->renderError( + 'install_err', + array('errors' => $installer->getErrors()) + ); + } + + $this->setLog( + self::STEP_SET_PASSWORD, + array(getlocal('Password is set.')) + ); + $this->setCurrentStep(self::STEP_IMPORT_LOCALES); + + return $this->renderStep( + 'install_step', + array('nextstep' => getlocal('Import locales')) + ); + } + + /** + * Renders a page for "Import locales" installation step. + * + * @param Request $request Incoming request. + * @return Response + */ + public function importLocalesAction() + { + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_IMPORT_LOCALES) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_IMPORT_LOCALES) { + $this->setCurrentStep(self::STEP_IMPORT_LOCALES); + } + + $installer = $this->getInstaller(); + if (!$installer->importLocales()) { + return $this->renderError( + 'install_err', + array('errors' => $installer->getErrors()) + ); + } + + $this->setLog(self::STEP_IMPORT_LOCALES, $installer->getLog()); + $this->setCurrentStep(self::STEP_DONE); + + return $this->renderStep( + 'install_step', + array('nextstep' => getlocal('Check sound and lock the installation')) + ); + } + + /** + * Renders a page for "Done" installation step. + * + * @param Request $request Incoming request. + * @return Response + */ + public function doneAction(Request $request) + { + if (empty($_SESSION[SESSION_PREFIX . 'installation_in_progress'])) { + // The installation has been finished (or had not been started yet) + // We should prevent access to this action but cannot use Access + // Check functionallity becase the user should be redirected to the + // beginnig. + return $this->redirect($this->generateUrl('install')); + } + + // Check if the user can run this step + if ($this->getCurrentStep() < self::STEP_DONE) { + return $this->redirect($this->generateStepUrl($this->getCurrentStep())); + } elseif ($this->getCurrentStep() != self::STEP_DONE) { + $this->setCurrentStep(self::STEP_DONE); + } + + // The installation is done. + unset($_SESSION[SESSION_PREFIX . 'installation_in_progress']); + + $login_link = getlocal( + 'You can login to usgin this link.', + array($this->generateUrl('login', array('user' => 'admin'))) + ); + + return $this->renderStep( + 'install_done', + array('loginLink' => $login_link) + ); + } + + /** + * Renders installation step page. + * + * It is just a wrapper for {@link AbstractController::render()} method + * which adds several default values to $parameters array. + * + * @param string $template Name of the template which should be rendered + * @param array $parameters List of values that should be passed to the + * template. + * @return string Rendered page content + */ + protected function renderStep($template, array $parameters = array()) + { + // Add default values + $parameters += array( + 'version' => MIBEW_VERSION, + 'localeLinks' => get_locale_links(), + 'fixedwrap' => true, + 'title' => getlocal('Installation'), + 'done' => $this->getLog(), + 'error' => array(), + 'nextstep' => false, + 'nextstepurl' => $this->generateStepUrl($this->getCurrentStep()), + 'nextnotice' => false, + ); + + return $this->render($template, $parameters); + } + + /** + * Renders installation error page. + * + * It is just a wrapper for {@link AbstractController::render()} method + * which adds several default values to $parameters array. + * + * @param string $template Name of the template which should be rendered + * @param array $parameters List of values that should be passed to the + * template. + * @return string Rendered page content + */ + protected function renderError($template, array $parameters = array()) + { + // Add default values + $parameters += array( + 'version' => MIBEW_VERSION, + 'localeLinks' => get_locale_links(), + 'title' => getlocal('Problem'), + 'fixedwrap' => true, + ); + + return $this->render($template, $parameters); + } + + /** + * Returns log messages for all steps excluding current. + * + * @return string[] List of logged messages. + */ + protected function getLog() + { + if (!isset($_SESSION[SESSION_PREFIX . 'installation_log'])) { + return array(); + } + + $log = array(); + foreach ($_SESSION[SESSION_PREFIX . 'installation_log'] as $step => $messages) { + if ($this->getCurrentStep() <= $step) { + // Combine only messages for previous steps + break; + } + $log = array_merge($log, $messages); + } + + return $log; + } + + /** + * Sets log for the specified installation step. + * + * @param integer $step An installation step. One of + * InstallController::STEP_* constants. + * @param string[] $messages List of logged messages. + */ + protected function setLog($step, $messages) + { + $_SESSION[SESSION_PREFIX . 'installation_log'][$step] = $messages; + } + + /** + * Returns current step of the installation process. + * + * @return integer An installation step. One of InstallController::STEP_* + * constants. + */ + protected function getCurrentStep() + { + // Set current step from the session. + return $this->currentStep = isset($_SESSION[SESSION_PREFIX . 'installation_step']) + ? $_SESSION[SESSION_PREFIX . 'installation_step'] + : self::STEP_CHECK_REQUIREMENTS; + } + + /** + * Sets the current installation step. + * + * @param integer $step An installation step. One of + * InstallController::STEP_* constants. + */ + protected function setCurrentStep($step) + { + $_SESSION[SESSION_PREFIX . 'installation_step'] = $step; + } + + /** + * Generates URL for the specified installation step. + * + * @param integer $step An installation step. One of + * InstallController::STEP_* constants. + * @return string An URL for the specified step. + * @throws \InvalidArgumentException If the step is unknown. + */ + protected function generateStepUrl($step) + { + $routes_map = array( + self::STEP_CHECK_REQUIREMENTS => 'install_check_requirements', + self::STEP_CHECK_CONNECTION => 'install_check_connection', + self::STEP_CREATE_TABLES => 'install_create_tables', + self::STEP_SET_PASSWORD => 'install_set_password', + self::STEP_IMPORT_LOCALES => 'install_import_locales', + self::STEP_DONE => 'install_done', + ); + + if (!array_key_exists($step, $routes_map)) { + throw new \InvalidArgumentException(sprintf( + 'Unknown step "%s"', + $step + )); + } + + return $this->generateUrl($routes_map[$step]); } /** diff --git a/src/mibew/libs/classes/Mibew/Installer.php b/src/mibew/libs/classes/Mibew/Installer.php index 6723acb8..96f6ff2c 100644 --- a/src/mibew/libs/classes/Mibew/Installer.php +++ b/src/mibew/libs/classes/Mibew/Installer.php @@ -30,31 +30,6 @@ class Installer */ const MIN_PHP_VERSION = 50303; - /** - * Installation process finished with error. - */ - const STATE_ERROR = 'error'; - - /** - * Installation process finished successfully. - */ - const STATE_SUCCESS = 'success'; - - /** - * Database tables should be created. - */ - const STATE_NEED_CREATE_TABLES = 'need_create_tables'; - - /** - * Database tables should be updated. - */ - const STATE_NEED_UPDATE_TABLES = 'need_update_tables'; - - /** - * Indicates that the main admin must change his password. - */ - const STATE_NEED_CHANGE_PASSWORD = 'need_change_password'; - /** * Associative array of system configs. * @@ -115,17 +90,34 @@ class Installer } /** - * Install Mibew. + * Checks if Mibew is already installed or not. + * + * @return boolean + */ + public function isInstalled() + { + return ($this->getDatabaseVersion() !== false); + } + + /** + * Checks installation requirements. + * + * It is one of the installation steps. Normally it should be called the + * first one. + * + * One can get all logged messages of this step using + * {@link Installer::getLog()} method. Also the list of all errors can be + * got using {@link \Mibew\Installer::getErrors()}. * * @param string $real_base_path Real base path of the Mibew instance. For * example if one tries to install Mibew to http://example.com/foo/mibew/ * the argument should be equal to "foo/mibew". - * @return string Installation state. One of Installer::STATE_* constant. + * @return boolean True if all reqirements are satisfied and false otherwise */ - public function install($real_base_path) + public function checkRequirements($real_base_path) { if (!$this->checkPhpVersion()) { - return self::STATE_ERROR; + return false; } $this->log[] = getlocal( @@ -134,7 +126,7 @@ class Installer ); if (!$this->checkMibewRoot($real_base_path)) { - return self::STATE_ERROR; + return false; } $this->log[] = getlocal( @@ -142,12 +134,29 @@ class Installer array($real_base_path) ); - if (!$this->checkConnection()) { - return self::STATE_ERROR; + return true; + } + + /** + * Checks database connection and MySQL version. + * + * It is one of the installation steps. Normally it should be called after + * {@link Installer::checkRequirements()}. + * + * One can get all logged messages of this step using + * {@link Installer::getLog()} method. Also the list of all errors can be + * got using {@link \Mibew\Installer::getErrors()}. + * + * @return boolean True if connection is established and false otherwise. + */ + public function checkConnection() + { + if (!$this->doCheckConnection()) { + return false; } if (!$this->checkMysqlVersion()) { - return self::STATE_ERROR; + return false; } $this->log[] = getlocal( @@ -155,41 +164,123 @@ class Installer array($this->getMysqlVersion()) ); - if (!$this->databaseExists()) { - return self::STATE_NEED_CREATE_TABLES; + return true; + } + + /** + * Create tables and prepopulate them with some info. + * + * It is one of the installation steps. Normally it should be called after + * {@link Installer::checkConnection()}. + * + * One can get all logged messages of this step using + * {@link Installer::getLog()} method. Also the list of all errors can be + * got using {@link \Mibew\Installer::getErrors()}. + * + * @return boolean True if all tables are created and false otherwise. + */ + public function createTables() + { + if ($this->tablesExist() && $this->tablesNeedUpdate()) { + // Tables already exists but they should be updated + $this->errors[] = getlocal('The tables are alredy in place but outdated. Run the updater to fix it.'); + + return false; } - if ($this->databaseNeedUpdate()) { - return self::STATE_NEED_UPDATE_TABLES; + if ($this->tablesExist()) { + $this->log[] = getlocal('Tables structure is up to date.'); + + return true; } - $this->log[] = getlocal('Required tables are created.'); - $this->log[] = getlocal('Tables structure is up to date.'); + // There are no tables in the database. We need to create them. + if (!$this->doCreateTables()) { + return false; + } + $this->log[] = getlocal('Tables are created.'); - if (!$this->importLocales()) { - return self::STATE_ERROR; + if (!$this->prepopulateDatabase()) { + return false; + } + $this->log[] = getlocal('Tables are pre popluated with necessary info.'); + + return true; + } + + /** + * Sets password of the main administrator of the system. + * + * It is one of the installation steps. Normally it should be called after + * {@link Installer::createTables()}. + * + * One can get all logged messages of this step using + * {@link Installer::getLog()} method. Also the list of all errors can be + * got using {@link \Mibew\Installer::getErrors()}. + * + * @param string $password Administrator password. + * @return boolean True if the password was set and false otherwise. + */ + public function setPassword($password) + { + if (!($db = $this->getDatabase())) { + return false; + } + + try { + $db->query( + 'UPDATE {chatoperator} SET vcpassword = :pass WHERE vclogin = :login', + array( + ':login' => 'admin', + ':pass' => calculate_password_hash('admin', $password) + ) + ); + } catch (\Exception $e) { + $this->errors[] = getlocal( + 'Cannot set password. Error: {0}', + array($e->getMessage()) + ); + + return false; + } + + return true; + } + + /** + * Import locales and all their content to the database. + * + * It is one of the installation steps. Normally it should be called after + * {@link Installer::createTables()}. + * + * One can get all logged messages of this step using + * {@link Installer::getLog()} method. Also the list of all errors can be + * got using {@link \Mibew\Installer::getErrors()}. + * + * @return boolean True if all locales with content are imported + * successfully and false otherwise. + */ + public function importLocales() + { + if (!$this->doImportLocales()) { + return false; } $this->log[] = getlocal('Locales are imported.'); if (!$this->importLocalesContent()) { - return self::STATE_ERROR; + return false; } $this->log[] = getlocal('Locales content is imported.'); - if ($this->needChangePassword()) { - return self::STATE_NEED_CHANGE_PASSWORD; - } - - return self::STATE_SUCCESS; + return true; } /** * Creates necessary tables. * - * @return boolean Indicates if tables created or not. A list of all errors - * can be got using {@link \Mibew\Installer::getErrors()} method. + * @return boolean Indicates if tables created or not. */ - public function createTables() + protected function doCreateTables() { if (!($db = $this->getDatabase())) { return false; @@ -234,7 +325,7 @@ class Installer implode(', ', $table_items) )); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->errors[] = getlocal( 'Cannot create tables. Error: {0}', array($e->getMessage()) @@ -243,10 +334,6 @@ class Installer return false; } - if (!$this->prepopulateDatabase()) { - return false; - } - return true; } @@ -292,7 +379,7 @@ class Installer ) ); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->errors[] = getlocal( 'Cannot create the first administrator. Error {0}', array($e->getMessage()) @@ -317,7 +404,7 @@ class Installer array(':init_revision' => 1) ); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->errors[] = getlocal( 'Cannot initialize chat revision sequence. Error {0}', array($e->getMessage()) @@ -345,7 +432,7 @@ class Installer ) ); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->errors[] = getlocal( 'Cannot store database structure version. Error {0}', array($e->getMessage()) @@ -386,7 +473,7 @@ class Installer * * @return boolean True if connection is established and false otherwise. */ - protected function checkConnection() + protected function doCheckConnection() { if (!$this->getDatabase()) { return false; @@ -509,7 +596,7 @@ class Installer * * @return boolean */ - protected function databaseNeedUpdate() + protected function tablesNeedUpdate() { return ($this->getDatabaseVersion() < DB_VERSION); } @@ -519,54 +606,18 @@ class Installer * * @return boolean */ - protected function databaseExists() + protected function tablesExist() { return ($this->getDatabaseVersion() !== false); } /** - * Check if the admin must change his password to a new one. - * - * @return boolean True if the password must be changed and false otherwise. - */ - protected function needChangePassword() - { - if (!($db = $this->getDatabase())) { - return false; - } - - try { - $admin = $db->query( - 'SELECT * FROM {chatoperator} WHERE vclogin = :login', - array(':login' => 'admin'), - array('return_rows' => Database::RETURN_ONE_ROW) - ); - } catch (\Exception $e) { - $this->errors[] = getlocal( - 'Cannot load the main administrator\'s data. Error: {0}', - array($e->getMessage()) - ); - - return false; - } - - if (!$admin) { - $this->errors[] = getlocal('The main administrator has disappeared ' - . 'from the database. Do not know how to continue'); - - return false; - } - - return ($admin['vcpassword'] == md5('')); - } - - /** - * Import all available locales to the database and enable each of them. + * Import all available locales to the database. * * @return boolean Indicates if the locales were imported correctly. True if * everything is OK and false otherwise. */ - protected function importLocales() + protected function doImportLocales() { if (!($db = $this->getDatabase())) { return false; @@ -697,7 +748,7 @@ class Installer $this->configs['database']['db'], $this->configs['database']['tables_prefix'] ); - } catch(\PDOException $e) { + } catch (\PDOException $e) { $this->errors[] = getlocal( "Could not connect. Please check server settings in config.yml. Error: {0}", array($e->getMessage()) diff --git a/src/mibew/styles/pages/default/css/default.css b/src/mibew/styles/pages/default/css/default.css index d7780c26..b2486484 100644 --- a/src/mibew/styles/pages/default/css/default.css +++ b/src/mibew/styles/pages/default/css/default.css @@ -927,6 +927,10 @@ table.awaiting .no-threads, table.awaiting .no-visitors { margin-left: 2em; } +#install .password-form { + margin-left: 2em; +} + #check-nv, #check-nm { color: #2f7599; text-decoration: none; diff --git a/src/mibew/styles/pages/default/templates_src/server_side/install_done.handlebars b/src/mibew/styles/pages/default/templates_src/server_side/install_done.handlebars new file mode 100644 index 00000000..f9afb1b8 --- /dev/null +++ b/src/mibew/styles/pages/default/templates_src/server_side/install_done.handlebars @@ -0,0 +1,18 @@ +{{#extends "install_step"}} + {{#override "nextStep"}} +
+ {{l10n "Application installed successfully."}} {{{loginLink}}} +
+
+ + + {{l10n "Click to check the sound"}}: + +
+ {{l10n "For security reasons you should remove install.php file from your server."}} + + {{/override}} +{{/extends}} \ No newline at end of file diff --git a/src/mibew/styles/pages/default/templates_src/server_side/install_password.handlebars b/src/mibew/styles/pages/default/templates_src/server_side/install_password.handlebars new file mode 100644 index 00000000..da9a929b --- /dev/null +++ b/src/mibew/styles/pages/default/templates_src/server_side/install_password.handlebars @@ -0,0 +1,35 @@ +{{#extends "install_step"}} + {{#override "nextStep"}} +
+
+ + {{l10n "Type a password for the first administrator"}}: + +
+ +
+
+
{{l10n "Password"}}:
+
+ +
+
+
+ +
+
{{l10n "Confirmation"}}:
+
+ +
+
+
+ +
+ +
+ +
+ +
+ {{/override}} +{{/extends}} \ No newline at end of file diff --git a/src/mibew/styles/pages/default/templates_src/server_side/install_index.handlebars b/src/mibew/styles/pages/default/templates_src/server_side/install_step.handlebars similarity index 76% rename from src/mibew/styles/pages/default/templates_src/server_side/install_index.handlebars rename to src/mibew/styles/pages/default/templates_src/server_side/install_step.handlebars index f184c01c..82ac8908 100644 --- a/src/mibew/styles/pages/default/templates_src/server_side/install_index.handlebars +++ b/src/mibew/styles/pages/default/templates_src/server_side/install_step.handlebars @@ -48,22 +48,24 @@ {{/each}} - {{#if nextstep}} -
-
+ {{#block "nextStep"}} + {{#if nextstep}} +
+
- {{l10n "Next step:"}} + {{l10n "Next step:"}} - + {{/if}} + {{/block}}