Côme Chilliet 2 days ago
committed by GitHub
parent
commit
f5144cbd8a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 67
      appupgrade.php
  2. 17
      core/Command/App/Update.php

67
appupgrade.php

@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;
/**
* This file is used to run the upgrade process of an application in occ upgrade command,
* after downloading the application code. This needs to be done in its own process to make
* sure it uses up-to-date code and autoloaders.
*/
require_once __DIR__ . '/lib/versioncheck.php';
try {
require_once __DIR__ . '/lib/base.php';
if (!\OC::$CLI) {
throw new \Exception('This file can only be used in CLI');
}
if (isset($argv[1])) {
$appid = $argv[1];
} else {
throw new \Exception('No appid');
}
$config = Server::get(IConfig::class);
// Don't do anything if Nextcloud has not been installed
if (!$config->getSystemValueBool('installed', false)) {
// TODO: check if this may be needed before installation is complete
exit(0);
}
$appManager = Server::get(IAppManager::class);
$logger = Server::get(LoggerInterface::class);
// set to run indefinitely if needed
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
@set_time_limit(0);
}
$success = $appManager->upgradeApp($appid);
if ($success) {
exit();
} else {
exit(1);
}
} catch (Throwable $ex) {
Server::get(LoggerInterface::class)->error(
$ex->getMessage(),
['app' => 'appupgrade.php', 'exception' => $ex]
);
echo $ex . PHP_EOL;
exit(1);
}

17
core/Command/App/Update.php

@ -79,13 +79,14 @@ class Update extends Command {
$return = 0;
foreach ($apps as $appId) {
$newVersion = $this->installer->isUpdateAvailable($appId, $input->getOption('allow-unstable'));
if ($newVersion) {
if ($newVersion !== false) {
$updateFound = true;
$output->writeln($appId . ' new version available: ' . $newVersion);
if (!$input->getOption('showonly')) {
try {
$result = $this->installer->updateAppstoreApp($appId, $input->getOption('allow-unstable'));
$this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
$result = $this->runUpgradeInSubProcess($appId);
} catch (\Exception $e) {
$this->logger->error('Failure during update of app "' . $appId . '"', [
'app' => 'app:update',
@ -116,4 +117,16 @@ class Update extends Command {
return $return;
}
protected function runUpgradeInSubProcess(string $appId): bool {
$command = PHP_BINARY . ' ' . \OC::$SERVERROOT . '/appudate.php ' . escapeshellarg($appId);
$execResult = exec($command, result_code:$resultCode);
if ($execResult === false) {
return false;
}
if ($resultCode !== 0) {
return false;
}
return true;
}
}
Loading…
Cancel
Save