Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dispatcher): Migrate to OCP event dispatcher before symfony/event… #38545

Merged
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
39 changes: 39 additions & 0 deletions .github/workflows/lint-eslint-when-unrelated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# Use lint-eslint together with lint-eslint-when-unrelated to make eslint a required check for GitHub actions
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks

name: Lint eslint

on:
pull_request:
paths-ignore:
- '.github/workflows/**'
- 'src/**'
- 'apps/**/appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.*'
- '.eslintignore'
- '**.js'
- '**.ts'
- '**.vue'

permissions:
contents: read

jobs:
lint:
permissions:
contents: none

runs-on: ubuntu-latest

name: eslint

steps:
- run: 'echo "No eslint required"'
43 changes: 43 additions & 0 deletions .github/workflows/node-when-unrelated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# Use node together with node-when-unrelated to make eslint a required check for GitHub actions
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks

name: Node

on:
pull_request:
paths-ignore:
- '.github/workflows/**'
- 'src/**'
- 'apps/**/appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '**.js'
- '**.ts'
- '**.vue'
push:
branches:
- main
- master
- stable*

concurrency:
group: node-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
permissions:
contents: none

runs-on: ubuntu-latest

name: node
steps:
- name: Skip
run: 'echo "No JS/TS files changed, skipped Node"'
8 changes: 4 additions & 4 deletions apps/lookup_server_connector/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Application extends App implements IBootstrap {
Expand All @@ -56,8 +56,8 @@ public function boot(IBootContext $context): void {
/**
* @todo move the OCP events and then move the registration to `register`
*/
private function registerEventListeners(EventDispatcher $dispatcher,
IAppContainer $appContainer): void {
private function registerEventListeners(EventDispatcherInterface $dispatcher,
ContainerInterface $appContainer): void {
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($appContainer) {
/** @var IUser $user */
$user = $event->getSubject();
Expand Down
4 changes: 2 additions & 2 deletions apps/systemtags/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SystemTag\ManagerEvent;
use OCP\SystemTag\MapperEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;

class Application extends App implements IBootstrap {
public const APP_ID = 'systemtags';
Expand All @@ -47,7 +47,7 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
$context->injectFn(function (EventDispatcher $dispatcher) use ($context) {
$context->injectFn(function (IEventDispatcher $dispatcher) use ($context) {
/*
* @todo move the OCP events and then move the registration to `register`
*/
Expand Down
3 changes: 1 addition & 2 deletions lib/private/EventDispatcher/SymfonyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public function dispatch($eventName, $event = null): object {

// Event with no payload (object) need special handling
if ($newEvent === null) {
$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
return new Event();
$newEvent = new Event();
}

// Flip the argument order for Symfony to prevent a trigger_error
Expand Down
1 change: 1 addition & 0 deletions tests/lib/EventDispatcher/SymfonyAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function testDispatchEventWithoutPayload(): void {
$symfonyDispatcher->expects(self::once())
->method('dispatch')
->with(
$this->anything(),
$eventName
)
->willReturnArgument(0);
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/Share20/LegacyHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@

namespace Test\Share20;

use OC\EventDispatcher\SymfonyAdapter;
use OC\Share20\LegacyHooks;
use OC\Share20\Manager;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\IServerContainer;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
Expand All @@ -46,7 +49,10 @@ class LegacyHooksTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->eventDispatcher = new EventDispatcher();
$symfonyDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$logger = $this->createMock(LoggerInterface::class);
$eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
$this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger);
$this->hooks = new LegacyHooks($this->eventDispatcher);
$this->manager = \OC::$server->getShareManager();
}
Expand Down