From cb96ad95c42fe6bcb62fd5758ad29f10678a7a63 Mon Sep 17 00:00:00 2001 From: Sergey Mosin Date: Fri, 30 Jun 2023 21:46:21 -0400 Subject: [PATCH] nextcloud: add ability to include custom php file in InstallStep migration --- .../snappymail/lib/Migration/InstallStep.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php index 7e0332dabb..c3b59a969b 100644 --- a/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php +++ b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php @@ -2,6 +2,8 @@ // https://docs.nextcloud.com/server/19/developer_manual/app/repair.html namespace OCA\SnappyMail\Migration; +use OCA\SnappyMail\AppInfo\Application; +use OCP\IConfig; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use OCP\ILogger; @@ -88,5 +90,22 @@ public function run(IOutput $output) { } $bSave && $oConfig->Save(); + + // check if admins provided additional/custom initial config file + // https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#setting-a-single-configuration-value + // ex: php occ config:app:set snappymail custom_config_file --value="/path/to/config.php" + try { + /** @var IConfig $ncConfig */ + $ncConfig = \OC::$server->get(IConfig::class); + $customConfigFile = $ncConfig->getAppValue(Application::APP_ID, 'custom_config_file'); + if ($customConfigFile && strpos($customConfigFile, ':') === false) { + include $customConfigFile; + } + } catch (\Throwable $e) { + $output->warning("custom config error: " . $e->getMessage()); + /** @var \Psr\Log\LoggerInterface $logger */ + $logger = \OC::$server->get(\Psr\Log\LoggerInterface::class); + $logger->error("custom config error: " . $e->getMessage()); + } } }