aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php
blob: d5a8855c3778d5662b5a0092ff0d94652c30a9fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

namespace phpbb\install\module\obtain_data\task;

use phpbb\install\exception\user_interaction_required_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\iohandler\iohandler_interface;
use phpbb\install\task_base;

class obtain_file_updater_method extends task_base
{
	/**
	 * @var array	Supported compression methods
	 *
	 * Note: .tar is assumed to be supported, but not in the list
	 */
	protected $available_methods;

	/**
	 * @var \phpbb\install\helper\config
	 */
	protected $installer_config;

	/**
	 * @var \phpbb\install\helper\iohandler\iohandler_interface
	 */
	protected $iohandler;

	/**
	 * Constructor
	 *
	 * @param config				$installer_config
	 * @param iohandler_interface	$iohandler
	 */
	public function __construct(config $installer_config, iohandler_interface $iohandler)
	{
		$this->installer_config	= $installer_config;
		$this->iohandler		= $iohandler;

		$this->available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');

		parent::__construct(false);
	}

	/**
	 * {@inheritdoc}
	 */
	public function check_requirements()
	{
		return $this->installer_config->get('do_update_files', false);
	}

	/**
	 * {@inheritdoc}
	 */
	public function run()
	{
		// Check if data is sent
		if ($this->iohandler->get_input('submit_update_file', false))
		{
			$supported_methods = array('compression', 'ftp', 'direct_file');
			$method = $this->iohandler->get_input('method', 'compression');
			$update_method = (in_array($method, $supported_methods, true)) ? $method : 'compression';
			$this->installer_config->set('file_update_method', $update_method);

			$compression = $this->iohandler->get_input('compression_method', '.zip');
			$supported_methods = array_keys($this->available_methods);
			$supported_methods[] = '.tar';
			$compression = (in_array($compression, $supported_methods, true)) ? $compression : '.zip';
			$this->installer_config->set('file_update_compression', $compression);
		}
		else
		{
			$this->iohandler->add_user_form_group('UPDATE_FILE_METHOD_TITLE', array(
				'method' => array(
					'label'		=> 'UPDATE_FILE_METHOD',
					'type'		=> 'select',
					'options'	=> array(
						array(
							'value'		=> 'compression',
							'label'		=> 'UPDATE_FILE_METHOD_DOWNLOAD',
							'selected'	=> true,
						),
						array(
							'value'		=> 'ftp',
							'label'		=> 'UPDATE_FILE_METHOD_FTP',
							'selected'	=> false,
						),
						array(
							'value'		=> 'direct_file',
							'label'		=> 'UPDATE_FILE_METHOD_FILESYSTEM',
							'selected'	=> false,
						),
					),
				),
				'compression_method' => array(
					'label'		=> 'SELECT_DOWNLOAD_FORMAT',
					'type'		=> 'select',
					'options'	=> $this->get_available_compression_methods(),
				),
				'submit_update_file' => array(
					'label'	=> 'SUBMIT',
					'type'	=> 'submit',
				),
			));

			throw new user_interaction_required_exception();
		}
	}

	/**
	 * Returns form elements in an array of available compression methods
	 *
	 * @return array
	 */
	protected function get_available_compression_methods()
	{
		$methods[] = array(
			'value'		=> '.tar',
			'label'		=> '.tar',
			'selected'	=> true,
		);

		foreach ($this->available_methods as $type => $module)
		{
			if (!@extension_loaded($module))
			{
				continue;
			}

			$methods[] = array(
				'value'		=> $type,
				'label'		=> $type,
				'selected'	=> false,
			);
		}

		return $methods;
	}

	/**
	 * {@inheritdoc}
	 */
	static public function get_step_count()
	{
		return 0;
	}

	/**
	 * {@inheritdoc}
	 */
	public function get_task_lang_name()
	{
		return '';
	}
}