1 | <?php |
||
24 | namespace Owncloud\Updater\Utils; |
||
|
|||
25 | |||
26 | class Locator { |
||
27 | |||
28 | /** |
||
29 | * absolute path to ownCloud root |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $owncloudRootPath; |
||
33 | |||
34 | /** |
||
35 | * absolute path to updater root |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $updaterRootPath; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @param string $baseDir |
||
43 | */ |
||
44 | public function __construct($baseDir){ |
||
45 | $this->updaterRootPath = $baseDir; |
||
46 | $this->owncloudRootPath = dirname($baseDir); |
||
47 | } |
||
48 | |||
49 | public function getOwncloudRootPath(){ |
||
50 | return $this->owncloudRootPath; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * expected items in the core |
||
55 | * @return array |
||
56 | */ |
||
57 | public function getRootDirContent(){ |
||
58 | return [ |
||
59 | "config/config.sample.php", |
||
60 | "core", |
||
61 | "l10n", |
||
62 | "lib", |
||
63 | "ocs", |
||
64 | "ocs-provider", |
||
65 | "resources", |
||
66 | "settings", |
||
67 | ".htaccess", |
||
68 | ".mailmap", |
||
69 | ".tag", |
||
70 | ".user.ini", |
||
71 | "AUTHORS", |
||
72 | "console.php", |
||
73 | "COPYING-AGPL", |
||
74 | "cron.php", |
||
75 | "db_structure.xml", |
||
76 | "index.html", |
||
77 | "index.php", |
||
78 | "indie.json", |
||
79 | "occ", |
||
80 | "public.php", |
||
81 | "remote.php", |
||
82 | "robots.txt", |
||
83 | "status.php", |
||
84 | "version.php" |
||
85 | ]; |
||
86 | } |
||
87 | |||
88 | public function getUpdaterContent(){ |
||
89 | return [ |
||
90 | 'app', |
||
91 | 'application.php', |
||
92 | 'box.json', |
||
93 | 'composer.json', |
||
94 | 'composer.lock', |
||
95 | 'CONTRIBUTING.md', |
||
96 | 'COPYING-AGPL', |
||
97 | 'index.php', |
||
98 | 'pub', |
||
99 | 'src', |
||
100 | 'vendor', |
||
101 | 'README.md', |
||
102 | '.travis.yml', |
||
103 | '.scrutinizer.yml', |
||
104 | ]; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Absolute path to core root dir content |
||
109 | * @return array |
||
110 | */ |
||
111 | public function getRootDirItems(){ |
||
112 | $items = $this->getRootDirContent(); |
||
113 | $items = array_map( |
||
114 | function($item){ return $this->owncloudRootPath . "/" . $item; }, |
||
115 | $items |
||
116 | ); |
||
117 | return $items; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Absolute path |
||
122 | * @return string |
||
123 | * @throws \Exception |
||
124 | */ |
||
125 | public function getDataDir(){ |
||
126 | $container = \Owncloud\Updater\Console\Application::$container; |
||
127 | if ($container['utils.configReader']->getIsLoaded()){ |
||
128 | return $container['utils.configReader']->getByPath('system.datadirectory'); |
||
129 | } |
||
130 | |||
131 | // Fallback case |
||
132 | include_once $this->getPathToConfigFile(); |
||
133 | if (isset($CONFIG['datadirectory'])){ |
||
134 | return $CONFIG['datadirectory']; |
||
135 | } |
||
136 | |||
137 | // Something went wrong |
||
138 | throw new \Exception('Unable to detect datadirectory'); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Absolute path to updater root dir |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getUpdaterBaseDir(){ |
||
146 | return $this->getDataDir() . '/updater-data'; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Absolute path to create a core and apps backups |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getCheckpointDir(){ |
||
154 | return $this->getUpdaterBaseDir() . '/checkpoint'; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Absolute path to store downloaded packages |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getDownloadBaseDir(){ |
||
162 | return $this->getUpdaterBaseDir() . '/download'; |
||
163 | } |
||
164 | |||
165 | public function getExtractionBaseDir(){ |
||
166 | return $this->owncloudRootPath . "/_oc_upgrade"; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getPathToOccFile(){ |
||
174 | return $this->owncloudRootPath . '/occ'; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getInstalledVersion(){ |
||
182 | include $this->getPathToVersionFile(); |
||
183 | |||
184 | /** @var $OC_Version string */ |
||
185 | return $OC_Version; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getChannelFromVersionsFile(){ |
||
193 | include $this->getPathToVersionFile(); |
||
194 | |||
195 | /** @var $OC_Version string */ |
||
230 |