aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php
blob: 4d7f0e0cdf9450f615fe4686a1c102553c303aa3 (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
<?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\update_filesystem\task;

use phpbb\filesystem\filesystem;
use phpbb\install\exception\jump_to_restart_point_exception;
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 download_updated_files extends task_base
{
	/**
	 * @var config
	 */
	protected $installer_config;

	/**
	 * @var filesystem
	 */
	protected $filesystem;

	/**
	 * @var iohandler_interface
	 */
	protected $iohandler;

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

		parent::__construct(false);
	}

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

	/**
	 * {@inheritdoc}
	 */
	public function run()
	{
		if ($this->iohandler->get_input('database_update_submit', false))
		{
			// Remove archive
			$this->filesystem->remove(
				$this->installer_config->get('update_file_archive', null)
			);

			$this->installer_config->set('update_file_archive', null);
		}
		else if ($this->iohandler->get_input('update_recheck_files_submit', false))
		{
			$this->installer_config->set('file_updater_elem_progress', '');
			$this->installer_config->set('update_files', array());
			throw new jump_to_restart_point_exception('check_update_files');
		}
		else
		{
			$file_update_info = $this->installer_config->get('update_files', array());

			// Display download box only if the archive won't be empty
			if (!empty($file_update_info) && !(isset($file_update_info['delete']) && count($file_update_info) == 1))
			{
				// Render download box
				$this->iohandler->add_download_link(
					'phpbb_installer_update_file_download',
					'DOWNLOAD_UPDATE_METHOD',
					'DOWNLOAD_UPDATE_METHOD_EXPLAIN'
				);
			}

			// Add form to continue update
			$this->iohandler->add_user_form_group('UPDATE_CONTINUE_UPDATE_PROCESS', array(
				'update_recheck_files_submit'	=> array(
					'label'			=> 'UPDATE_RECHECK_UPDATE_FILES',
					'type'			=> 'submit',
					'is_secondary'	=> empty($file_update_info),
				),
				'database_update_submit'	=> array(
					'label'		=> 'UPDATE_CONTINUE_UPDATE_PROCESS',
					'type'		=> 'submit',
					'disabled'	=> !empty($file_update_info),
				),
			));

			throw new user_interaction_required_exception();
		}
	}

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

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