1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-19 15:17:16 +01:00

[ticket/13740] Exit from installation if phpBB is already installed

PHPBB3-13740
This commit is contained in:
Mate Bartus 2015-07-20 19:26:07 +02:00
parent 6216007caa
commit 0488c49116
8 changed files with 103 additions and 12 deletions

View File

@ -21,6 +21,7 @@ services:
- @language
- @installer.helper.iohandler_factory
- @installer.installer.install
- @installer.helper.install_helper
tags:
- { name: console.installer.command }

View File

@ -30,3 +30,4 @@ services:
- @template
- @request
- @installer.installer.install
- @installer.helper.install_helper

View File

@ -56,6 +56,12 @@ services:
- %core.root_path%
- %core.php_ext%
installer.helper.install_helper:
class: phpbb\install\helper\install_helper
arguments:
- %core.root_path%
- %core.php_ext%
# -------- Installer --------------------------------
installer.module_base:
abstract: true

View File

@ -113,7 +113,8 @@ $lang = array_merge($lang, array(
// General error messages
$lang = array_merge($lang, array(
'INST_ERR_MISSING_DATA' => 'You must fill out all fields in this block.',
'INST_ERR_MISSING_DATA' => 'You must fill out all fields in this block.',
'PHPBB_ALREADY_INSTALLED' => 'phpBB is already installed.'
));
// Data obtaining translations

View File

@ -14,6 +14,7 @@
namespace phpbb\install\console\command\install;
use phpbb\install\exception\installer_exception;
use phpbb\install\helper\install_helper;
use phpbb\install\helper\iohandler\cli_iohandler;
use phpbb\install\helper\iohandler\factory;
use phpbb\install\installer;
@ -40,6 +41,11 @@ class install extends \phpbb\console\command\command
*/
protected $installer;
/**
* @var install_helper
*/
protected $install_helper;
/**
* @var language
*/
@ -48,21 +54,22 @@ class install extends \phpbb\console\command\command
/**
* Constructor
*
* @param language $language
* @param factory $factory
* @param installer $installer
* @param language $language
* @param factory $factory
* @param installer $installer
* @param install_helper $install_helper
*/
public function __construct(language $language, factory $factory, installer $installer)
public function __construct(language $language, factory $factory, installer $installer, install_helper $install_helper)
{
$this->iohandler_factory = $factory;
$this->installer = $installer;
$this->language = $language;
$this->install_helper = $install_helper;
parent::__construct(new \phpbb\user($language, 'datetime'));
}
/**
*
* {@inheritdoc}
*/
protected function configure()
@ -89,8 +96,6 @@ class install extends \phpbb\console\command\command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// @todo check that phpBB is not already installed
$this->iohandler_factory->set_environment('cli');
/** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
@ -102,6 +107,11 @@ class install extends \phpbb\console\command\command
$config_file = $input->getArgument('config-file');
if ($this->install_helper->is_phpbb_installed())
{
$iohandler->add_error_message('PHPBB_ALREADY_INSTALLED');
}
if (!is_file($config_file))
{
$iohandler->add_error_message(array('MISSING_FILE', array($config_file)));

View File

@ -219,7 +219,7 @@ class helper
protected function render_language_select()
{
$langs = $this->lang_helper->get_available_languages();
// @todo
// @todo Implement language change option
}
/**

View File

@ -13,7 +13,9 @@
namespace phpbb\install\controller;
use phpbb\exception\http_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\install_helper;
use phpbb\install\helper\navigation\navigation_provider;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\Response;
@ -69,6 +71,11 @@ class install
*/
protected $installer;
/**
* @var install_helper
*/
protected $install_helper;
/**
* Constructor
*
@ -80,8 +87,9 @@ class install
* @param template $template
* @param request_interface $request
* @param installer $installer
* @param install_helper $install_helper
*/
public function __construct(helper $helper, config $install_config, factory $factory, navigation_provider $nav_provider, language $language, template $template, request_interface $request, installer $installer)
public function __construct(helper $helper, config $install_config, factory $factory, navigation_provider $nav_provider, language $language, template $template, request_interface $request, installer $installer, install_helper $install_helper)
{
$this->controller_helper = $helper;
$this->installer_config = $install_config;
@ -91,6 +99,7 @@ class install
$this->template = $template;
$this->request = $request;
$this->installer = $installer;
$this->install_helper = $install_helper;
}
/**
@ -100,8 +109,6 @@ class install
*/
public function handle()
{
// @todo check that phpBB is not already installed
$this->template->assign_vars(array(
'U_ACTION' => $this->controller_helper->route('phpbb_installer_install'),
));
@ -124,6 +131,11 @@ class install
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $this->iohandler_factory->get();
if ($this->install_helper->is_phpbb_installed())
{
throw new http_exception(404, 'PAGE_NOT_FOUND');
}
// Set active navigation stage
if (isset($nav_data['active']) && is_array($nav_data['active']))
{

View File

@ -0,0 +1,60 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\install\helper;
/**
* General helper functionality for the installer
*/
class install_helper
{
/**
* @var string
*/
protected $php_ext;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* Constructor
*
* @param string $phpbb_root_path path to phpBB's root
* @param string $php_ext Extension of PHP files
*/
public function __construct($phpbb_root_path, $php_ext)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Check whether phpBB is installed.
*
* @return bool
*/
public function is_phpbb_installed()
{
$config_path = $this->phpbb_root_path . 'config' . $this->php_ext;
$install_lock_path = $this->phpbb_root_path . 'cache/install_lock';
if (file_exists($config_path) && !file_exists($install_lock_path))
{
include_once $config_path;
}
return defined('PHPBB_INSTALLED');
}
}