Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_update
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 1
72
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
14/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22class acp_update
23{
24    var $u_action;
25
26    function main($id, $mode)
27    {
28        global $config, $user, $template, $request;
29        global $phpbb_root_path, $phpEx, $phpbb_container;
30
31        $user->add_lang('install');
32
33        $this->tpl_name = 'acp_update';
34        $this->page_title = 'ACP_VERSION_CHECK';
35
36        /* @var $version_helper \phpbb\version_helper */
37        $version_helper = $phpbb_container->get('version_helper');
38        try
39        {
40            $recheck = $request->variable('versioncheck_force', false);
41            $do_update = $request->variable('do_update', false);
42
43            $updates_available = $version_helper->get_update_on_branch($recheck);
44            $upgrades_available = $version_helper->get_suggested_updates();
45            $branch = '';
46            if (!empty($upgrades_available))
47            {
48                $branch = array_key_last($upgrades_available);
49                $upgrades_available = array_pop($upgrades_available);
50            }
51
52            if ($do_update && !empty($updates_available))
53            {
54                $updater = $phpbb_container->get('updater.controller');
55                $current_version = $config['version'];
56                $new_version = $upgrades_available['current'];
57                $download_url = 'https://download.phpbb.com/pub/release/';
58                $download_url .= $branch . '/' . $new_version . '/';
59                $download_url .= 'phpBB-' . $current_version . '_to_' . $new_version . '.zip';
60                $data = $updater->handle(
61                    $download_url
62                );
63
64                $response = new \phpbb\json_response();
65                $response->send($data);
66            }
67        }
68        catch (\RuntimeException $e)
69        {
70            $template->assign_var('S_VERSIONCHECK_FAIL', true);
71
72            $updates_available = array();
73        }
74
75        if (!empty($updates_available))
76        {
77            $template->assign_block_vars('updates_available', $updates_available);
78        }
79
80        $update_link = $phpbb_root_path . 'install/app.' . $phpEx;
81
82        $template_ary = [
83            'S_UP_TO_DATE'                => empty($updates_available),
84            'U_ACTION'                    => $this->u_action,
85            'U_VERSIONCHECK_FORCE'        => append_sid($this->u_action . '&amp;versioncheck_force=1'),
86
87            'CURRENT_VERSION'            => $config['version'],
88
89            'UPDATE_INSTRUCTIONS'        => $user->lang('UPDATE_INSTRUCTIONS', $update_link),
90            'S_VERSION_UPGRADEABLE'        => !empty($upgrades_available),
91            'UPGRADE_INSTRUCTIONS'        => !empty($upgrades_available) ? $user->lang('UPGRADE_INSTRUCTIONS', $upgrades_available['current'], $upgrades_available['announcement']) : false,
92        ];
93
94        $template->assign_vars($template_ary);
95
96        // Incomplete update?
97        if (phpbb_version_compare($config['version'], PHPBB_VERSION, '<'))
98        {
99            $database_update_link = $phpbb_root_path . 'install/app.php/update';
100
101            $template->assign_vars(array(
102                'S_UPDATE_INCOMPLETE'        => true,
103                'FILES_VERSION'                => PHPBB_VERSION,
104                'INCOMPLETE_INSTRUCTIONS'    => $user->lang('UPDATE_INCOMPLETE_EXPLAIN', $database_update_link),
105            ));
106        }
107    }
108}