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
5 changes: 1 addition & 4 deletions lib/private/Migration/BackgroundRepair.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class BackgroundRepair extends TimedJob {
/** @var EventDispatcherInterface */
private $dispatcher;

/**
* @param EventDispatcherInterface $dispatcher
*/
public function setDispatcher(EventDispatcherInterface $dispatcher): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only executed in tests, why did it work then in the actual code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is then actually needed in line 94. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only used in

$queue->add('OC\Migration\BackgroundRepair', [
'app' => $appId,
'step' => $step]);
so I guess it just always ran without events

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because

if (!is_null($this->dispatcher)) {
$this->dispatcher->dispatch("$scope::$method",
new GenericEvent("$scope::$method", $arguments));
}
checks existence before using it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But shouldn't then this fail?

public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {

because there is only a type hint and not an explicit = null. Or is this only causing issues in strict mode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already a PR, because I can't find any.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is it. We now properly inject it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But where? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referencing the initialization of a new BackgroundRepair instance. But you are right - they are added to the queue and the queue then uses the DI container. Sorry for the noise.

public function __construct(EventDispatcherInterface $dispatcher) {
$this->dispatcher = $dispatcher;
}

Expand Down
5 changes: 2 additions & 3 deletions tests/lib/Migration/BackgroundRepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ public function setUp() {
$this->logger = $this->getMockBuilder(ILogger::class)
->disableOriginalConstructor()
->getMock();
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->job = $this->getMockBuilder(BackgroundRepair::class)
->setConstructorArgs([$this->dispatcher])
->setMethods(['loadApp'])
->getMock();

$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->job->setDispatcher($this->dispatcher);
}

public function testNoArguments() {
Expand Down