Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
install
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\install\controller;
15
16use phpbb\exception\http_exception;
17use phpbb\install\helper\install_helper;
18use phpbb\install\helper\navigation\navigation_provider;
19use Symfony\Component\HttpFoundation\StreamedResponse;
20use Symfony\Component\HttpFoundation\Response;
21use phpbb\install\helper\iohandler\factory;
22use phpbb\template\template;
23use phpbb\request\request_interface;
24use phpbb\install\installer;
25use phpbb\language\language;
26
27/**
28 * Controller for installing phpBB
29 */
30class install
31{
32    /**
33     * @var helper
34     */
35    protected $controller_helper;
36
37    /**
38     * @var factory
39     */
40    protected $iohandler_factory;
41
42    /**
43     * @var navigation_provider
44     */
45    protected $menu_provider;
46
47    /**
48     * @var language
49     */
50    protected $language;
51
52    /**
53     * @var template
54     */
55    protected $template;
56
57    /**
58     * @var request_interface
59     */
60    protected $request;
61
62    /**
63     * @var installer
64     */
65    protected $installer;
66
67    /**
68     * @var install_helper
69     */
70    protected $install_helper;
71
72    /**
73     * Constructor
74     *
75     * @param helper                 $helper
76     * @param factory                 $factory
77     * @param navigation_provider    $nav_provider
78     * @param language                $language
79     * @param template                $template
80     * @param request_interface        $request
81     * @param installer                $installer
82     * @param install_helper        $install_helper
83     */
84    public function __construct(helper $helper, factory $factory, navigation_provider $nav_provider, language $language, template $template, request_interface $request, installer $installer, install_helper $install_helper)
85    {
86        $this->controller_helper    = $helper;
87        $this->iohandler_factory    = $factory;
88        $this->menu_provider        = $nav_provider;
89        $this->language                = $language;
90        $this->template                = $template;
91        $this->request                = $request;
92        $this->installer            = $installer;
93        $this->install_helper        = $install_helper;
94    }
95
96    /**
97     * Controller logic
98     *
99     * @return Response|StreamedResponse
100     *
101     * @throws http_exception When phpBB is already installed
102     * @throws \phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception
103     * @psalm-suppress InvalidNullableReturnType
104     */
105    public function handle()
106    {
107        if ($this->install_helper->is_phpbb_installed())
108        {
109            throw new http_exception(403, 'INSTALL_PHPBB_INSTALLED');
110        }
111
112        $this->template->assign_vars(array(
113            'U_ACTION' => $this->controller_helper->route('phpbb_installer_install'),
114        ));
115
116        // Set up input-output handler
117        if ($this->request->is_ajax())
118        {
119            $this->iohandler_factory->set_environment('ajax');
120        }
121        else
122        {
123            $this->iohandler_factory->set_environment('nojs');
124        }
125
126        // Set the appropriate input-output handler
127        $this->installer->set_iohandler($this->iohandler_factory->get());
128        $this->controller_helper->handle_language_select();
129        $this->controller_helper->handle_installer_restart();
130
131        if ($this->request->is_ajax())
132        {
133            $installer = $this->installer;
134            $response = new StreamedResponse();
135            $response->setCallback(function() use ($installer) {
136                $installer->run();
137            });
138
139            // Try to bypass any server output buffers
140            $response->headers->set('X-Accel-Buffering', 'no');
141
142            return $response;
143        }
144        else
145        {
146            // Determine whether the installation was started or not
147            if (true)
148            {
149                // Set active stage
150                $this->menu_provider->set_nav_property(
151                    array('install', 0, 'introduction'),
152                    array(
153                        'selected'    => true,
154                        'completed'    => false,
155                    )
156                );
157
158                // If not, let's render the welcome page
159                $this->template->assign_vars(array(
160                    'SHOW_INSTALL_START_FORM'    => true,
161                    'TITLE'                        => $this->language->lang('INSTALL_INTRO'),
162                    'CONTENT'                    => $this->language->lang('INSTALL_INTRO_BODY'),
163                ));
164
165                /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
166                $iohandler = $this->iohandler_factory->get();
167                $this->controller_helper->handle_navigation($iohandler);
168
169                return $this->controller_helper->render('installer_install.html', 'INSTALL', true);
170            }
171
172            // @todo: implement no js controller logic
173        }
174    }
175}