mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-07 16:24:43 +03:00
Use step-by-step installation process
This commit is contained in:
parent
0820dc9997
commit
0a82b6933e
@ -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
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\AccessControl\Check;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Checks if the user can access istallation step.
|
||||
*/
|
||||
class CanInstallCheck extends AbstractCheck
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
return !empty($_SESSION[SESSION_PREFIX . 'installation_in_progress']);
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ namespace Mibew\Controller;
|
||||
use Mibew\Installer;
|
||||
use Mibew\Style\PageStyle;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Process all pages related with installation.
|
||||
@ -33,111 +34,429 @@ class InstallController extends AbstractController
|
||||
*/
|
||||
protected $installer = null;
|
||||
|
||||
const STEP_CHECK_REQUIREMENTS = 0;
|
||||
const STEP_CHECK_CONNECTION = 1;
|
||||
const STEP_CREATE_TABLES = 2;
|
||||
const STEP_SET_PASSWORD = 3;
|
||||
const STEP_IMPORT_LOCALES = 4;
|
||||
const STEP_DONE = 5;
|
||||
|
||||
/**
|
||||
* The main entry point of installation process.
|
||||
* Redirects the user to the current installation step.
|
||||
*
|
||||
* @param Request $request Incoming request.
|
||||
* @return string Rendered page content.
|
||||
* @return Response
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
$page = array(
|
||||
'version' => 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(
|
||||
"<a id='check-nv' href='javascript:void(0)'>" . getlocal("New Visitor") . "</a>",
|
||||
"<a id='check-nm' href='javascript:void(0)'>" . getlocal("New Message") . "</a>"
|
||||
));
|
||||
$page['done'][] = getlocal("<b>Application installed successfully.</b>");
|
||||
|
||||
if ($state == Installer::STATE_NEED_CHANGE_PASSWORD) {
|
||||
$notice = getlocal('You can logon as <b>admin</b> with empty password.')
|
||||
. '<br /><br />'
|
||||
. '<span class=\"warning\">'
|
||||
. getlocal(
|
||||
'For security reasons please change your password immediately and remove {0} file from your server.',
|
||||
array(MIBEW_WEB_ROOT . '/install.php')
|
||||
)
|
||||
. '</span>';
|
||||
|
||||
$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 <a href="{0}">this</a> 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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
|
@ -0,0 +1,18 @@
|
||||
{{#extends "install_step"}}
|
||||
{{#override "nextStep"}}
|
||||
<br />
|
||||
<b>{{l10n "Application installed successfully."}}</b> {{{loginLink}}}
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
{{l10n "Click to check the sound"}}:
|
||||
<ul>
|
||||
<li><a id="check-nv" href="javascript:void(0)">{{l10n "New Visitor"}}</a></li>
|
||||
<li><a id="check-nm" href="javascript:void(0)">{{l10n "New Message"}}</a></li>
|
||||
</ul>
|
||||
<br />
|
||||
<span class="warning">{{l10n "For security reasons you should remove install.php file from your server."}}</span>
|
||||
|
||||
{{/override}}
|
||||
{{/extends}}
|
@ -0,0 +1,35 @@
|
||||
{{#extends "install_step"}}
|
||||
{{#override "nextStep"}}
|
||||
<br />
|
||||
<br />
|
||||
|
||||
{{l10n "Type a password for the first administrator"}}:
|
||||
|
||||
<form name="passwordForm" method="post" class="password-form">
|
||||
|
||||
<div class="fieldForm">
|
||||
<div class="field">
|
||||
<div class="fleftlabel">{{l10n "Password"}}:</div>
|
||||
<div class="fvalue">
|
||||
<input type="password" name="password" size="25" value="" class="formauth" autocomplete="off"/>
|
||||
</div>
|
||||
<br clear="all"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<div class="fleftlabel">{{l10n "Confirmation"}}:</div>
|
||||
<div class="fvalue">
|
||||
<input type="password" name="password_confirm" size="25" value="" class="formauth" autocomplete="off"/>
|
||||
</div>
|
||||
<br clear="all"/>
|
||||
</div>
|
||||
|
||||
<div class="fbutton">
|
||||
<input type="submit" name="submit" class="submit-bg-button save-button" value="{{l10n "Save"}}" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{{/override}}
|
||||
{{/extends}}
|
@ -48,22 +48,24 @@
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
||||
{{#if nextstep}}
|
||||
<br/>
|
||||
<br/>
|
||||
{{#block "nextStep"}}
|
||||
{{#if nextstep}}
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
{{l10n "Next step:"}}
|
||||
{{l10n "Next step:"}}
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
{{#if nextnotice}}
|
||||
{{{nextnotice}}}<br/><br/>
|
||||
{{/if}}
|
||||
<ul>
|
||||
<li>
|
||||
{{#if nextnotice}}
|
||||
{{{nextnotice}}}<br/><br/>
|
||||
{{/if}}
|
||||
|
||||
<a href="{{nextstepurl}}">{{nextstep}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
<a href="{{nextstepurl}}">{{nextstep}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
{{/block}}
|
||||
</div>
|
||||
|
||||
<div class="formbottom">
|
Loading…
Reference in New Issue
Block a user