2013-10-24 21:59:39 +04:00
< ? php
/**
2016-07-30 17:26:21 +03:00
* @ copyright Copyright ( c ) 2016 , ownCloud , Inc .
2016-07-21 18:07:57 +03:00
*
2015-03-26 13:44:34 +03:00
* @ author Andreas Fischer < bantu @ owncloud . com >
2020-03-31 11:49:10 +03:00
* @ author Christoph Wurst < christoph @ winzerhof - wurst . at >
2016-07-21 18:07:57 +03:00
* @ author Joas Schilling < coding @ schilljs . com >
2016-05-26 20:56:05 +03:00
* @ author Lukas Reschke < lukas @ statuscode . ch >
2015-03-26 13:44:34 +03:00
* @ author Morris Jobke < hey @ morrisjobke . de >
2020-12-16 16:54:15 +03:00
* @ author Nils Wittenbrink < nilswittenbrink @ web . de >
2015-03-26 13:44:34 +03:00
* @ author Owen Winkler < a_github @ midnightcircus . com >
2017-11-06 17:56:42 +03:00
* @ author Robin Appelman < robin @ icewind . nl >
* @ author Sander Ruitenbeek < sander @ grids . be >
2015-03-26 13:44:34 +03:00
* @ author Thomas Müller < thomas . mueller @ tmit . eu >
2016-07-21 18:07:57 +03:00
* @ author Thomas Pulzer < t . pulzer @ kniel . de >
2020-12-16 16:54:15 +03:00
* @ author Vincent Petry < vincent @ nextcloud . com >
2015-03-26 13:44:34 +03:00
*
* @ license AGPL - 3.0
*
* This code is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License , version 3 ,
* as published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License , version 3 ,
2019-12-03 21:57:53 +03:00
* along with this program . If not , see < http :// www . gnu . org / licenses />
2015-03-26 13:44:34 +03:00
*
2013-10-24 21:59:39 +04:00
*/
2015-02-26 13:37:37 +03:00
2013-10-24 21:59:39 +04:00
namespace OC\Core\Command ;
2015-06-23 18:07:28 +03:00
use OC\Console\TimestampFormatter ;
2017-11-24 12:27:58 +03:00
use OC\Installer ;
2013-10-28 18:15:56 +04:00
use OC\Updater ;
2014-09-22 14:04:48 +04:00
use OCP\IConfig ;
2017-11-30 18:00:19 +03:00
use OCP\Util ;
2021-04-22 16:22:50 +03:00
use Psr\Log\LoggerInterface ;
2013-10-24 21:59:39 +04:00
use Symfony\Component\Console\Command\Command ;
2016-03-31 00:38:26 +03:00
use Symfony\Component\Console\Helper\ProgressBar ;
2013-10-24 21:59:39 +04:00
use Symfony\Component\Console\Input\InputInterface ;
use Symfony\Component\Console\Output\OutputInterface ;
2016-03-31 00:38:26 +03:00
use Symfony\Component\EventDispatcher\GenericEvent ;
2013-10-24 21:59:39 +04:00
class Upgrade extends Command {
2020-04-10 17:54:27 +03:00
public const ERROR_SUCCESS = 0 ;
public const ERROR_NOT_INSTALLED = 1 ;
public const ERROR_MAINTENANCE_MODE = 2 ;
public const ERROR_UP_TO_DATE = 0 ;
public const ERROR_INVALID_ARGUMENTS = 4 ;
public const ERROR_FAILURE = 5 ;
2014-09-22 13:59:13 +04:00
2015-10-09 15:08:22 +03:00
/** @var IConfig */
2014-09-22 14:04:48 +04:00
private $config ;
2021-04-22 16:22:50 +03:00
/** @var LoggerInterface */
2015-10-09 15:08:22 +03:00
private $logger ;
2021-04-22 16:22:50 +03:00
/** @var Installer */
private $installer ;
public function __construct ( IConfig $config , LoggerInterface $logger , Installer $installer ) {
2014-11-03 15:53:59 +03:00
parent :: __construct ();
2014-09-22 14:04:48 +04:00
$this -> config = $config ;
2015-10-09 15:08:22 +03:00
$this -> logger = $logger ;
2017-11-24 12:27:58 +03:00
$this -> installer = $installer ;
2014-09-22 14:04:48 +04:00
}
2013-10-24 21:59:39 +04:00
protected function configure () {
$this
-> setName ( 'upgrade' )
2018-01-19 16:00:27 +03:00
-> setDescription ( 'run upgrade routines after installation of a new release. The release has to be installed before.' );
2013-10-24 21:59:39 +04:00
}
2014-03-14 13:48:07 +04:00
/**
* Execute the upgrade command
*
* @ param InputInterface $input input interface
* @ param OutputInterface $output output interface
*/
2020-06-26 15:54:51 +03:00
protected function execute ( InputInterface $input , OutputInterface $output ) : int {
2020-04-10 15:19:56 +03:00
if ( Util :: needUpgrade ()) {
2015-06-23 18:07:28 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
// Prepend each line with a little timestamp
$timestampFormatter = new TimestampFormatter ( $this -> config , $output -> getFormatter ());
$output -> setFormatter ( $timestampFormatter );
}
2014-09-22 13:59:13 +04:00
$self = $this ;
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$updater = new Updater (
$this -> config ,
\OC :: $server -> getIntegrityCodeChecker (),
2017-11-24 12:27:58 +03:00
$this -> logger ,
2018-11-01 14:52:09 +03:00
$this -> installer
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
);
2013-10-28 18:15:56 +04:00
2016-03-31 00:38:26 +03:00
$dispatcher = \OC :: $server -> getEventDispatcher ();
$progress = new ProgressBar ( $output );
2016-04-04 17:20:53 +03:00
$progress -> setFormat ( " %message% \n %current%/%max% [%bar%] %percent:3s%% " );
2020-04-09 14:53:40 +03:00
$listener = function ( $event ) use ( $progress , $output ) {
2016-03-31 00:38:26 +03:00
if ( $event instanceof GenericEvent ) {
2016-03-31 13:41:57 +03:00
$message = $event -> getSubject ();
2016-04-04 17:20:53 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
$output -> writeln ( ' Checking table ' . $message );
} else {
if ( strlen ( $message ) > 60 ) {
$message = substr ( $message , 0 , 57 ) . '...' ;
}
$progress -> setMessage ( $message );
if ( $event [ 0 ] === 1 ) {
$output -> writeln ( '' );
$progress -> start ( $event [ 1 ]);
}
$progress -> setProgress ( $event [ 0 ]);
if ( $event [ 0 ] === $event [ 1 ]) {
$progress -> setMessage ( 'Done' );
$progress -> finish ();
$output -> writeln ( '' );
}
2016-03-31 00:38:26 +03:00
}
}
2016-04-04 17:20:53 +03:00
};
2020-04-09 14:53:40 +03:00
$repairListener = function ( $event ) use ( $progress , $output ) {
2016-04-27 14:19:00 +03:00
if ( ! $event instanceof GenericEvent ) {
return ;
}
switch ( $event -> getSubject ()) {
case '\OC\Repair::startProgress' :
$progress -> setMessage ( 'Starting ...' );
$output -> writeln ( $event -> getArgument ( 1 ));
$output -> writeln ( '' );
$progress -> start ( $event -> getArgument ( 0 ));
break ;
case '\OC\Repair::advance' :
$desc = $event -> getArgument ( 1 );
if ( ! empty ( $desc )) {
$progress -> setMessage ( $desc );
}
$progress -> advance ( $event -> getArgument ( 0 ));
break ;
case '\OC\Repair::finishProgress' :
$progress -> setMessage ( 'Done' );
$progress -> finish ();
$output -> writeln ( '' );
break ;
case '\OC\Repair::step' :
2020-04-10 15:19:56 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
2016-04-27 14:19:00 +03:00
$output -> writeln ( '<info>Repair step: ' . $event -> getArgument ( 0 ) . '</info>' );
}
break ;
case '\OC\Repair::info' :
2020-04-10 15:19:56 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
2016-04-27 14:19:00 +03:00
$output -> writeln ( '<info>Repair info: ' . $event -> getArgument ( 0 ) . '</info>' );
}
break ;
case '\OC\Repair::warning' :
$output -> writeln ( '<error>Repair warning: ' . $event -> getArgument ( 0 ) . '</error>' );
break ;
case '\OC\Repair::error' :
$output -> writeln ( '<error>Repair error: ' . $event -> getArgument ( 0 ) . '</error>' );
break ;
}
};
2016-04-04 17:20:53 +03:00
$dispatcher -> addListener ( '\OC\DB\Migrator::executeSql' , $listener );
$dispatcher -> addListener ( '\OC\DB\Migrator::checkTable' , $listener );
2016-04-27 14:19:00 +03:00
$dispatcher -> addListener ( '\OC\Repair::startProgress' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::advance' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::finishProgress' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::step' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::info' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::warning' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::error' , $repairListener );
2019-02-06 19:08:41 +03:00
2014-06-05 18:19:24 +04:00
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'maintenanceEnabled' , function () use ( $output ) {
2013-10-29 01:26:44 +04:00
$output -> writeln ( '<info>Turned on maintenance mode</info>' );
2013-10-28 18:15:56 +04:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'maintenanceDisabled' , function () use ( $output ) {
2015-05-19 11:27:53 +03:00
$output -> writeln ( '<info>Turned off maintenance mode</info>' );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'maintenanceActive' , function () use ( $output ) {
2015-05-19 11:27:53 +03:00
$output -> writeln ( '<info>Maintenance mode is kept active</info>' );
});
$updater -> listen ( '\OC\Updater' , 'updateEnd' ,
2020-04-09 14:53:40 +03:00
function ( $success ) use ( $output , $self ) {
2015-06-23 18:07:28 +03:00
if ( $success ) {
2016-09-21 16:12:00 +03:00
$message = " <info>Update successful</info> " ;
2015-06-23 18:07:28 +03:00
} else {
2016-09-21 16:12:00 +03:00
$message = " <error>Update failed</error> " ;
2015-06-23 18:07:28 +03:00
}
2014-09-22 13:59:13 +04:00
$output -> writeln ( $message );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'dbUpgradeBefore' , function () use ( $output ) {
2015-10-21 10:17:38 +03:00
$output -> writeln ( '<info>Updating database schema</info>' );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'dbUpgrade' , function () use ( $output ) {
2013-10-29 01:26:44 +04:00
$output -> writeln ( '<info>Updated database</info>' );
2013-10-28 18:15:56 +04:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'incompatibleAppDisabled' , function ( $app ) use ( $output ) {
2016-08-09 14:46:41 +03:00
$output -> writeln ( '<comment>Disabled incompatible app: ' . $app . '</comment>' );
2015-02-17 14:00:39 +03:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'checkAppStoreAppBefore' , function ( $app ) use ( $output ) {
2017-05-11 21:35:17 +03:00
$output -> writeln ( '<info>Checking for update of app ' . $app . ' in appstore</info>' );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'upgradeAppStoreApp' , function ( $app ) use ( $output ) {
2017-05-11 21:35:17 +03:00
$output -> writeln ( '<info>Update app ' . $app . ' from appstore</info>' );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'checkAppStoreApp' , function ( $app ) use ( $output ) {
2017-05-11 21:35:17 +03:00
$output -> writeln ( '<info>Checked for update of app "' . $app . '" in appstore </info>' );
2015-05-12 19:02:31 +03:00
});
2015-10-21 10:17:38 +03:00
$updater -> listen ( '\OC\Updater' , 'appSimulateUpdate' , function ( $app ) use ( $output ) {
$output -> writeln ( " <info>Checking whether the database schema for < $app > can be updated (this can take a long time depending on the database size)</info> " );
});
2015-06-23 11:43:45 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgradeStarted' , function ( $app , $version ) use ( $output ) {
$output -> writeln ( " <info>Updating < $app > ...</info> " );
});
2015-02-24 14:52:16 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgrade' , function ( $app , $version ) use ( $output ) {
$output -> writeln ( " <info>Updated < $app > to $version </info> " );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'failure' , function ( $message ) use ( $output , $self ) {
2014-09-22 13:59:13 +04:00
$output -> writeln ( " <error> $message </error> " );
2013-10-28 18:15:56 +04:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'setDebugLogLevel' , function ( $logLevel , $logLevelName ) use ( $output ) {
2020-09-10 16:17:59 +03:00
$output -> writeln ( " <info>Setting log level to debug</info> " );
2015-09-29 15:35:32 +03:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'resetLogLevel' , function ( $logLevel , $logLevelName ) use ( $output ) {
2020-09-10 16:17:59 +03:00
$output -> writeln ( " <info>Resetting log level</info> " );
2015-09-29 15:35:32 +03:00
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'startCheckCodeIntegrity' , function () use ( $output ) {
2016-01-22 15:18:00 +03:00
$output -> writeln ( " <info>Starting code integrity check...</info> " );
});
2020-04-09 14:53:40 +03:00
$updater -> listen ( '\OC\Updater' , 'finishedCheckCodeIntegrity' , function () use ( $output ) {
2016-01-22 15:18:00 +03:00
$output -> writeln ( " <info>Finished code integrity check</info> " );
});
2013-10-28 18:15:56 +04:00
2015-06-23 11:03:27 +03:00
$success = $updater -> upgrade ();
2014-03-14 13:48:07 +04:00
$this -> postUpgradeCheck ( $input , $output );
2020-04-10 15:19:56 +03:00
if ( ! $success ) {
2015-06-23 11:03:27 +03:00
return self :: ERROR_FAILURE ;
}
2013-10-29 00:50:28 +04:00
return self :: ERROR_SUCCESS ;
2020-04-10 15:19:56 +03:00
} elseif ( $this -> config -> getSystemValueBool ( 'maintenance' )) {
2016-07-30 16:39:32 +03:00
//Possible scenario: Nextcloud core is updated but an app failed
2021-01-15 18:38:25 +03:00
$output -> writeln ( '<comment>Nextcloud is in maintenance mode</comment>' );
2013-10-29 01:26:44 +04:00
$output -> write ( '<comment>Maybe an upgrade is already in process. Please check the '
2016-07-04 12:50:32 +03:00
. 'logfile (data/nextcloud.log). If you want to re-run the '
2013-10-29 01:19:15 +04:00
. 'upgrade procedure, remove the "maintenance mode" from '
2013-10-29 01:26:44 +04:00
. 'config.php and call this script again.</comment>'
2013-10-29 01:19:15 +04:00
, true );
return self :: ERROR_MAINTENANCE_MODE ;
2013-10-28 18:15:56 +04:00
} else {
2016-07-30 16:39:32 +03:00
$output -> writeln ( '<info>Nextcloud is already latest version</info>' );
2013-10-29 01:19:15 +04:00
return self :: ERROR_UP_TO_DATE ;
2013-10-28 18:15:56 +04:00
}
2013-10-24 21:59:39 +04:00
}
2014-03-14 13:48:07 +04:00
/**
* Perform a post upgrade check ( specific to the command line tool )
*
* @ param InputInterface $input input interface
* @ param OutputInterface $output output interface
*/
protected function postUpgradeCheck ( InputInterface $input , OutputInterface $output ) {
2020-03-26 11:30:18 +03:00
$trustedDomains = $this -> config -> getSystemValue ( 'trusted_domains' , []);
2014-03-14 13:48:07 +04:00
if ( empty ( $trustedDomains )) {
$output -> write (
'<warning>The setting "trusted_domains" could not be ' .
'set automatically by the upgrade script, ' .
'please set it manually</warning>'
);
}
}
2013-10-24 21:59:39 +04:00
}