|
|
|
|
@ -18,13 +18,15 @@ use OC\Archive\TAR;
|
|
|
|
|
use OC\DB\Connection;
|
|
|
|
|
use OC\DB\MigrationService;
|
|
|
|
|
use OC\Files\FilenameValidator;
|
|
|
|
|
use OC_App;
|
|
|
|
|
use OCP\App\AppPathNotFoundException;
|
|
|
|
|
use OCP\App\IAppManager;
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
|
|
|
|
use OCP\Files;
|
|
|
|
|
use OCP\HintException;
|
|
|
|
|
use OCP\Http\Client\IClientService;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\ITempManager;
|
|
|
|
|
use OCP\L10N\IFactory;
|
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
use OCP\Server;
|
|
|
|
|
use phpseclib\File\X509;
|
|
|
|
|
@ -43,6 +45,8 @@ class Installer {
|
|
|
|
|
private ITempManager $tempManager,
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
private IAppManager $appManager,
|
|
|
|
|
private IFactory $l10nFactory,
|
|
|
|
|
private bool $isCLI,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
@ -56,21 +60,12 @@ class Installer {
|
|
|
|
|
* @return string app ID
|
|
|
|
|
*/
|
|
|
|
|
public function installApp(string $appId, bool $forceEnable = false): string {
|
|
|
|
|
$app = \OC_App::findAppInDirectories($appId);
|
|
|
|
|
if ($app === false) {
|
|
|
|
|
throw new \Exception('App not found in any app directory');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$basedir = $app['path'] . '/' . $appId;
|
|
|
|
|
|
|
|
|
|
if (is_file($basedir . '/appinfo/database.xml')) {
|
|
|
|
|
throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
|
|
|
|
|
}
|
|
|
|
|
$appPath = $this->appManager->getAppPath($appId, true);
|
|
|
|
|
|
|
|
|
|
$l = \OCP\Util::getL10N('core');
|
|
|
|
|
$info = \OCP\Server::get(IAppManager::class)->getAppInfoByPath($basedir . '/appinfo/info.xml', $l->getLanguageCode());
|
|
|
|
|
$l = $this->l10nFactory->get('core');
|
|
|
|
|
$info = $this->appManager->getAppInfoByPath($appPath . '/appinfo/info.xml', $l->getLanguageCode());
|
|
|
|
|
|
|
|
|
|
if (!is_array($info)) {
|
|
|
|
|
if (!is_array($info) || $info['id'] !== $appId) {
|
|
|
|
|
throw new \Exception(
|
|
|
|
|
$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
|
|
|
|
|
[$appId]
|
|
|
|
|
@ -82,9 +77,8 @@ class Installer {
|
|
|
|
|
$ignoreMax = $forceEnable || in_array($appId, $ignoreMaxApps, true);
|
|
|
|
|
|
|
|
|
|
$version = implode('.', \OCP\Util::getVersion());
|
|
|
|
|
if (!\OC_App::isAppCompatible($version, $info, $ignoreMax)) {
|
|
|
|
|
if (!$this->appManager->isAppCompatible($version, $info, $ignoreMax)) {
|
|
|
|
|
throw new \Exception(
|
|
|
|
|
// TODO $l
|
|
|
|
|
$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
|
|
|
|
|
[$info['name']]
|
|
|
|
|
)
|
|
|
|
|
@ -93,47 +87,10 @@ class Installer {
|
|
|
|
|
|
|
|
|
|
// check for required dependencies
|
|
|
|
|
\OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax);
|
|
|
|
|
/** @var Coordinator $coordinator */
|
|
|
|
|
$coordinator = \OC::$server->get(Coordinator::class);
|
|
|
|
|
$coordinator = Server::get(Coordinator::class);
|
|
|
|
|
$coordinator->runLazyRegistration($appId);
|
|
|
|
|
\OC_App::registerAutoloading($appId, $basedir);
|
|
|
|
|
|
|
|
|
|
$previousVersion = $this->config->getAppValue($info['id'], 'installed_version', false);
|
|
|
|
|
if ($previousVersion) {
|
|
|
|
|
OC_App::executeRepairSteps($appId, $info['repair-steps']['pre-migration']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//install the database
|
|
|
|
|
$ms = new MigrationService($info['id'], \OCP\Server::get(Connection::class));
|
|
|
|
|
$ms->migrate('latest', !$previousVersion);
|
|
|
|
|
|
|
|
|
|
if ($previousVersion) {
|
|
|
|
|
OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\OC_App::setupBackgroundJobs($info['background-jobs']);
|
|
|
|
|
|
|
|
|
|
//run appinfo/install.php
|
|
|
|
|
self::includeAppScript($basedir . '/appinfo/install.php');
|
|
|
|
|
|
|
|
|
|
OC_App::executeRepairSteps($appId, $info['repair-steps']['install']);
|
|
|
|
|
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
//set the installed version
|
|
|
|
|
$config->setAppValue($info['id'], 'installed_version', \OCP\Server::get(IAppManager::class)->getAppVersion($info['id'], false));
|
|
|
|
|
$config->setAppValue($info['id'], 'enabled', 'no');
|
|
|
|
|
|
|
|
|
|
//set remote/public handlers
|
|
|
|
|
foreach ($info['remote'] as $name => $path) {
|
|
|
|
|
$config->setAppValue('core', 'remote_' . $name, $info['id'] . '/' . $path);
|
|
|
|
|
}
|
|
|
|
|
foreach ($info['public'] as $name => $path) {
|
|
|
|
|
$config->setAppValue('core', 'public_' . $name, $info['id'] . '/' . $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OC_App::setAppTypes($info['id']);
|
|
|
|
|
|
|
|
|
|
return $info['id'];
|
|
|
|
|
return $this->installAppLastSteps($appPath, $info, null, 'no');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -142,7 +99,7 @@ class Installer {
|
|
|
|
|
* @param bool $allowUnstable Allow unstable releases
|
|
|
|
|
*/
|
|
|
|
|
public function updateAppstoreApp(string $appId, bool $allowUnstable = false): bool {
|
|
|
|
|
if ($this->isUpdateAvailable($appId, $allowUnstable)) {
|
|
|
|
|
if ($this->isUpdateAvailable($appId, $allowUnstable) !== false) {
|
|
|
|
|
try {
|
|
|
|
|
$this->downloadApp($appId, $allowUnstable);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
@ -151,7 +108,7 @@ class Installer {
|
|
|
|
|
]);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return OC_App::updateApp($appId);
|
|
|
|
|
return $this->appManager->upgradeApp($appId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
@ -347,7 +304,7 @@ class Installer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the version is lower than before
|
|
|
|
|
$currentVersion = \OCP\Server::get(IAppManager::class)->getAppVersion($appId, true);
|
|
|
|
|
$currentVersion = $this->appManager->getAppVersion($appId, true);
|
|
|
|
|
$newVersion = (string)$xml->version;
|
|
|
|
|
if (version_compare($currentVersion, $newVersion) === 1) {
|
|
|
|
|
throw new \Exception(
|
|
|
|
|
@ -424,7 +381,7 @@ class Installer {
|
|
|
|
|
|
|
|
|
|
foreach ($this->apps as $app) {
|
|
|
|
|
if ($app['id'] === $appId) {
|
|
|
|
|
$currentVersion = \OCP\Server::get(IAppManager::class)->getAppVersion($appId, true);
|
|
|
|
|
$currentVersion = $this->appManager->getAppVersion($appId, true);
|
|
|
|
|
|
|
|
|
|
if (!isset($app['releases'][0]['version'])) {
|
|
|
|
|
return false;
|
|
|
|
|
@ -447,12 +404,12 @@ class Installer {
|
|
|
|
|
* The function will check if the path contains a .git folder
|
|
|
|
|
*/
|
|
|
|
|
private function isInstalledFromGit(string $appId): bool {
|
|
|
|
|
$app = \OC_App::findAppInDirectories($appId);
|
|
|
|
|
if ($app === false) {
|
|
|
|
|
try {
|
|
|
|
|
$appPath = $this->appManager->getAppPath($appId);
|
|
|
|
|
return file_exists($appPath . '/.git/');
|
|
|
|
|
} catch (AppPathNotFoundException) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$basedir = $app['path'] . '/' . $appId;
|
|
|
|
|
return file_exists($basedir . '/.git/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -487,7 +444,7 @@ class Installer {
|
|
|
|
|
*/
|
|
|
|
|
public function removeApp(string $appId): bool {
|
|
|
|
|
if ($this->isDownloaded($appId)) {
|
|
|
|
|
if (\OCP\Server::get(IAppManager::class)->isShipped($appId)) {
|
|
|
|
|
if ($this->appManager->isShipped($appId)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -518,8 +475,7 @@ class Installer {
|
|
|
|
|
$this->downloadApp($appId);
|
|
|
|
|
}
|
|
|
|
|
$this->installApp($appId);
|
|
|
|
|
$app = new OC_App();
|
|
|
|
|
$app->enable($appId);
|
|
|
|
|
$this->appManager->enableApp($appId);
|
|
|
|
|
}
|
|
|
|
|
$bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true);
|
|
|
|
|
$bundles[] = $bundle->getIdentifier();
|
|
|
|
|
@ -534,25 +490,23 @@ class Installer {
|
|
|
|
|
* working ownCloud at the end instead of an aborted update.
|
|
|
|
|
* @return array Array of error messages (appid => Exception)
|
|
|
|
|
*/
|
|
|
|
|
public static function installShippedApps(bool $softErrors = false, ?IOutput $output = null): array {
|
|
|
|
|
public function installShippedApps(bool $softErrors = false, ?IOutput $output = null): array {
|
|
|
|
|
if ($output instanceof IOutput) {
|
|
|
|
|
$output->debug('Installing shipped apps');
|
|
|
|
|
}
|
|
|
|
|
$appManager = \OCP\Server::get(IAppManager::class);
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
$errors = [];
|
|
|
|
|
foreach (\OC::$APPSROOTS as $app_dir) {
|
|
|
|
|
if ($dir = opendir($app_dir['path'])) {
|
|
|
|
|
while (false !== ($filename = readdir($dir))) {
|
|
|
|
|
if ($filename[0] !== '.' and is_dir($app_dir['path'] . "/$filename")) {
|
|
|
|
|
if (file_exists($app_dir['path'] . "/$filename/appinfo/info.xml")) {
|
|
|
|
|
if ($config->getAppValue($filename, 'installed_version') === '') {
|
|
|
|
|
$enabled = $appManager->isDefaultEnabled($filename);
|
|
|
|
|
if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps()))
|
|
|
|
|
&& $config->getAppValue($filename, 'enabled') !== 'no') {
|
|
|
|
|
if ($this->config->getAppValue($filename, 'installed_version') === '') {
|
|
|
|
|
$enabled = $this->appManager->isDefaultEnabled($filename);
|
|
|
|
|
if (($enabled || in_array($filename, $this->appManager->getAlwaysEnabledApps()))
|
|
|
|
|
&& $this->config->getAppValue($filename, 'enabled') !== 'no') {
|
|
|
|
|
if ($softErrors) {
|
|
|
|
|
try {
|
|
|
|
|
Installer::installShippedApp($filename, $output);
|
|
|
|
|
$this->installShippedApp($filename, $output);
|
|
|
|
|
} catch (HintException $e) {
|
|
|
|
|
if ($e->getPrevious() instanceof TableExistsException) {
|
|
|
|
|
$errors[$filename] = $e;
|
|
|
|
|
@ -561,9 +515,9 @@ class Installer {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Installer::installShippedApp($filename, $output);
|
|
|
|
|
$this->installShippedApp($filename, $output);
|
|
|
|
|
}
|
|
|
|
|
$config->setAppValue($filename, 'enabled', 'yes');
|
|
|
|
|
$this->config->setAppValue($filename, 'enabled', 'yes');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -576,59 +530,79 @@ class Installer {
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* install an app already placed in the app folder
|
|
|
|
|
*/
|
|
|
|
|
public static function installShippedApp(string $app, ?IOutput $output = null): string|false {
|
|
|
|
|
if ($output instanceof IOutput) {
|
|
|
|
|
$output->debug('Installing ' . $app);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$appManager = \OCP\Server::get(IAppManager::class);
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
|
|
|
|
|
$appPath = $appManager->getAppPath($app);
|
|
|
|
|
\OC_App::registerAutoloading($app, $appPath);
|
|
|
|
|
private function installAppLastSteps(string $appPath, array $info, ?IOutput $output = null, string $enabled = 'no'): string {
|
|
|
|
|
\OC_App::registerAutoloading($info['id'], $appPath);
|
|
|
|
|
|
|
|
|
|
$ms = new MigrationService($app, \OCP\Server::get(Connection::class));
|
|
|
|
|
$previousVersion = $this->config->getAppValue($info['id'], 'installed_version', '');
|
|
|
|
|
$ms = new MigrationService($info['id'], Server::get(Connection::class));
|
|
|
|
|
if ($output instanceof IOutput) {
|
|
|
|
|
$ms->setOutput($output);
|
|
|
|
|
}
|
|
|
|
|
$previousVersion = $config->getAppValue($app, 'installed_version', false);
|
|
|
|
|
$ms->migrate('latest', !$previousVersion);
|
|
|
|
|
if ($previousVersion !== '') {
|
|
|
|
|
\OC_App::executeRepairSteps($info['id'], $info['repair-steps']['pre-migration']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//run appinfo/install.php
|
|
|
|
|
self::includeAppScript("$appPath/appinfo/install.php");
|
|
|
|
|
$ms->migrate('latest', $previousVersion === '');
|
|
|
|
|
|
|
|
|
|
$info = \OCP\Server::get(IAppManager::class)->getAppInfo($app);
|
|
|
|
|
if (is_null($info)) {
|
|
|
|
|
return false;
|
|
|
|
|
if ($previousVersion !== '') {
|
|
|
|
|
\OC_App::executeRepairSteps($info['id'], $info['repair-steps']['post-migration']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($output instanceof IOutput) {
|
|
|
|
|
$output->debug('Registering tasks of ' . $app);
|
|
|
|
|
$output->debug('Registering tasks of ' . $info['id']);
|
|
|
|
|
}
|
|
|
|
|
\OC_App::setupBackgroundJobs($info['background-jobs']);
|
|
|
|
|
|
|
|
|
|
OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
|
|
|
|
|
// Setup background jobs
|
|
|
|
|
$queue = Server::get(IJobList::class);
|
|
|
|
|
foreach ($info['background-jobs'] as $job) {
|
|
|
|
|
$queue->add($job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$config->setAppValue($app, 'installed_version', \OCP\Server::get(IAppManager::class)->getAppVersion($app));
|
|
|
|
|
if (array_key_exists('ocsid', $info)) {
|
|
|
|
|
$config->setAppValue($app, 'ocsid', $info['ocsid']);
|
|
|
|
|
// Run deprecated appinfo/install.php if any
|
|
|
|
|
$appInstallScriptPath = $appPath . '/appinfo/install.php';
|
|
|
|
|
if (file_exists($appInstallScriptPath)) {
|
|
|
|
|
$this->logger->warning('Using an appinfo/install.php file is deprecated. Application "{app}" still uses one.', [
|
|
|
|
|
'app' => $info['id'],
|
|
|
|
|
]);
|
|
|
|
|
self::includeAppScript($appInstallScriptPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set remote/public handlers
|
|
|
|
|
\OC_App::executeRepairSteps($info['id'], $info['repair-steps']['install']);
|
|
|
|
|
|
|
|
|
|
// Set the installed version
|
|
|
|
|
$this->config->setAppValue($info['id'], 'installed_version', $this->appManager->getAppVersion($info['id'], false));
|
|
|
|
|
$this->config->setAppValue($info['id'], 'enabled', $enabled);
|
|
|
|
|
|
|
|
|
|
// Set remote/public handlers
|
|
|
|
|
foreach ($info['remote'] as $name => $path) {
|
|
|
|
|
$config->setAppValue('core', 'remote_' . $name, $app . '/' . $path);
|
|
|
|
|
$this->config->setAppValue('core', 'remote_' . $name, $info['id'] . '/' . $path);
|
|
|
|
|
}
|
|
|
|
|
foreach ($info['public'] as $name => $path) {
|
|
|
|
|
$config->setAppValue('core', 'public_' . $name, $app . '/' . $path);
|
|
|
|
|
$this->config->setAppValue('core', 'public_' . $name, $info['id'] . '/' . $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OC_App::setAppTypes($info['id']);
|
|
|
|
|
\OC_App::setAppTypes($info['id']);
|
|
|
|
|
|
|
|
|
|
return $info['id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* install an app already placed in the app folder
|
|
|
|
|
*/
|
|
|
|
|
public function installShippedApp(string $app, ?IOutput $output = null): string|false {
|
|
|
|
|
if ($output instanceof IOutput) {
|
|
|
|
|
$output->debug('Installing ' . $app);
|
|
|
|
|
}
|
|
|
|
|
$info = $this->appManager->getAppInfo($app);
|
|
|
|
|
if (is_null($info) || $info['id'] !== $app) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$appPath = $this->appManager->getAppPath($app);
|
|
|
|
|
|
|
|
|
|
return $this->installAppLastSteps($appPath, $info, $output, 'yes');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function includeAppScript(string $script): void {
|
|
|
|
|
if (file_exists($script)) {
|
|
|
|
|
include $script;
|
|
|
|
|
|