Completed
Pull Request — master (#222)
by Victor
02:43
created

Locator::getChannelFromVersionsFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
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
			"updater"
84
		];
85
	}
86
87
	/**
88
	 * Absolute path to core root dir content
89
	 * @return array
90
	 */
91
	public function getRootDirItems(){
92
		$items = $this->getRootDirContent();
93
		$items = array_map(
94
			function($item){ return $this->owncloudRootPath . "/" . $item;	},
95
			$items
96
		);
97
		return $items;
98
	}
99
100
	public function getDataDir(){
101
		return $this->updaterRootPath . '/data';
102
	}
103
104
	public function getCheckpointDir(){
105
		return $this->getDataDir() . '/checkpoint';
106
	}
107
108
	public function getDownloadBaseDir(){
109
		return $this->getDataDir() . '/download';
110
	}
111
112
	public function getExtractionBaseDir(){
113
		 return $this->owncloudRootPath . "/_oc_upgrade";
114
	}
115
116
	/**
117
	 *
118
	 * @return string
119
	 */
120
	public function getPathToOccFile(){
121
		return $this->owncloudRootPath . '/occ';
122
	}
123
124
	/**
125
	 *
126
	 * @return string
127
	 */
128
	public function getInstalledVersion(){
129
		include $this->getPathToVersionFile();
130
131
		/** @var $OC_Version string */
132
		return $OC_Version;
0 ignored issues
show
Bug introduced by
The variable $OC_Version does not exist. Did you forget to declare it?

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.

Loading history...
133
	}
134
135
	/**
136
	 *
137
	 * @return string
138
	 */
139
	public function getChannelFromVersionsFile(){
140
		include $this->getPathToVersionFile();
141
142
		/** @var $OC_Version string */
143
		return $OC_Channel;
0 ignored issues
show
Bug introduced by
The variable $OC_Channel does not exist. Did you forget to declare it?

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.

Loading history...
144
	}
145
146
	/**
147
	 *
148
	 * @return string
149
	 */
150
	public function getBuild(){
151
		include $this->getPathToVersionFile();
152
153
		/** @var $OC_Build string */
154
		return $OC_Build;
0 ignored issues
show
Bug introduced by
The variable $OC_Build does not exist. Did you forget to declare it?

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.

Loading history...
155
	}
156
157
	public function getPathtoConfigFiles($filePostfix = 'config.php'){
158
		// Only config.php for now
159
		return [
160
			$this->owncloudRootPath . '/config/' . $filePostfix
161
		];
162
	}
163
164
	public function getPathToConfigFile(){
165
		return $this->owncloudRootPath . '/config/config.php';
166
	}
167
168
	/**
169
	 *
170
	 * @return string
171
	 */
172
	public function getPathToVersionFile(){
173
		return $this->owncloudRootPath . '/version.php';
174
	}
175
176
}
177