Passed
Push — master ( fb1e55...843258 )
by Morris
11:26
created

Installer::updateAppstoreApp()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016, Lukas Reschke <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 * @author Brice Maron <[email protected]>
8
 * @author Christoph Wurst <[email protected]>
9
 * @author Frank Karlitschek <[email protected]>
10
 * @author Georg Ehrke <[email protected]>
11
 * @author Joas Schilling <[email protected]>
12
 * @author Kamil Domanski <[email protected]>
13
 * @author Lukas Reschke <[email protected]>
14
 * @author Morris Jobke <[email protected]>
15
 * @author Robin Appelman <[email protected]>
16
 * @author root "root@oc.(none)"
17
 * @author Thomas Müller <[email protected]>
18
 * @author Thomas Tanghus <[email protected]>
19
 *
20
 * @license AGPL-3.0
21
 *
22
 * This code is free software: you can redistribute it and/or modify
23
 * it under the terms of the GNU Affero General Public License, version 3,
24
 * as published by the Free Software Foundation.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
 * GNU Affero General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU Affero General Public License, version 3,
32
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
33
 *
34
 */
35
36
namespace OC;
37
38
use Doctrine\DBAL\Exception\TableExistsException;
39
use OC\App\AppStore\Bundles\Bundle;
40
use OC\App\AppStore\Fetcher\AppFetcher;
41
use OC\Archive\TAR;
42
use OC_App;
43
use OC_DB;
44
use OC_Helper;
45
use OCP\Http\Client\IClientService;
46
use OCP\IConfig;
47
use OCP\ILogger;
48
use OCP\ITempManager;
49
use phpseclib\File\X509;
50
51
/**
52
 * This class provides the functionality needed to install, update and remove apps
53
 */
54
class Installer {
55
	/** @var AppFetcher */
56
	private $appFetcher;
57
	/** @var IClientService */
58
	private $clientService;
59
	/** @var ITempManager */
60
	private $tempManager;
61
	/** @var ILogger */
62
	private $logger;
63
	/** @var IConfig */
64
	private $config;
65
	/** @var array - for caching the result of app fetcher */
66
	private $apps = null;
67
	/** @var bool|null - for caching the result of the ready status */
68
	private $isInstanceReadyForUpdates = null;
69
70
	/**
71
	 * @param AppFetcher $appFetcher
72
	 * @param IClientService $clientService
73
	 * @param ITempManager $tempManager
74
	 * @param ILogger $logger
75
	 * @param IConfig $config
76
	 */
77
	public function __construct(AppFetcher $appFetcher,
78
								IClientService $clientService,
79
								ITempManager $tempManager,
80
								ILogger $logger,
81
								IConfig $config) {
82
		$this->appFetcher = $appFetcher;
83
		$this->clientService = $clientService;
84
		$this->tempManager = $tempManager;
85
		$this->logger = $logger;
86
		$this->config = $config;
87
	}
88
89
	/**
90
	 * Installs an app that is located in one of the app folders already
91
	 *
92
	 * @param string $appId App to install
93
	 * @throws \Exception
94
	 * @return string app ID
95
	 */
96
	public function installApp($appId) {
97
		$app = \OC_App::findAppInDirectories($appId);
98
		if($app === false) {
99
			throw new \Exception('App not found in any app directory');
100
		}
101
102
		$basedir = $app['path'].'/'.$appId;
103
		$info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppInfo() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppInfo() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

103
		$info = /** @scrutinizer ignore-deprecated */ OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
104
105
		$l = \OC::$server->getL10N('core');
106
107
		if(!is_array($info)) {
108
			throw new \Exception(
109
				$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
110
					[$appId]
111
				)
112
			);
113
		}
114
115
		$ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []);
116
		$ignoreMax = in_array($appId, $ignoreMaxApps);
117
118
		$version = implode('.', \OCP\Util::getVersion());
119
		if (!\OC_App::isAppCompatible($version, $info, $ignoreMax)) {
120
			throw new \Exception(
121
				// TODO $l
122
				$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
123
					[$info['name']]
124
				)
125
			);
126
		}
127
128
		// check for required dependencies
129
		\OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax);
130
		\OC_App::registerAutoloading($appId, $basedir);
131
132
		//install the database
133
		if(is_file($basedir.'/appinfo/database.xml')) {
134
			if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) {
0 ignored issues
show
introduced by
The condition OC::server->getConfig()-...lled_version') === null is always false.
Loading history...
135
				OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
136
			} else {
137
				OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml');
138
			}
139
		} else {
140
			$ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
141
			$ms->migrate();
142
		}
143
144
		\OC_App::setupBackgroundJobs($info['background-jobs']);
145
146
		//run appinfo/install.php
147
		self::includeAppScript($basedir . '/appinfo/install.php');
148
149
		$appData = OC_App::getAppInfo($appId);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppInfo() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppInfo() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

149
		$appData = /** @scrutinizer ignore-deprecated */ OC_App::getAppInfo($appId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
150
		OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']);
151
152
		//set the installed version
153
		\OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false));
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppVersion() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppVersion() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

153
		\OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', /** @scrutinizer ignore-deprecated */ OC_App::getAppVersion($info['id'], false));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
154
		\OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
155
156
		//set remote/public handlers
157
		foreach($info['remote'] as $name=>$path) {
158
			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
159
		}
160
		foreach($info['public'] as $name=>$path) {
161
			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
162
		}
163
164
		OC_App::setAppTypes($info['id']);
165
166
		return $info['id'];
167
	}
168
169
	/**
170
	 * Updates the specified app from the appstore
171
	 *
172
	 * @param string $appId
173
	 * @return bool
174
	 */
175
	public function updateAppstoreApp($appId) {
176
		if($this->isUpdateAvailable($appId)) {
177
			try {
178
				$this->downloadApp($appId);
179
			} catch (\Exception $e) {
180
				$this->logger->logException($e, [
181
					'level' => ILogger::ERROR,
182
					'app' => 'core',
183
				]);
184
				return false;
185
			}
186
			return OC_App::updateApp($appId);
187
		}
188
189
		return false;
190
	}
191
192
	/**
193
	 * Downloads an app and puts it into the app directory
194
	 *
195
	 * @param string $appId
196
	 *
197
	 * @throws \Exception If the installation was not successful
198
	 */
199
	public function downloadApp($appId) {
200
		$appId = strtolower($appId);
201
202
		$apps = $this->appFetcher->get();
203
		foreach($apps as $app) {
204
			if($app['id'] === $appId) {
205
				// Load the certificate
206
				$certificate = new X509();
207
				$certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
208
				$loadedCertificate = $certificate->loadX509($app['certificate']);
209
210
				// Verify if the certificate has been revoked
211
				$crl = new X509();
212
				$crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
213
				$crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
214
				if($crl->validateSignature() !== true) {
215
					throw new \Exception('Could not validate CRL signature');
216
				}
217
				$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
218
				$revoked = $crl->getRevoked($csn);
219
				if ($revoked !== false) {
220
					throw new \Exception(
221
						sprintf(
222
							'Certificate "%s" has been revoked',
223
							$csn
224
						)
225
					);
226
				}
227
228
				// Verify if the certificate has been issued by the Nextcloud Code Authority CA
229
				if($certificate->validateSignature() !== true) {
230
					throw new \Exception(
231
						sprintf(
232
							'App with id %s has a certificate not issued by a trusted Code Signing Authority',
233
							$appId
234
						)
235
					);
236
				}
237
238
				// Verify if the certificate is issued for the requested app id
239
				$certInfo = openssl_x509_parse($app['certificate']);
240
				if(!isset($certInfo['subject']['CN'])) {
241
					throw new \Exception(
242
						sprintf(
243
							'App with id %s has a cert with no CN',
244
							$appId
245
						)
246
					);
247
				}
248
				if($certInfo['subject']['CN'] !== $appId) {
249
					throw new \Exception(
250
						sprintf(
251
							'App with id %s has a cert issued to %s',
252
							$appId,
253
							$certInfo['subject']['CN']
254
						)
255
					);
256
				}
257
258
				// Download the release
259
				$tempFile = $this->tempManager->getTemporaryFile('.tar.gz');
260
				$client = $this->clientService->newClient();
261
				$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
262
263
				// Check if the signature actually matches the downloaded content
264
				$certificate = openssl_get_publickey($app['certificate']);
265
				$verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
266
				openssl_free_key($certificate);
267
268
				if($verified === true) {
269
					// Seems to match, let's proceed
270
					$extractDir = $this->tempManager->getTemporaryFolder();
271
					$archive = new TAR($tempFile);
272
273
					if($archive) {
274
						if (!$archive->extract($extractDir)) {
275
							throw new \Exception(
276
								sprintf(
277
									'Could not extract app %s',
278
									$appId
279
								)
280
							);
281
						}
282
						$allFiles = scandir($extractDir);
283
						$folders = array_diff($allFiles, ['.', '..']);
284
						$folders = array_values($folders);
285
286
						if(count($folders) > 1) {
287
							throw new \Exception(
288
								sprintf(
289
									'Extracted app %s has more than 1 folder',
290
									$appId
291
								)
292
							);
293
						}
294
295
						// Check if appinfo/info.xml has the same app ID as well
296
						$loadEntities = libxml_disable_entity_loader(false);
297
						$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
298
						libxml_disable_entity_loader($loadEntities);
299
						if((string)$xml->id !== $appId) {
300
							throw new \Exception(
301
								sprintf(
302
									'App for id %s has a wrong app ID in info.xml: %s',
303
									$appId,
304
									(string)$xml->id
305
								)
306
							);
307
						}
308
309
						// Check if the version is lower than before
310
						$currentVersion = OC_App::getAppVersion($appId);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppVersion() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppVersion() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

310
						$currentVersion = /** @scrutinizer ignore-deprecated */ OC_App::getAppVersion($appId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
311
						$newVersion = (string)$xml->version;
312
						if(version_compare($currentVersion, $newVersion) === 1) {
313
							throw new \Exception(
314
								sprintf(
315
									'App for id %s has version %s and tried to update to lower version %s',
316
									$appId,
317
									$currentVersion,
318
									$newVersion
319
								)
320
							);
321
						}
322
323
						$baseDir = OC_App::getInstallPath() . '/' . $appId;
0 ignored issues
show
Bug introduced by
Are you sure OC_App::getInstallPath() of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

323
						$baseDir = /** @scrutinizer ignore-type */ OC_App::getInstallPath() . '/' . $appId;
Loading history...
324
						// Remove old app with the ID if existent
325
						OC_Helper::rmdirr($baseDir);
326
						// Move to app folder
327
						if(@mkdir($baseDir)) {
328
							$extractDir .= '/' . $folders[0];
329
							OC_Helper::copyr($extractDir, $baseDir);
330
						}
331
						OC_Helper::copyr($extractDir, $baseDir);
332
						OC_Helper::rmdirr($extractDir);
333
						return;
334
					} else {
335
						throw new \Exception(
336
							sprintf(
337
								'Could not extract app with ID %s to %s',
338
								$appId,
339
								$extractDir
340
							)
341
						);
342
					}
343
				} else {
344
					// Signature does not match
345
					throw new \Exception(
346
						sprintf(
347
							'App with id %s has invalid signature',
348
							$appId
349
						)
350
					);
351
				}
352
			}
353
		}
354
355
		throw new \Exception(
356
			sprintf(
357
				'Could not download app %s',
358
				$appId
359
			)
360
		);
361
	}
362
363
	/**
364
	 * Check if an update for the app is available
365
	 *
366
	 * @param string $appId
367
	 * @return string|false false or the version number of the update
368
	 */
369
	public function isUpdateAvailable($appId) {
370
		if ($this->isInstanceReadyForUpdates === null) {
371
			$installPath = OC_App::getInstallPath();
372
			if ($installPath === false || $installPath === null) {
373
				$this->isInstanceReadyForUpdates = false;
374
			} else {
375
				$this->isInstanceReadyForUpdates = true;
376
			}
377
		}
378
379
		if ($this->isInstanceReadyForUpdates === false) {
380
			return false;
381
		}
382
383
		if ($this->isInstalledFromGit($appId) === true) {
384
			return false;
385
		}
386
387
		if ($this->apps === null) {
388
			$this->apps = $this->appFetcher->get();
389
		}
390
391
		foreach($this->apps as $app) {
392
			if($app['id'] === $appId) {
393
				$currentVersion = OC_App::getAppVersion($appId);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppVersion() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppVersion() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

393
				$currentVersion = /** @scrutinizer ignore-deprecated */ OC_App::getAppVersion($appId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
394
395
				if (!isset($app['releases'][0]['version'])) {
396
					return false;
397
				}
398
				$newestVersion = $app['releases'][0]['version'];
399
				if ($currentVersion !== '0' && version_compare($newestVersion, $currentVersion, '>')) {
400
					return $newestVersion;
401
				} else {
402
					return false;
403
				}
404
			}
405
		}
406
407
		return false;
408
	}
409
410
	/**
411
	 * Check if app has been installed from git
412
	 * @param string $name name of the application to remove
413
	 * @return boolean
414
	 *
415
	 * The function will check if the path contains a .git folder
416
	 */
417
	private function isInstalledFromGit($appId) {
418
		$app = \OC_App::findAppInDirectories($appId);
419
		if($app === false) {
420
			return false;
421
		}
422
		$basedir = $app['path'].'/'.$appId;
423
		return file_exists($basedir.'/.git/');
424
	}
425
426
	/**
427
	 * Check if app is already downloaded
428
	 * @param string $name name of the application to remove
429
	 * @return boolean
430
	 *
431
	 * The function will check if the app is already downloaded in the apps repository
432
	 */
433
	public function isDownloaded($name) {
434
		foreach(\OC::$APPSROOTS as $dir) {
435
			$dirToTest  = $dir['path'];
436
			$dirToTest .= '/';
437
			$dirToTest .= $name;
438
			$dirToTest .= '/';
439
440
			if (is_dir($dirToTest)) {
441
				return true;
442
			}
443
		}
444
445
		return false;
446
	}
447
448
	/**
449
	 * Removes an app
450
	 * @param string $appId ID of the application to remove
451
	 * @return boolean
452
	 *
453
	 *
454
	 * This function works as follows
455
	 *   -# call uninstall repair steps
456
	 *   -# removing the files
457
	 *
458
	 * The function will not delete preferences, tables and the configuration,
459
	 * this has to be done by the function oc_app_uninstall().
460
	 */
461
	public function removeApp($appId) {
462
		if($this->isDownloaded( $appId )) {
463
			if (\OC::$server->getAppManager()->isShipped($appId)) {
464
				return false;
465
			}
466
			$appDir = OC_App::getInstallPath() . '/' . $appId;
0 ignored issues
show
Bug introduced by
Are you sure OC_App::getInstallPath() of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

466
			$appDir = /** @scrutinizer ignore-type */ OC_App::getInstallPath() . '/' . $appId;
Loading history...
467
			OC_Helper::rmdirr($appDir);
468
			return true;
469
		}else{
470
			\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

470
			/** @scrutinizer ignore-deprecated */ \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
471
472
			return false;
473
		}
474
475
	}
476
477
	/**
478
	 * Installs the app within the bundle and marks the bundle as installed
479
	 *
480
	 * @param Bundle $bundle
481
	 * @throws \Exception If app could not get installed
482
	 */
483
	public function installAppBundle(Bundle $bundle) {
484
		$appIds = $bundle->getAppIdentifiers();
485
		foreach($appIds as $appId) {
486
			if(!$this->isDownloaded($appId)) {
487
				$this->downloadApp($appId);
488
			}
489
			$this->installApp($appId);
490
			$app = new OC_App();
491
			$app->enable($appId);
492
		}
493
		$bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true);
494
		$bundles[] = $bundle->getIdentifier();
495
		$this->config->setAppValue('core', 'installed.bundles', json_encode($bundles));
496
	}
497
498
	/**
499
	 * Installs shipped apps
500
	 *
501
	 * This function installs all apps found in the 'apps' directory that should be enabled by default;
502
	 * @param bool $softErrors When updating we ignore errors and simply log them, better to have a
503
	 *                         working ownCloud at the end instead of an aborted update.
504
	 * @return array Array of error messages (appid => Exception)
505
	 */
506
	public static function installShippedApps($softErrors = false) {
507
		$appManager = \OC::$server->getAppManager();
508
		$config = \OC::$server->getConfig();
509
		$errors = [];
510
		foreach(\OC::$APPSROOTS as $app_dir) {
511
			if($dir = opendir( $app_dir['path'] )) {
512
				while( false !== ( $filename = readdir( $dir ))) {
513
					if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
514
						if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
515
							if($config->getAppValue($filename, "installed_version", null) === null) {
516
								$info=OC_App::getAppInfo($filename);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppInfo() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppInfo() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

516
								$info=/** @scrutinizer ignore-deprecated */ OC_App::getAppInfo($filename);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
517
								$enabled = isset($info['default_enable']);
518
								if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps()))
519
									  && $config->getAppValue($filename, 'enabled') !== 'no') {
520
									if ($softErrors) {
521
										try {
522
											Installer::installShippedApp($filename);
523
										} catch (HintException $e) {
524
											if ($e->getPrevious() instanceof TableExistsException) {
525
												$errors[$filename] = $e;
526
												continue;
527
											}
528
											throw $e;
529
										}
530
									} else {
531
										Installer::installShippedApp($filename);
532
									}
533
									$config->setAppValue($filename, 'enabled', 'yes');
534
								}
535
							}
536
						}
537
					}
538
				}
539
				closedir( $dir );
540
			}
541
		}
542
543
		return $errors;
544
	}
545
546
	/**
547
	 * install an app already placed in the app folder
548
	 * @param string $app id of the app to install
549
	 * @return integer
550
	 */
551
	public static function installShippedApp($app) {
552
		//install the database
553
		$appPath = OC_App::getAppPath($app);
554
		\OC_App::registerAutoloading($app, $appPath);
555
556
		if(is_file("$appPath/appinfo/database.xml")) {
557
			try {
558
				OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
559
			} catch (TableExistsException $e) {
560
				throw new HintException(
561
					'Failed to enable app ' . $app,
562
					'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.',
563
					0, $e
564
				);
565
			}
566
		} else {
567
			$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
568
			$ms->migrate();
569
		}
570
571
		//run appinfo/install.php
572
		self::includeAppScript("$appPath/appinfo/install.php");
573
574
		$info = OC_App::getAppInfo($app);
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppInfo() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppInfo() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

574
		$info = /** @scrutinizer ignore-deprecated */ OC_App::getAppInfo($app);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
575
		if (is_null($info)) {
576
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type integer.
Loading history...
577
		}
578
		\OC_App::setupBackgroundJobs($info['background-jobs']);
579
580
		OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
581
582
		$config = \OC::$server->getConfig();
583
584
		$config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app));
0 ignored issues
show
Deprecated Code introduced by
The function OC_App::getAppVersion() has been deprecated: 14.0.0 use \OC::$server->getAppManager()->getAppVersion() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

584
		$config->setAppValue($app, 'installed_version', /** @scrutinizer ignore-deprecated */ OC_App::getAppVersion($app));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
585
		if (array_key_exists('ocsid', $info)) {
586
			$config->setAppValue($app, 'ocsid', $info['ocsid']);
587
		}
588
589
		//set remote/public handlers
590
		foreach($info['remote'] as $name=>$path) {
591
			$config->setAppValue('core', 'remote_'.$name, $app.'/'.$path);
592
		}
593
		foreach($info['public'] as $name=>$path) {
594
			$config->setAppValue('core', 'public_'.$name, $app.'/'.$path);
595
		}
596
597
		OC_App::setAppTypes($info['id']);
598
599
		return $info['id'];
600
	}
601
602
	/**
603
	 * @param string $script
604
	 */
605
	private static function includeAppScript($script) {
606
		if ( file_exists($script) ){
607
			include $script;
608
		}
609
	}
610
}
611