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

Using dispatchTyped and changed event names broke dependent app integrations #159

Open
payne8 opened this issue Apr 23, 2022 · 2 comments
Open

Comments

@payne8
Copy link

payne8 commented Apr 23, 2022

I have an app integration that is dependent on files_fulltextsearch. I hook into the EventDispatcher and listen for specific events. It has been a while since I upgraded my app (along with upgrading files_fulltextsearch), but in attempting to do so I noticed that all the events stopped working. I noticed that this app (files_fulltextsearch_tesseract) is having the same issues I am.

I did some digging and noticed that files_fulltextsearch was still calling $this->dispatch in the lib/Service/ExtensionService.php file. But the dispatch function was changed to call $this->eventDispatcher->dispatchTyped in this commit: df0ec11#diff-966d10a7ed8f3b02fa5f56cb2ad73d79b5a4cb1d947f6817a389e40c3f6569cdR123

When I print out the names of these new versions of the events, I get OCP\EventDispatcher\GenericEvent instead of the expected event names.

I believe this means that all apps that are dependent on these events are currently broken or they've figured out they have to listen to the event OCP\EventDispatcher\GenericEvent and figure out how to handle the various arguments coming through.

I think the fix is to go back to using $this->eventDispatcher->dispatch on the line I linked to above. Then the dependent apps can switch to the new event names and they will start working again.

I'm happy to submit a PR to fix it if that is desired.

Affected files:
lib/Service/ExtensionService.php

@payne8
Copy link
Author

payne8 commented Apr 23, 2022

Another option is to create an event class that extends GenericEvent for each event being published.

@thiscantbeserious
Copy link

thiscantbeserious commented Jan 8, 2023

Thanks for this hint! This here is currently working on NC 25.0.2 with the latest version:

		//fixed thanks to this hint: https://github.com/nextcloud/files_fulltextsearch/issues/159
		$eventDispatcher->addListener(
			'OCP\EventDispatcher\GenericEvent',
			function (GenericEvent $e) {
				$subject = $e->getSubject();
				$this->logger->info(self::APP_NAME." {$subject} event catched");
				switch($subject) {
					case "Files_FullTextSearch.onFileIndexing":
					$this->mailService->onFileIndexing($e);
					break;
					case "Files_FullTextSearch.onSearchRequest":
					$this->mailService->onSearchRequest($e);
					break;
					case "Files_FullTextSearch.onSearchResult":
					$this->mailService->onSearchResult($e);
					break;

				}
				$this->mailService->onSearchResult($e);
			}
		);

However I fully agree that it might be better to switch to proper distinct events that subclass OCP\EventDispatcher\Event in this app here, because the current workaround is rather ... ugly and generic instead (phun intended).

Not sure if that's possible with Nextcloud accross Apps? These changes seem to origin starting NC22 where they refactored to their own Event-Bus away from Symphony, that's at least how I understand it from the depcrecated notes. Documentation could be really better in that regard in regards to NC itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants