Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
obtain_update_files
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 5
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 check_requirements
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
30
 get_step_count
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_task_lang_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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\module\obtain_data\task;
15
16use phpbb\install\exception\user_interaction_required_exception;
17use phpbb\install\helper\config;
18use phpbb\install\helper\iohandler\iohandler_interface;
19use phpbb\install\task_base;
20
21class obtain_update_files extends task_base
22{
23    /**
24     * @var config
25     */
26    protected $installer_config;
27
28    /**
29     * @var iohandler_interface
30     */
31    protected $iohandler;
32
33    /**
34     * @var string
35     */
36    protected $phpbb_root_path;
37
38    /**
39     * @var string
40     */
41    protected $php_ext;
42
43    /**
44     * Constructor
45     *
46     * @param config                $config
47     * @param iohandler_interface    $iohandler
48     * @param string                $phpbb_root_path
49     * @param string                $php_ext
50     */
51    public function __construct(config $config, iohandler_interface $iohandler, $phpbb_root_path, $php_ext)
52    {
53        $this->installer_config    = $config;
54        $this->iohandler        = $iohandler;
55        $this->phpbb_root_path    = $phpbb_root_path;
56        $this->php_ext            = $php_ext;
57
58        parent::__construct(false);
59    }
60
61    /**
62     * {@inheritdoc}
63     */
64    public function check_requirements()
65    {
66        return $this->installer_config->get('do_update_files', false);
67    }
68
69    /**
70     * {@inheritdoc}
71     */
72    public function run()
73    {
74        // Load update info file
75        // The file should be checked in the requirements, so we assume that it exists
76        $update_info_file = $this->phpbb_root_path . 'install/update/index.' . $this->php_ext;
77        include($update_info_file);
78        /** @var array $update_info */
79        $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
80
81        // If the file is invalid, abort mission
82        if (!$info)
83        {
84            $this->iohandler->add_error_message('WRONG_INFO_FILE_FORMAT');
85            throw new user_interaction_required_exception();
86        }
87
88        // Replace .php with $this->php_ext if needed
89        if ($this->php_ext !== 'php')
90        {
91            $custom_extension = '.' . $this->php_ext;
92            $info['files'] = preg_replace('#\.php$#i', $custom_extension, $info['files']);
93        }
94
95        // Save update info
96        $this->installer_config->set('update_info_unprocessed', $info);
97    }
98
99    /**
100     * {@inheritdoc}
101     */
102    public static function get_step_count()
103    {
104        return 0;
105    }
106
107    /**
108     * {@inheritdoc}
109     */
110    public function get_task_lang_name()
111    {
112        return '';
113    }
114}