summaryrefslogtreecommitdiffstats
path: root/core/Command/Maintenance
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-04-06 10:40:55 +0200
committerLukas Reschke <lukas@owncloud.com>2016-04-06 11:00:52 +0200
commita4b19a5b1e4079752e33d6eb75c72a47ce048bde (patch)
treedb63cde4a4c0c69fd7c284331ba84367a93279f6 /core/Command/Maintenance
parent046506dd146f823499098d0d2b0042072e436469 (diff)
downloadnextcloud-server-a4b19a5b1e4079752e33d6eb75c72a47ce048bde.tar.gz
nextcloud-server-a4b19a5b1e4079752e33d6eb75c72a47ce048bde.zip
Rename files to be PSR-4 compliant
Diffstat (limited to 'core/Command/Maintenance')
-rw-r--r--core/Command/Maintenance/Install.php178
-rw-r--r--core/Command/Maintenance/Mimetype/UpdateDB.php97
-rw-r--r--core/Command/Maintenance/Mimetype/UpdateJS.php129
-rw-r--r--core/Command/Maintenance/Mode.php75
-rw-r--r--core/Command/Maintenance/Repair.php91
-rw-r--r--core/Command/Maintenance/SingleUser.php78
6 files changed, 648 insertions, 0 deletions
diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php
new file mode 100644
index 00000000000..b1b63b9b3bd
--- /dev/null
+++ b/core/Command/Maintenance/Install.php
@@ -0,0 +1,178 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Christian Kampka <christian@kampka.net>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OC\Core\Command\Maintenance;
+
+use InvalidArgumentException;
+use OC\Setup;
+use OCP\IConfig;
+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 Install extends Command {
+
+ /**
+ * @var IConfig
+ */
+ private $config;
+
+ public function __construct(IConfig $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:install')
+ ->setDescription('install ownCloud')
+ ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
+ ->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
+ ->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
+ ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
+ ->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
+ ->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null)
+ ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
+ ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
+ ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+
+ // validate the environment
+ $server = \OC::$server;
+ $setupHelper = new Setup($this->config, $server->getIniWrapper(),
+ $server->getL10N('lib'), new \OC_Defaults(), $server->getLogger(),
+ $server->getSecureRandom());
+ $sysInfo = $setupHelper->getSystemInfo(true);
+ $errors = $sysInfo['errors'];
+ if (count($errors) > 0) {
+ $this->printErrors($output, $errors);
+
+ // ignore the OS X setup warning
+ if(count($errors) !== 1 ||
+ (string)($errors[0]['error']) !== 'Mac OS X is not supported and ownCloud will not work properly on this platform. Use it at your own risk! ') {
+ return 1;
+ }
+ }
+
+ // validate user input
+ $options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
+
+ // perform installation
+ $errors = $setupHelper->install($options);
+ if (count($errors) > 0) {
+ $this->printErrors($output, $errors);
+ return 1;
+ }
+ $output->writeln("ownCloud was successfully installed");
+ return 0;
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @param string[] $supportedDatabases
+ * @return array
+ */
+ protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
+ $db = strtolower($input->getOption('database'));
+
+ if (!in_array($db, $supportedDatabases)) {
+ throw new InvalidArgumentException("Database <$db> is not supported.");
+ }
+
+ $dbUser = $input->getOption('database-user');
+ $dbPass = $input->getOption('database-pass');
+ $dbName = $input->getOption('database-name');
+ $dbHost = $input->getOption('database-host');
+ $dbTablePrefix = 'oc_';
+ if ($input->hasParameterOption('--database-table-prefix')) {
+ $dbTablePrefix = (string) $input->getOption('database-table-prefix');
+ $dbTablePrefix = trim($dbTablePrefix);
+ }
+ if ($input->hasParameterOption('--database-pass')) {
+ $dbPass = (string) $input->getOption('database-pass');
+ }
+ $adminLogin = $input->getOption('admin-user');
+ $adminPassword = $input->getOption('admin-pass');
+ $dataDir = $input->getOption('data-dir');
+
+ if ($db !== 'sqlite') {
+ if (is_null($dbUser)) {
+ throw new InvalidArgumentException("Database user not provided.");
+ }
+ if (is_null($dbName)) {
+ throw new InvalidArgumentException("Database name not provided.");
+ }
+ if (is_null($dbPass)) {
+ /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
+ $dialog = $this->getHelperSet()->get('dialog');
+ $dbPass = $dialog->askHiddenResponse(
+ $output,
+ "<question>What is the password to access the database with user <$dbUser>?</question>",
+ false
+ );
+ }
+ }
+
+ if (is_null($adminPassword)) {
+ /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
+ $dialog = $this->getHelperSet()->get('dialog');
+ $adminPassword = $dialog->askHiddenResponse(
+ $output,
+ "<question>What is the password you like to use for the admin account <$adminLogin>?</question>",
+ false
+ );
+ }
+
+ $options = [
+ 'dbtype' => $db,
+ 'dbuser' => $dbUser,
+ 'dbpass' => $dbPass,
+ 'dbname' => $dbName,
+ 'dbhost' => $dbHost,
+ 'dbtableprefix' => $dbTablePrefix,
+ 'adminlogin' => $adminLogin,
+ 'adminpass' => $adminPassword,
+ 'directory' => $dataDir
+ ];
+ return $options;
+ }
+
+ /**
+ * @param OutputInterface $output
+ * @param $errors
+ */
+ protected function printErrors(OutputInterface $output, $errors) {
+ foreach ($errors as $error) {
+ if (is_array($error)) {
+ $output->writeln('<error>' . (string)$error['error'] . '</error>');
+ $output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
+ } else {
+ $output->writeln('<error>' . (string)$error . '</error>');
+ }
+ }
+ }
+}
diff --git a/core/Command/Maintenance/Mimetype/UpdateDB.php b/core/Command/Maintenance/Mimetype/UpdateDB.php
new file mode 100644
index 00000000000..9532f9e1cd9
--- /dev/null
+++ b/core/Command/Maintenance/Mimetype/UpdateDB.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Maintenance\Mimetype;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
+
+use OCP\Files\IMimeTypeDetector;
+use OCP\Files\IMimeTypeLoader;
+
+class UpdateDB extends Command {
+
+ const DEFAULT_MIMETYPE = 'application/octet-stream';
+
+ /** @var IMimeTypeDetector */
+ protected $mimetypeDetector;
+
+ /** @var IMimeTypeLoader */
+ protected $mimetypeLoader;
+
+ public function __construct(
+ IMimeTypeDetector $mimetypeDetector,
+ IMimeTypeLoader $mimetypeLoader
+ ) {
+ parent::__construct();
+ $this->mimetypeDetector = $mimetypeDetector;
+ $this->mimetypeLoader = $mimetypeLoader;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:mimetype:update-db')
+ ->setDescription('Update database mimetypes and update filecache')
+ ->addOption(
+ 'repair-filecache',
+ null,
+ InputOption::VALUE_NONE,
+ 'Repair filecache for all mimetypes, not just new ones'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $mappings = $this->mimetypeDetector->getAllMappings();
+
+ $totalFilecacheUpdates = 0;
+ $totalNewMimetypes = 0;
+
+ foreach ($mappings as $ext => $mimetypes) {
+ if ($ext[0] === '_') {
+ // comment
+ continue;
+ }
+ $mimetype = $mimetypes[0];
+ $existing = $this->mimetypeLoader->exists($mimetype);
+ // this will add the mimetype if it didn't exist
+ $mimetypeId = $this->mimetypeLoader->getId($mimetype);
+
+ if (!$existing) {
+ $output->writeln('Added mimetype "'.$mimetype.'" to database');
+ $totalNewMimetypes++;
+ }
+
+ if (!$existing || $input->getOption('repair-filecache')) {
+ $touchedFilecacheRows = $this->mimetypeLoader->updateFilecache($ext, $mimetypeId);
+ if ($touchedFilecacheRows > 0) {
+ $output->writeln('Updated '.$touchedFilecacheRows.' filecache rows for mimetype "'.$mimetype.'"');
+ }
+ $totalFilecacheUpdates += $touchedFilecacheRows;
+ }
+ }
+
+ $output->writeln('Added '.$totalNewMimetypes.' new mimetypes');
+ $output->writeln('Updated '.$totalFilecacheUpdates.' filecache rows');
+ }
+}
diff --git a/core/Command/Maintenance/Mimetype/UpdateJS.php b/core/Command/Maintenance/Mimetype/UpdateJS.php
new file mode 100644
index 00000000000..a87f50e32de
--- /dev/null
+++ b/core/Command/Maintenance/Mimetype/UpdateJS.php
@@ -0,0 +1,129 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Maintenance\Mimetype;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use OCP\Files\IMimeTypeDetector;
+
+class UpdateJS extends Command {
+
+ /** @var IMimeTypeDetector */
+ protected $mimetypeDetector;
+
+ public function __construct(
+ IMimeTypeDetector $mimetypeDetector
+ ) {
+ parent::__construct();
+ $this->mimetypeDetector = $mimetypeDetector;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:mimetype:update-js')
+ ->setDescription('Update mimetypelist.js');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ // Fetch all the aliases
+ $aliases = $this->mimetypeDetector->getAllAliases();
+
+ // Remove comments
+ $keys = array_filter(array_keys($aliases), function($k) {
+ return $k[0] === '_';
+ });
+ foreach($keys as $key) {
+ unset($aliases[$key]);
+ }
+
+ // Fetch all files
+ $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
+
+ $files = [];
+ foreach($dir as $fileInfo) {
+ if ($fileInfo->isFile()) {
+ $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
+ $files[] = $file;
+ }
+ }
+
+ //Remove duplicates
+ $files = array_values(array_unique($files));
+ sort($files);
+
+ // Fetch all themes!
+ $themes = [];
+ $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
+ foreach($dirs as $dir) {
+ //Valid theme dir
+ if ($dir->isFile() || $dir->isDot()) {
+ continue;
+ }
+
+ $theme = $dir->getFilename();
+ $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
+ // Check if this theme has its own filetype icons
+ if (!file_exists($themeDir)) {
+ continue;
+ }
+
+ $themes[$theme] = [];
+ // Fetch all the theme icons!
+ $themeIt = new \DirectoryIterator($themeDir);
+ foreach ($themeIt as $fileInfo) {
+ if ($fileInfo->isFile()) {
+ $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
+ $themes[$theme][] = $file;
+ }
+ }
+
+ //Remove Duplicates
+ $themes[$theme] = array_values(array_unique($themes[$theme]));
+ sort($themes[$theme]);
+ }
+
+ //Generate the JS
+ $js = '/**
+* This file is automatically generated
+* DO NOT EDIT MANUALLY!
+*
+* You can update the list of MimeType Aliases in config/mimetypealiases.json
+* The list of files is fetched from core/img/filetypes
+* To regenerate this file run ./occ maintenance:mimetypesjs
+*/
+OC.MimeTypeList={
+ aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
+ files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
+ themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
+};
+';
+
+ //Output the JS
+ file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $js);
+
+ $output->writeln('<info>mimetypelist.js is updated');
+ }
+}
diff --git a/core/Command/Maintenance/Mode.php b/core/Command/Maintenance/Mode.php
new file mode 100644
index 00000000000..28f4fb2f7f1
--- /dev/null
+++ b/core/Command/Maintenance/Mode.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author scolebrook <scolebrook@mac.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Maintenance;
+
+use \OCP\IConfig;
+
+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 {
+
+ /** @var IConfig */
+ protected $config;
+
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ parent::__construct();
+ }
+
+ 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')) {
+ $this->config->setSystemValue('maintenance', true);
+ $output->writeln('Maintenance mode enabled');
+ } elseif ($input->getOption('off')) {
+ $this->config->setSystemValue('maintenance', false);
+ $output->writeln('Maintenance mode disabled');
+ } else {
+ if ($this->config->getSystemValue('maintenance', false)) {
+ $output->writeln('Maintenance mode is currently enabled');
+ } else {
+ $output->writeln('Maintenance mode is currently disabled');
+ }
+ }
+ }
+}
diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php
new file mode 100644
index 00000000000..95e2b872227
--- /dev/null
+++ b/core/Command/Maintenance/Repair.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+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 Repair extends Command {
+ /**
+ * @var \OC\Repair $repair
+ */
+ protected $repair;
+ /** @var \OCP\IConfig */
+ protected $config;
+
+ /**
+ * @param \OC\Repair $repair
+ * @param \OCP\IConfig $config
+ */
+ public function __construct(\OC\Repair $repair, \OCP\IConfig $config) {
+ $this->repair = $repair;
+ $this->config = $config;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:repair')
+ ->setDescription('repair this installation')
+ ->addOption(
+ 'include-expensive',
+ null,
+ InputOption::VALUE_NONE,
+ 'Use this option when you want to include resource and load expensive tasks'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $includeExpensive = $input->getOption('include-expensive');
+ if ($includeExpensive) {
+ foreach ($this->repair->getExpensiveRepairSteps() as $step) {
+ $this->repair->addStep($step);
+ }
+ }
+
+ $maintenanceMode = $this->config->getSystemValue('maintenance', false);
+ $this->config->setSystemValue('maintenance', true);
+
+ $this->repair->listen('\OC\Repair', 'step', function ($description) use ($output) {
+ $output->writeln(' - ' . $description);
+ });
+ $this->repair->listen('\OC\Repair', 'info', function ($description) use ($output) {
+ $output->writeln(' - ' . $description);
+ });
+ $this->repair->listen('\OC\Repair', 'warning', function ($description) use ($output) {
+ $output->writeln(' - WARNING: ' . $description);
+ });
+ $this->repair->listen('\OC\Repair', 'error', function ($description) use ($output) {
+ $output->writeln(' - ERROR: ' . $description);
+ });
+
+ $this->repair->run();
+
+ $this->config->setSystemValue('maintenance', $maintenanceMode);
+ }
+}
diff --git a/core/Command/Maintenance/SingleUser.php b/core/Command/Maintenance/SingleUser.php
new file mode 100644
index 00000000000..2e6f1f136e7
--- /dev/null
+++ b/core/Command/Maintenance/SingleUser.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+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;
+
+use OCP\IConfig;
+
+class SingleUser extends Command {
+
+ /** @var IConfig */
+ protected $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:singleuser')
+ ->setDescription('set single user mode')
+ ->addOption(
+ 'on',
+ null,
+ InputOption::VALUE_NONE,
+ 'enable single user mode'
+ )
+ ->addOption(
+ 'off',
+ null,
+ InputOption::VALUE_NONE,
+ 'disable single user mode'
+ );
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ if ($input->getOption('on')) {
+ $this->config->setSystemValue('singleuser', true);
+ $output->writeln('Single user mode enabled');
+ } elseif ($input->getOption('off')) {
+ $this->config->setSystemValue('singleuser', false);
+ $output->writeln('Single user mode disabled');
+ } else {
+ if ($this->config->getSystemValue('singleuser', false)) {
+ $output->writeln('Single user mode is currently enabled');
+ } else {
+ $output->writeln('Single user mode is currently disabled');
+ }
+ }
+ }
+}