Skip to content
Merged
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
34 changes: 26 additions & 8 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,9 @@
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
</DeprecatedClass>
<DeprecatedInterface>
<code><![CDATA[Expire]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
Expand Down Expand Up @@ -1826,6 +1829,9 @@
</DeprecatedMethod>
</file>
<file src="apps/files_trashbin/lib/Command/Size.php">
<DeprecatedInterface>
<code><![CDATA[private]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[setAppValue]]></code>
Expand Down Expand Up @@ -2046,6 +2052,11 @@
<code><![CDATA[\OC_Util::tearDownFS()]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_versions/lib/Command/Expire.php">
<DeprecatedInterface>
<code><![CDATA[Expire]]></code>
</DeprecatedInterface>
</file>
<file src="apps/files_versions/lib/Command/ExpireVersions.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::setupFS($user)]]></code>
Expand Down Expand Up @@ -2095,6 +2106,9 @@
<code><![CDATA[Files::streamCopy($source, $target, true)]]></code>
<code><![CDATA[\OC_Util::setupFS($uid)]]></code>
</DeprecatedClass>
<DeprecatedInterface>
<code><![CDATA[$bus]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[Files::streamCopy($source, $target, true)]]></code>
<code><![CDATA[dispatch]]></code>
Expand Down Expand Up @@ -3468,15 +3482,19 @@
}, $context->getCalendarProviders())]]></code>
</NamedArgumentNotAllowed>
</file>
<file src="lib/private/Command/CallableJob.php">
<ParamNameMismatch>
<code><![CDATA[$serializedCallable]]></code>
</ParamNameMismatch>
<file src="lib/private/Command/CommandJob.php">
<UndefinedClass>
<code><![CDATA[\Test\Command\FilesystemCommand]]></code>
<code><![CDATA[\Test\Command\SimpleCommand]]></code>
<code><![CDATA[\Test\Command\StateFullCommand]]></code>
</UndefinedClass>
</file>
<file src="lib/private/Command/ClosureJob.php">
<InvalidArgument>
<code><![CDATA[[LaravelClosure::class]]]></code>
</InvalidArgument>
<file src="lib/private/Command/QueueBus.php">
<UndefinedClass>
<code><![CDATA[\Test\Command\FilesystemCommand]]></code>
<code><![CDATA[\Test\Command\SimpleCommand]]></code>
<code><![CDATA[\Test\Command\StateFullCommand]]></code>
</UndefinedClass>
</file>
<file src="lib/private/Comments/Manager.php">
<RedundantCast>
Expand Down
2 changes: 0 additions & 2 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,6 @@
'OC\\Collaboration\\Resources\\Resource' => $baseDir . '/lib/private/Collaboration/Resources/Resource.php',
'OC\\Color' => $baseDir . '/lib/private/Color.php',
'OC\\Command\\AsyncBus' => $baseDir . '/lib/private/Command/AsyncBus.php',
'OC\\Command\\CallableJob' => $baseDir . '/lib/private/Command/CallableJob.php',
'OC\\Command\\ClosureJob' => $baseDir . '/lib/private/Command/ClosureJob.php',
'OC\\Command\\CommandJob' => $baseDir . '/lib/private/Command/CommandJob.php',
'OC\\Command\\CronBus' => $baseDir . '/lib/private/Command/CronBus.php',
'OC\\Command\\FileAccess' => $baseDir . '/lib/private/Command/FileAccess.php',
Expand Down
2 changes: 0 additions & 2 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Collaboration\\Resources\\Resource' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Resource.php',
'OC\\Color' => __DIR__ . '/../../..' . '/lib/private/Color.php',
'OC\\Command\\AsyncBus' => __DIR__ . '/../../..' . '/lib/private/Command/AsyncBus.php',
'OC\\Command\\CallableJob' => __DIR__ . '/../../..' . '/lib/private/Command/CallableJob.php',
'OC\\Command\\ClosureJob' => __DIR__ . '/../../..' . '/lib/private/Command/ClosureJob.php',
'OC\\Command\\CommandJob' => __DIR__ . '/../../..' . '/lib/private/Command/CommandJob.php',
'OC\\Command\\CronBus' => __DIR__ . '/../../..' . '/lib/private/Command/CronBus.php',
'OC\\Command\\FileAccess' => __DIR__ . '/../../..' . '/lib/private/Command/FileAccess.php',
Expand Down
39 changes: 12 additions & 27 deletions lib/private/Command/AsyncBus.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -19,14 +21,12 @@ abstract class AsyncBus implements IBus {
*
* @var string[]
*/
private $syncTraits = [];
private array $syncTraits = [];

/**
* Schedule a command to be fired
*
* @param \OCP\Command\ICommand | callable $command
*/
public function push($command) {
public function push(ICommand $command): void {
if ($this->canRunAsync($command)) {
$this->queueCommand($command);
} else {
Expand All @@ -36,54 +36,39 @@ public function push($command) {

/**
* Queue a command in the bus
*
* @param \OCP\Command\ICommand | callable $command
*/
abstract protected function queueCommand($command);
abstract protected function queueCommand(ICommand $command);

/**
* Require all commands using a trait to be run synchronous
*
* @param string $trait
*/
public function requireSync($trait) {
public function requireSync(string $trait): void {
$this->syncTraits[] = trim($trait, '\\');
}

/**
* @param \OCP\Command\ICommand | callable $command
*/
private function runCommand($command) {
if ($command instanceof ICommand) {
$command->handle();
} else {
$command();
}
private function runCommand(ICommand $command): void {
$command->handle();
}

/**
* @param \OCP\Command\ICommand | callable $command
* @return bool
*/
private function canRunAsync($command) {
private function canRunAsync(ICommand $command): bool {
$traits = $this->getTraits($command);
foreach ($traits as $trait) {
if (in_array($trait, $this->syncTraits)) {
if (in_array($trait, $this->syncTraits, true)) {
return false;
}
}
return true;
}

/**
* @param \OCP\Command\ICommand | callable $command
* @return string[]
*/
private function getTraits($command) {
if ($command instanceof ICommand) {
return class_uses($command);
} else {
return [];
}
private function getTraits(ICommand $command): array {
return class_uses($command);
}
}
21 changes: 0 additions & 21 deletions lib/private/Command/CallableJob.php

This file was deleted.

23 changes: 0 additions & 23 deletions lib/private/Command/ClosureJob.php

This file was deleted.

8 changes: 7 additions & 1 deletion lib/private/Command/CommandJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
*/
class CommandJob extends QueuedJob {
protected function run($argument) {
$command = unserialize($argument);
$command = unserialize($argument, ['allowed_classes' => [
\Test\Command\SimpleCommand::class,
\Test\Command\StateFullCommand::class,
\Test\Command\FilesystemCommand::class,
\OCA\Files_Trashbin\Command\Expire::class,
\OCA\Files_Versions\Command\Expire::class,
]]);
if ($command instanceof ICommand) {
$command->handle();
} else {
Expand Down
38 changes: 4 additions & 34 deletions lib/private/Command/CronBus.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Command;

use Laravel\SerializableClosure\SerializableClosure;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\Command\ICommand;

Expand All @@ -17,37 +17,7 @@ public function __construct(
) {
}

protected function queueCommand($command): void {
$this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
}

/**
* @param ICommand|callable $command
* @return class-string<IJob>
*/
private function getJobClass($command): string {
if ($command instanceof \Closure) {
return ClosureJob::class;
} elseif (is_callable($command)) {
return CallableJob::class;
} elseif ($command instanceof ICommand) {
return CommandJob::class;
} else {
throw new \InvalidArgumentException('Invalid command');
}
}

/**
* @param ICommand|callable $command
* @return string
*/
private function serializeCommand($command): string {
if ($command instanceof \Closure) {
return serialize(new SerializableClosure($command));
} elseif (is_callable($command) || $command instanceof ICommand) {
return serialize($command);
} else {
throw new \InvalidArgumentException('Invalid command');
}
protected function queueCommand(ICommand $command): void {
$this->jobList->add(CommandJob::class, serialize($command));
}
}
43 changes: 20 additions & 23 deletions lib/private/Command/QueueBus.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -12,45 +14,40 @@

class QueueBus implements IBus {
/**
* @var ICommand[]|callable[]
* @var ICommand[]
*/
private $queue = [];
private array $queue = [];

/**
* Schedule a command to be fired
*
* @param \OCP\Command\ICommand | callable $command
*/
public function push($command) {
public function push(ICommand $command): void {
$this->queue[] = $command;
}

/**
* Require all commands using a trait to be run synchronous
*
* @param string $trait
*/
public function requireSync($trait) {
public function requireSync(string $trait): void {
}

/**
* @param \OCP\Command\ICommand | callable $command
*/
private function runCommand($command) {
if ($command instanceof ICommand) {
// ensure the command can be serialized
$serialized = serialize($command);
if (strlen($serialized) > 4000) {
throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
}
$unserialized = unserialize($serialized);
$unserialized->handle();
} else {
$command();
private function runCommand(ICommand $command): void {
// ensure the command can be serialized
$serialized = serialize($command);
if (strlen($serialized) > 4000) {
throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
}
$unserialized = unserialize($serialized, ['allowed_classes' => [
\Test\Command\SimpleCommand::class,
\Test\Command\StateFullCommand::class,
\Test\Command\FilesystemCommand::class,
\OCA\Files_Trashbin\Command\Expire::class,
\OCA\Files_Versions\Command\Expire::class,
]]);
$unserialized->handle();
}

public function run() {
public function run(): void {
while ($command = array_shift($this->queue)) {
$this->runCommand($command);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/public/Command/IBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
/**
* Interface IBus
*
* @deprecated 33.0.0 The interface is considered internal going forward and should not be implemented by apps anymore
* @since 8.1.0
*/
interface IBus {
/**
* Schedule a command to be fired
*
* @param \OCP\Command\ICommand | callable $command
* @param \OCP\Command\ICommand $command
* @since 33.0.0 Only allowed for {@see \OCA\Files_Trashbin\Command\Expire} and {@see \OCA\Files_Versions\Command\Expire}
* @since 8.1.0
*/
public function push($command);
public function push(ICommand $command): void;

/**
* Require all commands using a trait to be run synchronous
*
* @param string $trait
* @since 8.1.0
*/
public function requireSync($trait);
public function requireSync(string $trait): void;
}
Loading
Loading