-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcontroller.php
137 lines (118 loc) · 3.14 KB
/
controller.php
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
<?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\update;
use phpbb\filesystem\filesystem_interface;
use phpbb\language\language;
class controller
{
/** @var filesystem_interface Filesystem manager */
private filesystem_interface $filesystem;
/** @var get_updates Updater class */
private get_updates $updater;
/** @var language Translation handler */
private language $language;
/** @var string phpBB root path */
private string $phpbb_root_path;
/**
* Constructor.
*
* @param filesystem_interface $filesystem
* @param get_updates $updater
* @param language $language
* @param string $phpbb_root_path
*/
public function __construct(
filesystem_interface $filesystem,
get_updates $updater,
language $language,
string $phpbb_root_path)
{
$this->filesystem = $filesystem;
$this->language = $language;
$this->updater = $updater;
$this->phpbb_root_path = $phpbb_root_path;
}
/**
* Handle requests.
*
* @param string $download The download URL.
*
* @return string[] Unencoded json response.
*/
public function handle(string $download): array
{
$update_path = $this->phpbb_root_path . 'store/update.zip';
$status = ['status' => 'continue'];
if (!$this->filesystem->exists($update_path))
{
$result = $this->updater->download($download, $update_path);
if (!$result)
{
return $this->error_response('UPDATE_PACKAGE_DOWNLOAD_FAILURE');
}
return $status;
}
if (!$this->filesystem->exists($update_path . '.sig'))
{
$result = $this->updater->download($download . '.sig', $update_path . '.sig');
if (!$result)
{
return $this->error_response('UPDATE_SIGNATURE_DOWNLOAD_FAILURE');
}
return $status;
}
if (!$this->filesystem->exists($this->phpbb_root_path . 'store/update') || !is_dir($this->phpbb_root_path . 'store/update'))
{
$result = $this->updater->validate($update_path, $update_path . '.sig');
if (!$result)
{
return $this->error_response('UPDATE_SIGNATURE_INVALID');
}
$result = $this->updater->extract($update_path, $this->phpbb_root_path . 'store/update');
if (!$result)
{
return $this->error_response('UPDATE_PACKAGE_EXTRACT_FAILURE');
}
return $status;
}
if (!$this->filesystem->exists($this->phpbb_root_path . 'install') || !is_dir($this->phpbb_root_path . 'install'))
{
$result = $this->updater->copy($this->phpbb_root_path . 'store/update');
if (!$result)
{
return $this->error_response('UPDATE_FILES_COPY_FAILURE');
}
return $status;
}
$this->filesystem->remove([
$this->phpbb_root_path . 'store/update',
$update_path,
$update_path . '.sig'
]);
$status['status'] = 'done';
return $status;
}
/**
* Create error response
*
* @param string $error_key
* @return array Error response
*/
protected function error_response(string $error_key): array
{
return [
'status' => 'error',
'error' => $this->language->lang($error_key),
];
}
}