nextcloud / nextcloud/server

Add event dispatcher to OC\DB\QueryBuilder::execute

Open
#28,923 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage enhancement
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

How to use GitHub
  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Is your feature request related to a problem? Please describe.
For advanced app integration, it would be nice to have an event dispatcher run before and after OC\DB\QueryBuilder::execute. While this may seem a little odd, there are certainly situations where this functionality would be useful:

  • Security apps could check SQL queries and parameters for dangerous patterns and prevent them from executing.
  • Some apps don't fire events themselves, but they do access the DB. A QueryBuilder event listener would allow developers to execute code when a query matching certain conditions is executed.
  • Deep integration with the platform and other apps would be possible.
  • In my particular case, I'm wanting to encrypt/decrypt certain fields used by other apps. I have written an app to transparently encrypt DAV data, but this required some rather kludge code to avoid editing core libraries. An event listener would have been a simpler solution.

Describe the solution you'd like
It would be great to have an event dispatcher added to OC\DB\QueryBuilder::execute both before and after $result = $this->queryBuilder->execute();. The dispatcher should be able to check if propagation has been halted, and if so, it will return the result provided by the listener.

Describe alternatives you've considered

  • I have tried to use the existing middleware and events to add certain functionalities, but these were neither efficient, reliable, nor ideal.
  • In order to modify DB calls made by existing apps, I have "overloaded" their classes by unregistering their existing classmap, autoloading a modified classmap specifying my modified classes, and executed queries this way. While this works and doesn't modify core code . . . it is gross and not recommended.
  • I have tried editing core libraries, but this is obviously not recommended.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at OC\DB\QueryBuilder::execute and inspect how its underlying queryBuilder executes SQL. Review the existing middleware and events mentioned in the issue before deciding how pre- and post-execution dispatching and halted propagation should work. Done means listeners can inspect or stop a query before execution and receive or provide the result afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.