Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@
'OCP\\Collaboration\\Resources\\LoadAdditionalScriptsEvent' => $baseDir . '/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php',
'OCP\\Collaboration\\Resources\\ResourceException' => $baseDir . '/lib/public/Collaboration/Resources/ResourceException.php',
'OCP\\Color' => $baseDir . '/lib/public/Color.php',
'OCP\\Command\\Events\\BeforeCommandExecutedEvent' => $baseDir . '/lib/public/Command/Events/BeforeCommandExecutedEvent.php',
'OCP\\Command\\Events\\CommandExecutedEvent' => $baseDir . '/lib/public/Command/Events/CommandExecutedEvent.php',
'OCP\\Command\\IBus' => $baseDir . '/lib/public/Command/IBus.php',
'OCP\\Command\\ICommand' => $baseDir . '/lib/public/Command/ICommand.php',
'OCP\\Comments\\CommentsEntityEvent' => $baseDir . '/lib/public/Comments/CommentsEntityEvent.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Collaboration\\Resources\\LoadAdditionalScriptsEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php',
'OCP\\Collaboration\\Resources\\ResourceException' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/ResourceException.php',
'OCP\\Color' => __DIR__ . '/../../..' . '/lib/public/Color.php',
'OCP\\Command\\Events\\BeforeCommandExecutedEvent' => __DIR__ . '/../../..' . '/lib/public/Command/Events/BeforeCommandExecutedEvent.php',
'OCP\\Command\\Events\\CommandExecutedEvent' => __DIR__ . '/../../..' . '/lib/public/Command/Events/CommandExecutedEvent.php',
'OCP\\Command\\IBus' => __DIR__ . '/../../..' . '/lib/public/Command/IBus.php',
'OCP\\Command\\ICommand' => __DIR__ . '/../../..' . '/lib/public/Command/ICommand.php',
'OCP\\Comments\\CommentsEntityEvent' => __DIR__ . '/../../..' . '/lib/public/Comments/CommentsEntityEvent.php',
Expand Down
52 changes: 51 additions & 1 deletion lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
namespace OC\Console;

use ArgumentCountError;
use OC\EventDispatcher\EventDispatcher;
use OC\MemoryInfo;
use OC\NeedsUpdateException;
use OC\SystemConfig;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\Command\Events\BeforeCommandExecutedEvent;
use OCP\Command\Events\CommandExecutedEvent;
use OCP\Command\Events\CommandFailedEvent;
use OCP\Console\ConsoleEvent;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
Expand All @@ -23,25 +27,71 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Application {
private IEventDispatcher $dispatcher;
private SymfonyApplication $application;

public function __construct(
ServerVersion $serverVersion,
private IConfig $config,
private IEventDispatcher $dispatcher,
EventDispatcher $dispatcher,
private IRequest $request,
private LoggerInterface $logger,
private MemoryInfo $memoryInfo,
private IAppManager $appManager,
private Defaults $defaults,
) {
$this->dispatcher = $dispatcher;
$this->application = new SymfonyApplication($defaults->getName(), $serverVersion->getVersionString());
$symfonyDispatcher = $dispatcher->getSymfonyDispatcher();
$symfonyDispatcher->addListener(\Symfony\Component\Console\ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) use ($dispatcher) {
$command = $event->getCommand();
$name = $command?->getName();
if ($name === null) {
// Ignore unnamed events
return;
}
$dispatcher->dispatchTyped(
new BeforeCommandExecutedEvent(

Check failure on line 63 in lib/private/Console/Application.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InternalMethod

lib/private/Console/Application.php:63:5: InternalMethod: Constructor OCP\Command\Events\BeforeCommandExecutedEvent::__construct is internal to OCP but called from OC\Console (see https://psalm.dev/175)
$name,
)
);
});
$symfonyDispatcher->addListener(\Symfony\Component\Console\ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) use ($dispatcher) {
$command = $event->getCommand();
$name = $command?->getName();
if ($name === null) {
// Ignore unnamed events
return;
}
$dispatcher->dispatchTyped(
new CommandExecutedEvent(

Check failure on line 76 in lib/private/Console/Application.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InternalMethod

lib/private/Console/Application.php:76:5: InternalMethod: Constructor OCP\Command\Events\CommandExecutedEvent::__construct is internal to OCP but called from OC\Console (see https://psalm.dev/175)
$name,
)
);
});
$symfonyDispatcher->addListener(\Symfony\Component\Console\ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($dispatcher) {
$command = $event->getCommand();
$name = $command?->getName();
if ($name === null) {
// Ignore unnamed events
return;
}
$dispatcher->dispatchTyped(
new CommandFailedEvent(

Check failure on line 89 in lib/private/Console/Application.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InternalMethod

lib/private/Console/Application.php:89:5: InternalMethod: Constructor OCP\Command\Events\CommandFailedEvent::__construct is internal to OCP but called from OC\Console (see https://psalm.dev/175)
$name,
)
);
});
$this->application->setDispatcher($symfonyDispatcher);
}

/**
Expand Down
37 changes: 37 additions & 0 deletions lib/public/Command/Events/BeforeCommandExecutedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCP\Command\Events;

use OCP\EventDispatcher\Event;

/**
* Dispatched before an occ command is executed
*
* @since 32.0.0
*/
class BeforeCommandExecutedEvent extends Event {
/**
* @since 32.0.0
* @internal instances are created by Nextcloud server
*/
public function __construct(
private string $command,
) {
parent::__construct();
}

/**
* @since 32.0.0
*/
public function getCommand(): string {
return $this->command;
}

}
37 changes: 37 additions & 0 deletions lib/public/Command/Events/CommandExecutedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCP\Command\Events;

use OCP\EventDispatcher\Event;

/**
* Dispatched after an occ command is executed
*
* @since 32.0.0
*/
class CommandExecutedEvent extends Event {
/**
* @since 32.0.0
* @internal instances are created by Nextcloud server
*/
public function __construct(
private string $command,
) {
parent::__construct();
}

/**
* @since 32.0.0
*/
public function getCommand(): string {
return $this->command;
}

}
37 changes: 37 additions & 0 deletions lib/public/Command/Events/CommandFailedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCP\Command\Events;

use OCP\EventDispatcher\Event;

/**
* Dispatched when an occ command failed
*
* @since 32.0.0
*/
class CommandFailedEvent extends Event {
/**
* @since 32.0.0
* @internal instances are created by Nextcloud server
*/
public function __construct(
private string $command,
) {
parent::__construct();
}

/**
* @since 32.0.0
*/
public function getCommand(): string {
return $this->command;
}

}
Loading