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
update
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 2
30
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
20
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\iohandler\factory;
19use phpbb\install\helper\navigation\navigation_provider;
20use phpbb\install\installer;
21use phpbb\language\language;
22use phpbb\request\request_interface;
23use phpbb\template\template;
24use Symfony\Component\HttpFoundation\Response;
25use Symfony\Component\HttpFoundation\StreamedResponse;
26
27/**
28 * Updater controller
29 */
30class update
31{
32    /**
33     * @var helper
34     */
35    protected $controller_helper;
36
37    /**
38     * @var installer
39     */
40    protected $installer;
41
42    /**
43     * @var install_helper
44     */
45    protected $install_helper;
46
47    /**
48     * @var factory
49     */
50    protected $iohandler_factory;
51
52    /**
53     * @var language
54     */
55    protected $language;
56
57    /**
58     * @var navigation_provider
59     */
60    protected $menu_provider;
61
62    /**
63     * @var request_interface
64     */
65    protected $request;
66
67    /**
68     * @var template
69     */
70    protected $template;
71
72    /**
73     * Constructor
74     *
75     * @param helper                $controller_helper
76     * @param installer                $installer
77     * @param install_helper        $install_helper
78     * @param factory                $iohandler
79     * @param language                $language
80     * @param navigation_provider    $menu_provider
81     * @param request_interface        $request
82     * @param template                $template
83     */
84    public function __construct(helper $controller_helper, installer $installer, install_helper $install_helper, factory $iohandler, language $language, navigation_provider $menu_provider, request_interface $request, template $template)
85    {
86        $this->controller_helper    = $controller_helper;
87        $this->installer            = $installer;
88        $this->install_helper        = $install_helper;
89        $this->iohandler_factory    = $iohandler;
90        $this->language                = $language;
91        $this->menu_provider        = $menu_provider;
92        $this->request                = $request;
93        $this->template                = $template;
94    }
95
96    /**
97     * Controller entry point
98     *
99     * @return Response|StreamedResponse
100     *
101     * @throws http_exception When phpBB is not installed
102     */
103    public function handle()
104    {
105        if (!$this->install_helper->is_phpbb_installed())
106        {
107            throw new http_exception(403, 'INSTALL_PHPBB_NOT_INSTALLED');
108        }
109
110        $this->template->assign_vars(array(
111            'U_ACTION' => $this->controller_helper->route('phpbb_installer_update'),
112        ));
113
114        // Set up input-output handler
115        if ($this->request->is_ajax())
116        {
117            $this->iohandler_factory->set_environment('ajax');
118        }
119        else
120        {
121            $this->iohandler_factory->set_environment('nojs');
122        }
123
124        // Set the appropriate input-output handler
125        $this->installer->set_iohandler($this->iohandler_factory->get());
126        $this->controller_helper->handle_language_select();
127
128        // Render the intro page
129        if ($this->request->is_ajax())
130        {
131            $installer = $this->installer;
132            $response = new StreamedResponse();
133            $response->setCallback(function() use ($installer) {
134                $installer->run();
135            });
136
137            // Try to bypass any server output buffers
138            $response->headers->set('X-Accel-Buffering', 'no');
139            $response->headers->set('Content-type', 'application/json');
140
141            return $response;
142        }
143        else
144        {
145            // Set active stage
146            $this->menu_provider->set_nav_property(
147                array('update', 0, 'introduction'),
148                array(
149                    'selected'    => true,
150                    'completed'    => false,
151                )
152            );
153
154            $this->template->assign_vars(array(
155                'SHOW_INSTALL_START_FORM'    => true,
156                'TITLE'                        => $this->language->lang('UPDATE_INSTALLATION'),
157                'CONTENT'                    => $this->language->lang('UPDATE_INSTALLATION_EXPLAIN'),
158            ));
159
160            /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
161            $iohandler = $this->iohandler_factory->get();
162            $this->controller_helper->handle_navigation($iohandler);
163
164            return $this->controller_helper->render('installer_update.html', 'UPDATE_INSTALLATION', true);
165        }
166    }
167}