1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Victor Dubiniuk <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Owncloud\Updater\Utils; |
23
|
|
|
|
24
|
|
|
class Locator { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* absolute path to ownCloud root |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $owncloudRootPath; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* absolute path to updater root |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $updaterRootPath; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @param string $baseDir |
41
|
|
|
*/ |
42
|
|
|
public function __construct($baseDir){ |
43
|
|
|
$this->updaterRootPath = $baseDir; |
44
|
|
|
$this->owncloudRootPath = dirname($baseDir); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getOwncloudRootPath(){ |
48
|
|
|
return $this->owncloudRootPath; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* expected items in the core |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function getRootDirContent(){ |
56
|
|
|
return [ |
57
|
|
|
"config/config.sample.php", |
58
|
|
|
"core", |
59
|
|
|
"l10n", |
60
|
|
|
"lib", |
61
|
|
|
"ocs", |
62
|
|
|
"ocs-provider", |
63
|
|
|
"resources", |
64
|
|
|
"settings", |
65
|
|
|
".htaccess", |
66
|
|
|
".mailmap", |
67
|
|
|
".tag", |
68
|
|
|
".user.ini", |
69
|
|
|
"AUTHORS", |
70
|
|
|
"console.php", |
71
|
|
|
"COPYING-AGPL", |
72
|
|
|
"cron.php", |
73
|
|
|
"db_structure.xml", |
74
|
|
|
"index.html", |
75
|
|
|
"index.php", |
76
|
|
|
"indie.json", |
77
|
|
|
"occ", |
78
|
|
|
"public.php", |
79
|
|
|
"remote.php", |
80
|
|
|
"robots.txt", |
81
|
|
|
"status.php", |
82
|
|
|
"version.php" |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getUpdaterContent(){ |
87
|
|
|
return [ |
88
|
|
|
'app', |
89
|
|
|
'application.php', |
90
|
|
|
'box.json', |
91
|
|
|
'composer.json', |
92
|
|
|
'composer.lock', |
93
|
|
|
'CONTRIBUTING.md', |
94
|
|
|
'COPYING-AGPL', |
95
|
|
|
'index.php', |
96
|
|
|
'pub', |
97
|
|
|
'src', |
98
|
|
|
'vendor', |
99
|
|
|
'README.md', |
100
|
|
|
'.travis.yml', |
101
|
|
|
'.scrutinizer.yml', |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Absolute path to core root dir content |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
public function getRootDirItems(){ |
110
|
|
|
$items = $this->getRootDirContent(); |
111
|
|
|
$items = array_map( |
112
|
|
|
function($item){ return $this->owncloudRootPath . "/" . $item; }, |
113
|
|
|
$items |
114
|
|
|
); |
115
|
|
|
return $items; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getDataDir(){ |
119
|
|
|
return $this->updaterRootPath . '/data'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getCheckpointDir(){ |
123
|
|
|
return $this->getDataDir() . '/checkpoint'; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getDownloadBaseDir(){ |
127
|
|
|
return $this->getDataDir() . '/download'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getExtractionBaseDir(){ |
131
|
|
|
return $this->owncloudRootPath . "/_oc_upgrade"; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getPathToOccFile(){ |
139
|
|
|
return $this->owncloudRootPath . '/occ'; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getInstalledVersion(){ |
147
|
|
|
include $this->getPathToVersionFile(); |
148
|
|
|
|
149
|
|
|
/** @var $OC_Version string */ |
150
|
|
|
return $OC_Version; |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getChannelFromVersionsFile(){ |
158
|
|
|
include $this->getPathToVersionFile(); |
159
|
|
|
|
160
|
|
|
/** @var $OC_Version string */ |
161
|
|
|
return $OC_Channel; |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getBuild(){ |
169
|
|
|
include $this->getPathToVersionFile(); |
170
|
|
|
|
171
|
|
|
/** @var $OC_Build string */ |
172
|
|
|
return $OC_Build; |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function getPathtoConfigFiles($filePostfix = 'config.php'){ |
176
|
|
|
// Only config.php for now |
177
|
|
|
return [ |
178
|
|
|
$this->owncloudRootPath . '/config/' . $filePostfix |
179
|
|
|
]; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getPathToConfigFile(){ |
183
|
|
|
return $this->owncloudRootPath . '/config/config.php'; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* |
188
|
|
|
* @return string |
189
|
|
|
*/ |
190
|
|
|
public function getPathToVersionFile(){ |
191
|
|
|
return $this->owncloudRootPath . '/version.php'; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.