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		$info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
79
80		// If the file is invalid, abort mission
81		if (!$info)
82		{
83			$this->iohandler->add_error_message('WRONG_INFO_FILE_FORMAT');
84			throw new user_interaction_required_exception();
85		}
86
87		// Replace .php with $this->php_ext if needed
88		if ($this->php_ext !== 'php')
89		{
90			$custom_extension = '.' . $this->php_ext;
91			$info['files'] = preg_replace('#\.php$#i', $custom_extension, $info['files']);
92		}
93
94		// Save update info
95		$this->installer_config->set('update_info_unprocessed', $info);
96	}
97
98	/**
99	 * {@inheritdoc}
100	 */
101	static public function get_step_count()
102	{
103		return 0;
104	}
105
106	/**
107	 * {@inheritdoc}
108	 */
109	public function get_task_lang_name()
110	{
111		return '';
112	}
113}
114