aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/install/controller/install.php
blob: c1329b6456088c7d6d489d93209c4f7b393f2891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?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\controller;

use phpbb\install\helper\config;
use phpbb\install\helper\navigation\navigation_provider;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\Response;
use phpbb\install\helper\iohandler\factory;
use phpbb\install\controller\helper;
use phpbb\template\template;
use phpbb\request\request_interface;
use phpbb\install\installer;
use phpbb\language\language;

/**
 * Controller for installing phpBB
 */
class install
{
	/**
	 * @var helper
	 */
	protected $controller_helper;

	/**
	 * @var config
	 */
	protected $installer_config;

	/**
	 * @var factory
	 */
	protected $iohandler_factory;

	/**
	 * @var navigation_provider
	 */
	protected $menu_provider;

	/**
	 * @var language
	 */
	protected $language;

	/**
	 * @var template
	 */
	protected $template;

	/**
	 * @var request_interface
	 */
	protected $request;

	/**
	 * @var installer
	 */
	protected $installer;

	/**
	 * Constructor
	 *
	 * @param helper 				$helper
	 * @param config				$install_config
	 * @param factory 				$factory
	 * @param navigation_provider	$nav_provider
	 * @param language				$language
	 * @param request_interface		$request
	 * @param 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)
	{
		$this->controller_helper	= $helper;
		$this->installer_config		= $install_config;
		$this->iohandler_factory	= $factory;
		$this->menu_provider		= $nav_provider;
		$this->language				= $language;
		$this->template				= $template;
		$this->request				= $request;
		$this->installer			= $installer;
	}

	/**
	 * Controller logic
	 *
	 * @return Response|StreamedResponse
	 */
	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'),
		));

		// Set up input-output handler
		if ($this->request->is_ajax())
		{
			$this->iohandler_factory->set_environment('ajax');
		}
		else
		{
			$this->iohandler_factory->set_environment('nojs');
		}

		// Set the appropriate input-output handler
		$this->installer->set_iohandler($this->iohandler_factory->get());

		// Set up navigation
		$nav_data = $this->installer_config->get_navigation_data();
		/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
		$iohandler = $this->iohandler_factory->get();

		// Set active navigation stage
		if (isset($nav_data['active']) && is_array($nav_data['active']))
		{
			$iohandler->set_active_stage_menu($nav_data['active']);
			$this->menu_provider->set_nav_property($nav_data['active'], array(
				'selected'	=> true,
				'completed'	=> false,
			));
		}

		// Set finished navigation stages
		if (isset($nav_data['finished']) && is_array($nav_data['finished']))
		{
			foreach ($nav_data['finished'] as $finished_stage)
			{
				$iohandler->set_finished_stage_menu($finished_stage);
				$this->menu_provider->set_nav_property($finished_stage, array(
					'selected'	=> false,
					'completed'	=> true,
				));
			}
		}

		if ($this->request->is_ajax())
		{
			$installer = $this->installer;
			$response = new StreamedResponse();
			$response->setCallback(function() use ($installer) {
				$installer->run();
			});

			return $response;
		}
		else
		{
			// Determine whether the installation was started or not
			if (true)
			{
				// Set active stage
				$this->menu_provider->set_nav_property(
					array('install', 0, 'introduction'),
					array(
						'selected'	=> true,
						'completed'	=> false,
					)
				);

				// If not, let's render the welcome page
				$this->template->assign_vars(array(
					'SHOW_INSTALL_START_FORM'	=> true,
					'TITLE'						=> $this->language->lang('INSTALL_INTRO'),
					'CONTENT'					=> $this->language->lang('INSTALL_INTRO_BODY'),
				));
				return $this->controller_helper->render('installer_install.html', 'INSTALL');
			}

			// @todo: implement no js controller logic
		}
	}
}