Merge pull request #32868 from nextcloud/fix/replace-opis-closure-by-laravel-fork

Replace opis/closure by laravel/serializable-closure
This commit is contained in:
blizzz 2022-06-21 12:21:32 +02:00 committed by GitHub
commit 53eafc0cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 5 deletions

@ -1 +1 @@
Subproject commit 82f352b055efce690ffc533d68c08f77f734fafc
Subproject commit b5f73e95a36edde3bf36bea8c72204692af1a0b5

View File

@ -23,10 +23,13 @@
namespace OC\Command;
use OC\BackgroundJob\QueuedJob;
use Laravel\SerializableClosure\SerializableClosure as LaravelClosure;
use Opis\Closure\SerializableClosure as OpisClosure;
class ClosureJob extends QueuedJob {
protected function run($serializedCallable) {
$callable = \Opis\Closure\unserialize($serializedCallable);
$callable = unserialize($serializedCallable, [LaravelClosure::class, OpisClosure::class]);
$callable = $callable->getClosure();
if (is_callable($callable)) {
$callable();
} else {

View File

@ -30,7 +30,7 @@ use OCP\Command\ICommand;
*/
class CommandJob extends QueuedJob {
protected function run($serializedCommand) {
$command = \Opis\Closure\unserialize($serializedCommand);
$command = unserialize($serializedCommand);
if ($command instanceof ICommand) {
$command->handle();
} else {

View File

@ -26,6 +26,7 @@
namespace OC\Command;
use OCP\Command\ICommand;
use Laravel\SerializableClosure\SerializableClosure;
class CronBus extends AsyncBus {
/**
@ -67,9 +68,9 @@ class CronBus extends AsyncBus {
*/
private function serializeCommand($command) {
if ($command instanceof \Closure) {
return \Opis\Closure\serialize($command);
return serialize(new SerializableClosure($command));
} elseif (is_callable($command) or $command instanceof ICommand) {
return \Opis\Closure\serialize($command);
return serialize($command);
} else {
throw new \InvalidArgumentException('Invalid command');
}

View File

@ -47,4 +47,11 @@ class CronBusTest extends AsyncBusTest {
$job->execute($this->jobList);
}
}
public function testClosureFromPreviousVersion() {
$serializedClosure = 'C:32:"Opis\\Closure\\SerializableClosure":217:{a:5:{s:3:"use";a:0:{}s:8:"function";s:64:"function () {\\Test\\Command\\AsyncBusTest::$lastCommand = \'opis\';}";s:5:"scope";s:24:"Test\\Command\\CronBusTest";s:4:"this";N;s:4:"self";s:32:"0000000027dcfe2f00000000407fa805";}}';
$this->jobList->add('OC\Command\ClosureJob', $serializedClosure);
$this->runJobs();
$this->assertEquals('opis', AsyncBusTest::$lastCommand);
}
}