aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Maintenance
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Maintenance')
-rw-r--r--core/Command/Maintenance/DataFingerprint.php4
-rw-r--r--core/Command/Maintenance/Install.php30
-rw-r--r--core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php22
-rw-r--r--core/Command/Maintenance/Mimetype/UpdateDB.php12
-rw-r--r--core/Command/Maintenance/Mimetype/UpdateJS.php3
-rw-r--r--core/Command/Maintenance/Mode.php3
-rw-r--r--core/Command/Maintenance/Repair.php4
-rw-r--r--core/Command/Maintenance/RepairShareOwnership.php20
-rw-r--r--core/Command/Maintenance/UpdateHtaccess.php3
-rw-r--r--core/Command/Maintenance/UpdateTheme.php1
10 files changed, 66 insertions, 36 deletions
diff --git a/core/Command/Maintenance/DataFingerprint.php b/core/Command/Maintenance/DataFingerprint.php
index 15a427e2cc6..014d6c411a4 100644
--- a/core/Command/Maintenance/DataFingerprint.php
+++ b/core/Command/Maintenance/DataFingerprint.php
@@ -28,7 +28,9 @@ class DataFingerprint extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $this->config->setSystemValue('data-fingerprint', md5($this->timeFactory->getTime()));
+ $fingerPrint = md5($this->timeFactory->getTime());
+ $this->config->setSystemValue('data-fingerprint', $fingerPrint);
+ $output->writeln('<info>Updated data-fingerprint to ' . $fingerPrint . '</info>');
return 0;
}
}
diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php
index bfe955f9979..6170c5a2638 100644
--- a/core/Command/Maintenance/Install.php
+++ b/core/Command/Maintenance/Install.php
@@ -15,6 +15,7 @@ use OC\Console\TimestampFormatter;
use OC\Migration\ConsoleOutput;
use OC\Setup;
use OC\SystemConfig;
+use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
@@ -43,23 +44,24 @@ class Install extends Command {
->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'Login to connect to the database')
->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null)
+ ->addOption('disable-admin-user', null, InputOption::VALUE_NONE, 'Disable the creation of an admin user')
->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'Login of the admin account', 'admin')
->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
- ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
+ ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT . '/data');
}
protected function execute(InputInterface $input, OutputInterface $output): int {
// validate the environment
- $setupHelper = \OCP\Server::get(\OC\Setup::class);
+ $setupHelper = Server::get(Setup::class);
$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 Nextcloud will not work properly on this platform. Use it at your own risk! ') {
+ if (count($errors) !== 1
+ || (string)$errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk!') {
return 1;
}
}
@@ -85,7 +87,7 @@ class Install extends Command {
if ($setupHelper->shouldRemoveCanInstallFile()) {
$output->writeln('<warn>Could not remove CAN_INSTALL from the config folder. Please remove this file manually.</warn>');
}
- $output->writeln("Nextcloud was successfully installed");
+ $output->writeln('Nextcloud was successfully installed');
return 0;
}
@@ -99,7 +101,7 @@ class Install extends Command {
$db = strtolower($input->getOption('database'));
if (!in_array($db, $supportedDatabases)) {
- throw new InvalidArgumentException("Database <$db> is not supported. " . implode(", ", $supportedDatabases) . " are supported.");
+ throw new InvalidArgumentException("Database <$db> is not supported. " . implode(', ', $supportedDatabases) . ' are supported.');
}
$dbUser = $input->getOption('database-user');
@@ -117,8 +119,9 @@ class Install extends Command {
$dbHost .= ':' . $dbPort;
}
if ($input->hasParameterOption('--database-pass')) {
- $dbPass = (string) $input->getOption('database-pass');
+ $dbPass = (string)$input->getOption('database-pass');
}
+ $disableAdminUser = (bool)$input->getOption('disable-admin-user');
$adminLogin = $input->getOption('admin-user');
$adminPassword = $input->getOption('admin-pass');
$adminEmail = $input->getOption('admin-email');
@@ -126,31 +129,31 @@ class Install extends Command {
if ($db !== 'sqlite') {
if (is_null($dbUser)) {
- throw new InvalidArgumentException("Database account not provided.");
+ throw new InvalidArgumentException('Database account not provided.');
}
if (is_null($dbName)) {
- throw new InvalidArgumentException("Database name not provided.");
+ throw new InvalidArgumentException('Database name not provided.');
}
if (is_null($dbPass)) {
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
- $question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
+ $question = new Question('What is the password to access the database with user <' . $dbUser . '>?');
$question->setHidden(true);
$question->setHiddenFallback(false);
$dbPass = $helper->ask($input, $output, $question);
}
}
- if (is_null($adminPassword)) {
+ if (!$disableAdminUser && $adminPassword === null) {
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
- $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
+ $question = new Question('What is the password you like to use for the admin account <' . $adminLogin . '>?');
$question->setHidden(true);
$question->setHiddenFallback(false);
$adminPassword = $helper->ask($input, $output, $question);
}
- if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
+ if (!$disableAdminUser && $adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
}
@@ -160,6 +163,7 @@ class Install extends Command {
'dbpass' => $dbPass,
'dbname' => $dbName,
'dbhost' => $dbHost,
+ 'admindisable' => $disableAdminUser,
'adminlogin' => $adminLogin,
'adminpass' => $adminPassword,
'adminemail' => $adminEmail,
diff --git a/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php b/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php
index 1a6c3933461..f8f19a61993 100644
--- a/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php
+++ b/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php
@@ -15,14 +15,18 @@ class GenerateMimetypeFileBuilder {
* @param array<string,string> $aliases
* @return string
*/
- public function generateFile(array $aliases): string {
+ public function generateFile(array $aliases, array $names): string {
// Remove comments
$aliases = array_filter($aliases, static function ($key) {
+ // Single digit extensions will be treated as integers
+ // Let's make sure they are strings
+ // https://github.com/nextcloud/server/issues/42902
+ $key = (string)$key;
return !($key === '' || $key[0] === '_');
}, ARRAY_FILTER_USE_KEY);
// Fetch all files
- $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
+ $dir = new \DirectoryIterator(\OC::$SERVERROOT . '/core/img/filetypes');
$files = [];
foreach ($dir as $fileInfo) {
@@ -38,7 +42,7 @@ class GenerateMimetypeFileBuilder {
// Fetch all themes!
$themes = [];
- $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
+ $dirs = new \DirectoryIterator(\OC::$SERVERROOT . '/themes/');
foreach ($dirs as $dir) {
//Valid theme dir
if ($dir->isFile() || $dir->isDot()) {
@@ -67,6 +71,15 @@ class GenerateMimetypeFileBuilder {
sort($themes[$theme]);
}
+ $namesOutput = '';
+ foreach ($names as $key => $name) {
+ if (str_starts_with($key, '_') || trim($name) === '') {
+ // Skip internal names
+ continue;
+ }
+ $namesOutput .= "'$key': t('core', " . json_encode($name) . "),\n";
+ }
+
//Generate the JS
return '/**
* This file is automatically generated
@@ -79,7 +92,8 @@ class GenerateMimetypeFileBuilder {
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) . '
+ themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ',
+ names: {' . $namesOutput . '},
};
';
}
diff --git a/core/Command/Maintenance/Mimetype/UpdateDB.php b/core/Command/Maintenance/Mimetype/UpdateDB.php
index fd448cf862a..4467e89eb32 100644
--- a/core/Command/Maintenance/Mimetype/UpdateDB.php
+++ b/core/Command/Maintenance/Mimetype/UpdateDB.php
@@ -45,6 +45,10 @@ class UpdateDB extends Command {
$totalNewMimetypes = 0;
foreach ($mappings as $ext => $mimetypes) {
+ // Single digit extensions will be treated as integers
+ // Let's make sure they are strings
+ // https://github.com/nextcloud/server/issues/42902
+ $ext = (string)$ext;
if ($ext[0] === '_') {
// comment
continue;
@@ -55,21 +59,21 @@ class UpdateDB extends Command {
$mimetypeId = $this->mimetypeLoader->getId($mimetype);
if (!$existing) {
- $output->writeln('Added mimetype "'.$mimetype.'" to database');
+ $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.'"');
+ $output->writeln('Updated ' . $touchedFilecacheRows . ' filecache rows for mimetype "' . $mimetype . '"');
}
$totalFilecacheUpdates += $touchedFilecacheRows;
}
}
- $output->writeln('Added '.$totalNewMimetypes.' new mimetypes');
- $output->writeln('Updated '.$totalFilecacheUpdates.' filecache rows');
+ $output->writeln('Added ' . $totalNewMimetypes . ' new mimetypes');
+ $output->writeln('Updated ' . $totalFilecacheUpdates . ' filecache rows');
return 0;
}
}
diff --git a/core/Command/Maintenance/Mimetype/UpdateJS.php b/core/Command/Maintenance/Mimetype/UpdateJS.php
index a1559024f2e..2132ff54c6d 100644
--- a/core/Command/Maintenance/Mimetype/UpdateJS.php
+++ b/core/Command/Maintenance/Mimetype/UpdateJS.php
@@ -32,7 +32,8 @@ class UpdateJS extends Command {
// Output the JS
$generatedMimetypeFile = new GenerateMimetypeFileBuilder();
- file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases));
+ $namings = $this->mimetypeDetector->getAllNamings();
+ file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases, $namings));
$output->writeln('<info>mimetypelist.js is updated');
return 0;
diff --git a/core/Command/Maintenance/Mode.php b/core/Command/Maintenance/Mode.php
index 5e706d88ed8..853e843f57b 100644
--- a/core/Command/Maintenance/Mode.php
+++ b/core/Command/Maintenance/Mode.php
@@ -24,7 +24,8 @@ class Mode extends Command {
protected function configure() {
$this
->setName('maintenance:mode')
- ->setDescription('set maintenance mode')
+ ->setDescription('Show or toggle maintenance mode status')
+ ->setHelp('Maintenance mode prevents new logins, locks existing sessions, and disables background jobs.')
->addOption(
'on',
null,
diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php
index 09d75cec45c..f0c88f6811b 100644
--- a/core/Command/Maintenance/Repair.php
+++ b/core/Command/Maintenance/Repair.php
@@ -61,7 +61,7 @@ class Repair extends Command {
$this->repair->addStep($step);
}
- $apps = $this->appManager->getInstalledApps();
+ $apps = $this->appManager->getEnabledApps();
foreach ($apps as $app) {
if (!$this->appManager->isEnabledForUser($app)) {
continue;
@@ -70,7 +70,7 @@ class Repair extends Command {
if (!is_array($info)) {
continue;
}
- \OC_App::loadApp($app);
+ $this->appManager->loadApp($app);
$steps = $info['repair-steps']['post-migration'];
foreach ($steps as $step) {
try {
diff --git a/core/Command/Maintenance/RepairShareOwnership.php b/core/Command/Maintenance/RepairShareOwnership.php
index 56a95b68ed7..16675545afe 100644
--- a/core/Command/Maintenance/RepairShareOwnership.php
+++ b/core/Command/Maintenance/RepairShareOwnership.php
@@ -14,6 +14,7 @@ use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -33,7 +34,7 @@ class RepairShareOwnership extends Command {
->setName('maintenance:repair-share-owner')
->setDescription('repair invalid share-owner entries in the database')
->addOption('no-confirm', 'y', InputOption::VALUE_NONE, "Don't ask for confirmation before repairing the shares")
- ->addArgument('user', InputArgument::OPTIONAL, "User to fix incoming shares for, if omitted all users will be fixed");
+ ->addArgument('user', InputArgument::OPTIONAL, 'User to fix incoming shares for, if omitted all users will be fixed');
}
protected function execute(InputInterface $input, OutputInterface $output): int {
@@ -51,15 +52,16 @@ class RepairShareOwnership extends Command {
}
if ($shares) {
- $output->writeln("");
- $output->writeln("Found " . count($shares) . " shares with invalid share owner");
+ $output->writeln('');
+ $output->writeln('Found ' . count($shares) . ' shares with invalid share owner');
foreach ($shares as $share) {
/** @var array{shareId: int, fileTarget: string, initiator: string, receiver: string, owner: string, mountOwner: string} $share */
$output->writeln(" - share {$share['shareId']} from \"{$share['initiator']}\" to \"{$share['receiver']}\" at \"{$share['fileTarget']}\", owned by \"{$share['owner']}\", that should be owned by \"{$share['mountOwner']}\"");
}
- $output->writeln("");
+ $output->writeln('');
if (!$noConfirm) {
+ /** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Repair these shares? [y/N]', false);
@@ -67,10 +69,10 @@ class RepairShareOwnership extends Command {
return 0;
}
}
- $output->writeln("Repairing " . count($shares) . " shares");
+ $output->writeln('Repairing ' . count($shares) . ' shares');
$this->repairShares($shares);
} else {
- $output->writeln("Found no shares with invalid share owner");
+ $output->writeln('Found no shares with invalid share owner');
}
return 0;
@@ -85,7 +87,7 @@ class RepairShareOwnership extends Command {
$brokenShares = $qb
->select('s.id', 'm.user_id', 's.uid_owner', 's.uid_initiator', 's.share_with', 's.file_target')
->from('share', 's')
- ->join('s', 'filecache', 'f', $qb->expr()->eq('s.item_source', $qb->expr()->castColumn('f.fileid', IQueryBuilder::PARAM_STR)))
+ ->join('s', 'filecache', 'f', $qb->expr()->eq($qb->expr()->castColumn('s.item_source', IQueryBuilder::PARAM_INT), 'f.fileid'))
->join('s', 'mounts', 'm', $qb->expr()->eq('f.storage', 'm.storage_id'))
->where($qb->expr()->neq('m.user_id', 's.uid_owner'))
->andWhere($qb->expr()->eq($qb->func()->concat($qb->expr()->literal('/'), 'm.user_id', $qb->expr()->literal('/')), 'm.mount_point'))
@@ -96,7 +98,7 @@ class RepairShareOwnership extends Command {
foreach ($brokenShares as $share) {
$found[] = [
- 'shareId' => (int) $share['id'],
+ 'shareId' => (int)$share['id'],
'fileTarget' => $share['file_target'],
'initiator' => $share['uid_initiator'],
'receiver' => $share['share_with'],
@@ -130,7 +132,7 @@ class RepairShareOwnership extends Command {
foreach ($brokenShares as $share) {
$found[] = [
- 'shareId' => (int) $share['id'],
+ 'shareId' => (int)$share['id'],
'fileTarget' => $share['file_target'],
'initiator' => $share['uid_initiator'],
'receiver' => $share['share_with'],
diff --git a/core/Command/Maintenance/UpdateHtaccess.php b/core/Command/Maintenance/UpdateHtaccess.php
index 4939e368e2d..eeff3bf8c62 100644
--- a/core/Command/Maintenance/UpdateHtaccess.php
+++ b/core/Command/Maintenance/UpdateHtaccess.php
@@ -7,6 +7,7 @@
*/
namespace OC\Core\Command\Maintenance;
+use OC\Setup;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -19,7 +20,7 @@ class UpdateHtaccess extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- if (\OC\Setup::updateHtaccess()) {
+ if (Setup::updateHtaccess()) {
$output->writeln('.htaccess has been updated');
return 0;
} else {
diff --git a/core/Command/Maintenance/UpdateTheme.php b/core/Command/Maintenance/UpdateTheme.php
index f819b9c8e58..3fbcb546cca 100644
--- a/core/Command/Maintenance/UpdateTheme.php
+++ b/core/Command/Maintenance/UpdateTheme.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later