aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Services/IInitialState.php
blob: 1a597567e192a9218be1eb9d502352c98f6763ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

declare(strict_types=1);

/**
 * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
 *
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * 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
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
namespace OCP\AppFramework\Services;

use Closure;

/**
 * @since 20.0.0
 */
interface IInitialState {
	/**
	 * Allows an app to provide its initial state to the template system.
	 * Use this if you know your initial state sill be used for example if
	 * you are in the render function of you controller.
	 *
	 * @since 20.0.0
	 *
	 * @param string $key
	 * @param bool|int|float|string|array|\JsonSerializable $data
	 */
	public function provideInitialState(string $key, $data): void;

	/**
	 * Allows an app to provide its initial state via a lazy method.
	 * This will call the closure when the template is being generated.
	 * Use this if your app is injected into pages. Since then the render method
	 * is not called explicitly. But we do not want to load the state on webdav
	 * requests for example.
	 *
	 * @since 20.0.0
	 *
	 * @param string $key
	 * @param Closure $closure returns a primitive or an object that implements JsonSerializable
	 * @psalm-param Closure():bool|Closure():int|Closure():float|Closure():string|Closure():\JsonSerializable $closure
	 */
	public function provideLazyInitialState(string $key, Closure $closure): void;
}
p">); $this->appManager->disableApp('files_trashbin'); } /** * Reset the maintenance mode and re-enable the trashbin app */ protected function resetMaintenanceAndTrashbin(): void { $this->config->setSystemValue('maintenance', false); if ($this->wasTrashbinEnabled) { $this->appManager->enableApp('files_trashbin'); } } protected function configure() { parent::configure(); $this->setName('encryption:encrypt-all'); $this->setDescription('Encrypt all files for all users'); $this->setHelp( 'This will encrypt all files for all users. ' . 'Please make sure that no user access his files during this process!' ); } protected function execute(InputInterface $input, OutputInterface $output): int { if (!$input->isInteractive()) { $output->writeln('Invalid TTY.'); $output->writeln('If you are trying to execute the command in a Docker '); $output->writeln("container, do not forget to execute 'docker exec' with"); $output->writeln("the '-i' and '-t' options."); $output->writeln(''); return 1; } if ($this->encryptionManager->isEnabled() === false) { throw new \Exception('Server side encryption is not enabled'); } if ($this->config->getSystemValueBool('maintenance')) { $output->writeln('<error>This command cannot be run with maintenance mode enabled.</error>'); return self::FAILURE; } $output->writeln("\n"); $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); $output->writeln('Please ensure that no user accesses their files during this time!'); $output->writeln('Note: The encryption module you use determines which files get encrypted.'); $output->writeln(''); $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); if ($this->questionHelper->ask($input, $output, $question)) { $this->forceMaintenanceAndTrashbin(); try { $defaultModule = $this->encryptionManager->getEncryptionModule(); $defaultModule->encryptAll($input, $output); } catch (\Exception $ex) { $this->resetMaintenanceAndTrashbin(); throw $ex; } $this->resetMaintenanceAndTrashbin(); return self::SUCCESS; } $output->writeln('aborted'); return self::FAILURE; } }