How to realize that a file has been shared/unshared by querying the database or using hooks

Back in the OC days I had written a small app that restored important files shared by some specific ‘admin’ on the users accounts. I was getting the info that a user unshared a file shared by that admin by querying the database and checking some status or permissions field.

Since, the database scheme has changed and that app doesn’t work. Moreover I cannot find the fields that would provide the ‘unshared’ info in the new DB. Even worse, it seems like the ‘post_unshare’ event does not fire when a recipient unshares a file from his account. That I could verify from the admin audit as well… Only if the owner unshares the file, then the event is recorder through the admin_audit.

Is there any way to know from within the database that a file has been unshared? Is there a way to catch that with a hook?

Many thanks!

briefly, before anyone with better knowledge answer:

Thank you very much for the reply. May I ask why you chose to handle the events on a different file (FilesEvents.php) rather than writing the handling functions directly in the FilesHooks.php? I am trying to handle the events directly in a “Hooks.php” and some of them do not seem to respond, i.e. the ‘delete’ event, and the ‘post_unshare’. While others do… I wonder if I should handle it the same way as in Nextant:

registering in an "Application.php"
catching in a "FilesHooks.php
serving in a “FilesEvents.php”

My code follows the logic of admin_audit app and handles the hooks directly in the “FilesHooks.php”.

Like I said, my knowledge on nextcloud is limited; this is the way devs told me (4 months ago) to handle Hooks (using apps/activity/ as an example)

Now, if I heard of a cleaner way, i’ll switch :]

If I get something concrete, I will share here. Thanks again.

I found this discussion when I was studying how to detect unshare by the file recipient. With some more investigation, I found that in the older versions of ownCloud there used to be signal post_unshareFromSelf emitted when the recipient unshares a file, but this was missing from ownCloud versions >= 9.0. The sharing library had been rewritten at that point, and probably the signal had been forgotten.

Hence, I made pull requests to add this signal again to ownCloud and Nextcloud. For Nextcloud, the PR is and it was merged 3 days ago. It will probably still take some time before the signal is emitted in any official release of Nextcloud.