Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
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 / 42
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 / 34
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
130        if ($this->request->is_ajax())
131        {
132            $installer = $this->installer;
133            $response = new StreamedResponse();
134            $response->setCallback(function() use ($installer) {
135                $installer->run();
136            });
137
138            // Try to bypass any server output buffers
139            $response->headers->set('X-Accel-Buffering', 'no');
140
141            return $response;
142        }
143        else
144        {
145            // Determine whether the installation was started or not
146            if (true)
147            {
148                // Set active stage
149                $this->menu_provider->set_nav_property(
150                    array('install', 0, 'introduction'),
151                    array(
152                        'selected'    => true,
153                        'completed'    => false,
154                    )
155                );
156
157                // If not, let's render the welcome page
158                $this->template->assign_vars(array(
159                    'SHOW_INSTALL_START_FORM'    => true,
160                    'TITLE'                        => $this->language->lang('INSTALL_INTRO'),
161                    'CONTENT'                    => $this->language->lang('INSTALL_INTRO_BODY'),
162                ));
163
164                /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
165                $iohandler = $this->iohandler_factory->get();
166                $this->controller_helper->handle_navigation($iohandler);
167
168                return $this->controller_helper->render('installer_install.html', 'INSTALL', true);
169            }
170
171            // @todo: implement no js controller logic
172        }
173    }
174}