From a7eedf014933277ff392824e1a6e62b041da58f8 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 3 Feb 2015 00:39:01 +0100 Subject: [PATCH 1/2] Disallow disabling of files app --- core/command/app/disable.php | 8 ++++++-- lib/private/app.php | 3 +++ lib/private/app/appmanager.php | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/command/app/disable.php b/core/command/app/disable.php index dcdee92349..2e028d183b 100644 --- a/core/command/app/disable.php +++ b/core/command/app/disable.php @@ -28,8 +28,12 @@ class Disable extends Command { protected function execute(InputInterface $input, OutputInterface $output) { $appId = $input->getArgument('app-id'); if (\OC_App::isEnabled($appId)) { - \OC_App::disable($appId); - $output->writeln($appId . ' disabled'); + try { + \OC_App::disable($appId); + $output->writeln($appId . ' disabled'); + } catch(\Exception $e) { + $output->writeln($e->getMessage()); + } } else { $output->writeln('No such app enabled: ' . $appId); } diff --git a/lib/private/app.php b/lib/private/app.php index 3a1f731d62..aa28e36057 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -321,6 +321,9 @@ class OC_App { * @param string $app app */ public static function disable($app) { + if($app === 'files') { + throw new \Exception("App 'files' can't be disabled."); + } self::$enabledAppsCache = array(); // flush // check if app is a shipped app or not. if not delete \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 6d9aa0bfe3..7527c93dae 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -131,8 +131,12 @@ class AppManager implements IAppManager { * Disable an app for every user * * @param string $appId + * @throws \Exception if app can't be disabled */ public function disableApp($appId) { + if($appId === 'files') { + throw new \Exception("App 'files' can't be disabled."); + } $this->appConfig->setValue($appId, 'enabled', 'no'); } } From d70160c6077ca017d6cb7d61f066fe33e3b1e081 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 3 Feb 2015 00:52:04 +0100 Subject: [PATCH 2/2] enabled disabled files app in repair step --- lib/private/app.php | 2 +- lib/private/app/appmanager.php | 2 +- lib/private/repair.php | 2 ++ lib/repair/enablefilesapp.php | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/repair/enablefilesapp.php diff --git a/lib/private/app.php b/lib/private/app.php index aa28e36057..60b644e58e 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -322,7 +322,7 @@ class OC_App { */ public static function disable($app) { if($app === 'files') { - throw new \Exception("App 'files' can't be disabled."); + throw new \Exception("files can't be disabled."); } self::$enabledAppsCache = array(); // flush // check if app is a shipped app or not. if not delete diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 7527c93dae..20a765e343 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -135,7 +135,7 @@ class AppManager implements IAppManager { */ public function disableApp($appId) { if($appId === 'files') { - throw new \Exception("App 'files' can't be disabled."); + throw new \Exception("files can't be disabled."); } $this->appConfig->setValue($appId, 'enabled', 'no'); } diff --git a/lib/private/repair.php b/lib/private/repair.php index d9fd99707e..c74283896f 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -13,6 +13,7 @@ use OC\Hooks\Emitter; use OC\Repair\AssetCache; use OC\Repair\CleanTags; use OC\Repair\Collation; +use OC\Repair\EnableFilesApp; use OC\Repair\FillETags; use OC\Repair\InnoDB; use OC\Repair\RepairConfig; @@ -84,6 +85,7 @@ class Repair extends BasicEmitter { new AssetCache(), new FillETags(\OC_DB::getConnection()), new CleanTags(\OC_DB::getConnection()), + new EnableFilesApp(\OC::$server->getConfig()), ); } diff --git a/lib/repair/enablefilesapp.php b/lib/repair/enablefilesapp.php new file mode 100644 index 0000000000..a3298cf76b --- /dev/null +++ b/lib/repair/enablefilesapp.php @@ -0,0 +1,50 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Repair; + +use OC\Hooks\BasicEmitter; +use OC\RepairStep; +use OCP\IConfig; + +/** + * Class EnableFilesApp - enables files app if disabled + * + * TODO: remove this with ownCloud 8.1 - this isn't possible anymore with 8.0 + * + * @package OC\Repair + */ +class EnableFilesApp extends BasicEmitter implements RepairStep { + + /** @var IConfig */ + protected $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return string + */ + public function getName() { + return 'Re-enable file app'; + } + + /** + * Enables the files app if it is disabled + */ + public function run() { + if ($this->config->getAppValue('files', 'enabled', 'no') !== 'yes') { + $this->config->setAppValue('files', 'enabled', 'yes'); + $this->emit('\OC\Repair', 'info', ['Files app was disabled - re-enabled']); + } + } +}