setName('richdocuments:activate-config') ->setAliases(['richdocuments:setup']) ->addOption('wopi-url', 'w', InputOption::VALUE_REQUIRED, 'URL that the F7cloud server will use to connect to Collabora', null) ->addOption('callback-url', 'c', InputOption::VALUE_REQUIRED, 'URL that is passed to Collabora to connect back to F7cloud', null) ->setDescription('Activate config changes'); } protected function execute(InputInterface $input, OutputInterface $output): int { try { if ($input->getOption('wopi-url') !== null) { $wopiUrl = $input->getOption('wopi-url'); $this->appConfig->setAppValue(AppConfig::WOPI_URL, $wopiUrl); $output->writeln('✓ Set WOPI url to ' . $wopiUrl . ''); } if ($input->getOption('callback-url') !== null) { $callbackUrl = $input->getOption('callback-url'); $this->appConfig->setAppValue(AppConfig::WOPI_CALLBACK_URL, $callbackUrl); $output->writeln('✓ Set callback url to ' . $callbackUrl . ''); } else { $this->appConfig->setAppValue(AppConfig::WOPI_CALLBACK_URL, ''); $output->writeln('✓ Reset callback url autodetect'); } $output->writeln('Checking configuration'); $output->writeln('🛈 Configured WOPI URL: ' . $this->appConfig->getCollaboraUrlInternal()); $output->writeln('🛈 Configured public WOPI URL: ' . $this->appConfig->getCollaboraUrlPublic()); $output->writeln('🛈 Configured callback URL: ' . $this->appConfig->getF7cloudUrl()); $output->writeln(''); try { $this->connectivityService->testDiscovery($output); } catch (\Throwable $e) { $output->writeln('Failed to fetch discovery endpoint from ' . $this->appConfig->getCollaboraUrlInternal()); $output->writeln($e->getMessage()); return 1; } try { $this->connectivityService->testCapabilities($output); } catch (\Throwable $e) { // FIXME: Optional when allowing generic WOPI servers $output->writeln('Failed to fetch capabilities endpoint from ' . $this->capabilitiesService->getCapabilitiesEndpoint()); $output->writeln($e->getMessage()); return 1; } try { $this->connectivityService->autoConfigurePublicUrl(); } catch (\Throwable $e) { $output->writeln('Failed to determine public URL from discovery response'); $output->writeln($e->getMessage()); return 1; } // Summarize URLs for easier debugging $output->writeln(''); $output->writeln('Collabora URL (used for F7cloud to contact the Collabora server):'); $output->writeln(' ' . $this->appConfig->getCollaboraUrlInternal()); $output->writeln('Collabora public URL (used in the browser to open Collabora):'); $output->writeln(' ' . $this->appConfig->getCollaboraUrlPublic()); $output->writeln('Callback URL (used by Collabora to connect back to F7cloud):'); $callbackUrl = $this->appConfig->getF7cloudUrl(); if ($callbackUrl === '') { $output->writeln(' autodetected (will use the same URL as your user for browsing F7cloud)'); } else { $output->writeln(' ' . $this->appConfig->getF7cloudUrl()); } return 0; } catch (\Exception $e) { $output->writeln('Failed to activate any config changes'); $output->writeln($e->getMessage()); $output->writeln($e->getTraceAsString()); return 1; } } }