Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to enable/disable maintenance mode from cli. #8748

Merged
merged 3 commits into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions core/command/maintenance/mode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2014?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code was written in 2013 by Robin. This is just a cp of singleuser.php with a handful of changes for the different config option. So I left it. Should it be changed to 2014 or 2013-2014?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another copyright line with 2014 and your name?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that you probably copied singleuser.php to mode.php and then swapped all the logic contained in the actually command class, I am not sure there is anything remaining that would have to attributed to robin.

* and Stephen Colebrook <scolebrook@mac.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

namespace OC\Core\Command\Maintenance;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Mode extends Command {

protected function configure() {
$this
->setName('maintenance:mode')
->setDescription('set maintenance mode')
->addOption(
'on',
null,
InputOption::VALUE_NONE,
'enable maintenance mode'
)
->addOption(
'off',
null,
InputOption::VALUE_NONE,
'disable maintenance mode'
);
}

protected function execute(InputInterface $input, OutputInterface $output) {
if ($input->getOption('on')) {
\OC_Config::setValue('maintenance', true);
$output->writeln('Maintenance mode enabled');
} elseif ($input->getOption('off')) {
\OC_Config::setValue('maintenance', false);
$output->writeln('Maintenance mode disabled');
} else {
if (\OC_Config::getValue('maintenance', false)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use elseif instead, which is one level less deep.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a computation perspective it doesn't make any difference but I prefer this style. There are three available options, on, off and nothing. In the event of nothing, status is displayed which can have two possible values.

So determining and returning that status is nested. Representing the 3 options as 4 parts of the same if block because one of the options can have two return values makes it a little less readable to my mind.

$output->writeln('Maintenance mode is currently enabled');
} else {
$output->writeln('Maintenance mode is currently disabled');
}
}
}
}
1 change: 1 addition & 0 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$application->add(new OC\Core\Command\Db\ConvertType(OC_Config::getObject(), new \OC\DB\ConnectionFactory()));
$application->add(new OC\Core\Command\Upgrade());
$application->add(new OC\Core\Command\Maintenance\SingleUser());
$application->add(new OC\Core\Command\Maintenance\Mode());
$application->add(new OC\Core\Command\App\Disable());
$application->add(new OC\Core\Command\App\Enable());
$application->add(new OC\Core\Command\App\ListApps());
Expand Down