{"id":380,"date":"2024-12-03T17:15:42","date_gmt":"2024-12-03T16:15:42","guid":{"rendered":"https:\/\/www.richard-becker.net\/blog\/?p=380"},"modified":"2024-12-03T17:15:42","modified_gmt":"2024-12-03T16:15:42","slug":"occ-web-mit-nextcloud-30-0-2-nutzen","status":"publish","type":"post","link":"https:\/\/www.richard-becker.net\/blog\/2024\/12\/03\/occ-web-mit-nextcloud-30-0-2-nutzen\/","title":{"rendered":"OCC Web mit Nextcloud 30.0.2 nutzen"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Wie man <a href=\"https:\/\/help.nextcloud.com\/t\/occ-web-doesnt-work-in-nextcloud-30-0-0\/206139\" data-type=\"link\" data-id=\"https:\/\/help.nextcloud.com\/t\/occ-web-doesnt-work-in-nextcloud-30-0-0\/206139\" target=\"_blank\" rel=\"noreferrer noopener\">diesem Forenbeitrag<\/a> entnehmen kann, funktioniert <a href=\"https:\/\/apps.nextcloud.com\/apps\/occweb\" data-type=\"link\" data-id=\"https:\/\/apps.nextcloud.com\/apps\/occweb\" target=\"_blank\" rel=\"noreferrer noopener\">OCC Web<\/a> nicht unter Nextcloud 30. Dort wird zwar ein L\u00f6sungsvorschlag angeboten, dieser reicht allein aber nicht aus, um OCC Web unter Nextcloud 30.0.2 zum Laufen zu bringen. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Der L\u00f6sungsvorschlag des Nutzers &#8222;Gerald1969&#8220; aus dem oben genannten Forenbeitrag erl\u00e4utert, dass man die Datei <code>apps\/occweb\/lib\/Controller\/OccController.php<\/code> durch folgenden Inhalt ersetzen muss:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace OCA\\OCCWeb\\Controller;\n\nuse Exception;\nuse OC;\nuse OC\\Console\\Application;\nuse OC\\MemoryInfo;\nuse OCP\\IRequest;\nuse OCP\\AppFramework\\Http\\TemplateResponse;\nuse OCP\\AppFramework\\Http\\DataResponse;\nuse OCP\\AppFramework\\Controller;\nuse OCP\\ILogger;\nuse Symfony\\Component\\Console\\Input\\StringInput;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\nuse Psr\\Log\\LoggerInterface;\n\nclass OccController extends Controller\n{\n  private $logger;\n  private $userId;\n\n  private $application;\n  private $symphonyApplication;\n  private $output;\n\n  public function __construct(ILogger $logger, $AppName, IRequest $request, $userId)\n  {\n    parent::__construct($AppName, $request);\n    $this->logger = $logger;\n    $this->userId = $userId;\n\n    \/\/ Obtendo o IAppManager como sexto argumento\n    $this->application = new Application(\n      OC::$server->getConfig(),\n      OC::$server->get(\\OCP\\EventDispatcher\\IEventDispatcher::class),\n      new FakeRequest(),\n      OC::$server->get(LoggerInterface::class),\n      OC::$server->query(MemoryInfo::class),\n      OC::$server->get(\\OCP\\App\\IAppManager::class) \/\/ addition for NC30\n    );\n    \n    $this->application->setAutoExit(false);\n    $this->output = new OccOutput(OutputInterface::VERBOSITY_NORMAL, true);\n    $this->application->loadCommands(new StringInput(\"\"), $this->output);    \n\n    $reflectionProperty = new \\ReflectionProperty(Application::class, 'application');\n    $reflectionProperty->setAccessible(true);\n    $this->symphonyApplication = $reflectionProperty->getValue($this->application);\n  }\n\n  \/**\n   * @NoCSRFRequired\n   *\/\n  public function index()\n  {\n    return new TemplateResponse('occweb', 'index');\n  }\n\n  \/**\n   * @param $input\n   * @return string\n   *\/\n  private function run($input)\n  {\n    try {\n      $this->application->run($input, $this->output);\n      return $this->output->fetch();\n    } catch (Exception $ex) {\n      $this->logger->logException($ex);\n      return \"error: \" . $ex->getMessage();\n    }\n  }\n\n  \/**\n   * @param string $command\n   * @return DataResponse\n   *\/\n  public function cmd($command)\n  {\n    $this->logger->debug($command);\n    $input = new StringInput($command);\n    $response = $this->run($input);\n    $this->logger->debug($response);\n    return new DataResponse($response);\n  }\n\n  public function list() {\n    $defs = $this->symphonyApplication->all();\n    $cmds = array();\n    foreach ($defs as $d) {\n      array_push($cmds, $d->getName());\n    }\n    return new DataResponse($cmds);\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Bei mir folgte daraufhin ein <code>Internal Server Error (500)<\/code> sodass ich noch einmal tiefer in die Logs schauen musste. Ein Kompatibilit\u00e4tsproblem mit <code>Symfony\\Component\\Console\\Output\\ConsoleOutputInterface<\/code> verhindert, dass die App korrekt l\u00e4uft.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ersetzt man nun noch den Inhalt der Datei <code><code>apps\/occweb\/lib\/Controller\/OccOutput.php<\/code><\/code> mit folgendem Code, funktioniert OCC Web wieder &#8211; auch unter Nextcloud 30.0.2. Zumindest ist dies bei meiner Installation der Fall.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace OCA\\OCCWeb\\Controller;\n\nuse Symfony\\Component\\Console\\Output\\BufferedOutput;\nuse Symfony\\Component\\Console\\Output\\ConsoleOutputInterface;\nuse Symfony\\Component\\Console\\Output\\ConsoleSectionOutput;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\nclass OccOutput extends BufferedOutput implements ConsoleOutputInterface\n{\n    private $consoleSectionOutputs = &#91;];\n    private $errorOutput;\n    private $stream;\n\n    public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)\n    {\n        parent::__construct($verbosity, $decorated, $formatter);\n        \/\/ Initialize error output to avoid null references\n        $this->errorOutput = new BufferedOutput($verbosity, $decorated, $formatter);\n    }\n\n    \/**\n     * Gets the OutputInterface for errors.\n     *\n     * @return OutputInterface\n     *\/\n    public function getErrorOutput(): OutputInterface\n    {\n        return $this->errorOutput;\n    }\n\n    \/**\n     * Sets the OutputInterface for errors.\n     *\n     * @param OutputInterface $error\n     *\/\n    public function setErrorOutput(OutputInterface $error): void\n    {\n        $this->errorOutput = $error;\n    }\n\n    \/**\n     * Creates a new output section.\n     *\/\n    public function section(): ConsoleSectionOutput\n    {\n        if ($this->stream === null) {\n            $this->stream = fopen('php:\/\/temp', 'w');\n        }\n        return new ConsoleSectionOutput($this->stream, $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter());\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie man diesem Forenbeitrag entnehmen kann, funktioniert OCC Web nicht unter Nextcloud 30. Dort wird&hellip; <a class=\"read-more-link\" href=\"https:\/\/www.richard-becker.net\/blog\/2024\/12\/03\/occ-web-mit-nextcloud-30-0-2-nutzen\/\">[Weiterlesen]<\/a><\/p>\n","protected":false},"author":2,"featured_media":382,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[70,72,7],"class_list":["post-380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technologie","tag-nextcloud","tag-patch","tag-technologie"],"_links":{"self":[{"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/comments?post=380"}],"version-history":[{"count":1,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":381,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions\/381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/media\/382"}],"wp:attachment":[{"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/media?parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/categories?post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richard-becker.net\/blog\/wp-json\/wp\/v2\/tags?post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}