OCC Web doesn't work in Nextcloud 30.0.0

Hello,

I have
Nextcloud version 30.0.0
Operating system and version Ubuntu 20.04.6 LTS
Apache or nginx version Apache 2.4.25
PHP version 8.1

Nextcloud 30.0.0 running but OccWeb 0.2.0 gives Internal Error…here the error log:

{"reqId":"xxx","level":3,"time":"2024-10-06T11:08:29+00:00","remoteAddr":"xxx",
"user":"admin","app":"index","method":"GET","url":"/index.php/apps/occweb/","message":"Too few arguments to function OC\\Console\\Application::__construct(), 5 passed in
/var/www/vhosts/mydomaine/nextcloud.mydomaine/apps/occweb/lib/Controller/OccController.php on line 38 and exactly 6 expected",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36","version":"30.0.0.14","exception":
{"Exception":"ArgumentCountError","Message":"Too few arguments to function 
OC\\Console\\Application::__construct(), 5 passed in 
/var/www/vhosts/mydomaine/nextcloud.mydomaine/apps/occweb/lib/Controller/OccController.php
 on line 38 and exactly 6 expected","Code":0,"Trace":[{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/apps/occweb/lib/Controller/OccController.php","line":38,"function":"__construct","class":
"OC\\Console\\Application","type":"->"},{"function":"__construct","class":"OCA\\OCCWeb\\Controller\\OccController","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/Utility/SimpleContainer.php",
"line":98,"function":"newInstanceArgs","class":"ReflectionClass","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/Utility/SimpleContainer.php",
"line":106,"function":"buildClass","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/Utility/SimpleContainer.php",
"line":124,"function":"resolve","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/DependencyInjection/DIContainer.php","line":448,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->"},{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/DependencyInjection/DIContainer.php","line":420,"function":"queryNoFallback","class":"OC\\AppFramework\\DependencyInjection\\DIContainer","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/AppFramework/App.php","line":140,"function":"query","class":"OC\\AppFramework\\DependencyInjection\\DIContainer","type":"->"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},
{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/base.php","line":1001,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/index.php","line":24,"function":"handleRequest",
"class":"OC","type":"::"}],"File":"/var/www/vhosts/mydomaine/nextcloud.mydomaine/lib/private/Console/Application.php","Line":29,"message":"Too few arguments to function OC\\Console\\Application::__construct(), 5 passed in /var/www/vhosts/mydomaine/nextcloud.mydomaine/apps/occweb/lib/Controller/OccController.php on line 38 and exactly 6 expected","exception":[],"CustomMessage":"Too few 
arguments to function OC\\Console\\Application::__construct(), 5 passed in 
/var/www/vhosts/mydomaine/nextcloud.mydomaine/apps/occweb/lib/Controller/OccController.php on line 38 and exactly 6 expected"},"id":"67026fb7cdefc"}

has anybody a hint ?

I found this

For version 30 change apps/occweb/lib/ControllerOccController.php with the following code

<?php

namespace OCA\OCCWeb\Controller;

use Exception;
use OC;
use OC\Console\Application;
use OC\MemoryInfo;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\ILogger;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Psr\Log\LoggerInterface;

class OccController extends Controller
{
  private $logger;
  private $userId;

  private $application;
  private $symphonyApplication;
  private $output;

  public function __construct(ILogger $logger, $AppName, IRequest $request, $userId)
  {
    parent::__construct($AppName, $request);
    $this->logger = $logger;
    $this->userId = $userId;

    // Obtendo o IAppManager como sexto argumento
    $this->application = new Application(
      OC::$server->getConfig(),
      OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
      new FakeRequest(),
      OC::$server->get(LoggerInterface::class),
      OC::$server->query(MemoryInfo::class),
      OC::$server->get(\OCP\App\IAppManager::class) // Obtenção do IAppManager
    );
    
    $this->application->setAutoExit(false);
    $this->output = new OccOutput(OutputInterface::VERBOSITY_NORMAL, true);
    $this->application->loadCommands(new StringInput(""), $this->output);    

    $reflectionProperty = new \ReflectionProperty(Application::class, 'application');
    $reflectionProperty->setAccessible(true);
    $this->symphonyApplication = $reflectionProperty->getValue($this->application);
  }

  /**
   * @NoCSRFRequired
   */
  public function index()
  {
    return new TemplateResponse('occweb', 'index');
  }

  /**
   * @param $input
   * @return string
   */
  private function run($input)
  {
    try {
      $this->application->run($input, $this->output);
      return $this->output->fetch();
    } catch (Exception $ex) {
      $this->logger->logException($ex);
      return "error: " . $ex->getMessage();
    }
  }

  /**
   * @param string $command
   * @return DataResponse
   */
  public function cmd($command)
  {
    $this->logger->debug($command);
    $input = new StringInput($command);
    $response = $this->run($input);
    $this->logger->debug($response);
    return new DataResponse($response);
  }

  public function list() {
    $defs = $this->symphonyApplication->all();
    $cmds = array();
    foreach ($defs as $d) {
      array_push($cmds, $d->getName());
    }
    return new DataResponse($cmds);
  }
}

and its works…

3 Likes

Thanks! That works for me

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.