Skip to content

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

@summersab

Description

@summersab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagePending check for reproducibility or if it fits our roadmapenhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions