nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.32k stars 4.06k forks source link

Detect changes to files (using custom hooks) #46588

Open mrAceT opened 3 months ago

mrAceT commented 3 months ago

I have built a 'hook' into the database of NextCloud and use it for it's cloud-drive capabilities and file management structure.

This is all working quite nicely, but when a file is moved the only way to process that change seems to do a complete database scan and compare the NextCloud tabel 'oc_filecache' to my table.

Detecting a new/newer file is now done using the field 'storage_mtime'

But I can't see a 'file move' nor a 'file rename' in the table. Could it be possible to simply update the 'storage_mtime' to "now"?

Or is there an other way?

joshtrichards commented 3 months ago

https://docs.nextcloud.com/server/latest/developer_manual/basics/events.html

mrAceT commented 3 months ago

@joshtrichards OK! So I could build an "event listener"!

I now "sort of reverse engineered" the 'oc_filecache' table. I understand where you directed me to, and I know PHP, but I have no experience what so ever in building something like this!

Are there simple examples somewhere where I can extend/append/alter upon? Where do I put the code?

mrAceT commented 3 weeks ago

My knowledge does not go deep/far enough to get this working..

But to be honest, why isn't 'storage_mtime' updated with a move, that's a change to is it not? And also have the distinct impression that when a file is added to NextCloud, the 'storage_mtime' is the date of the original file, not a "NC modification time"(haven't done deep testing, but I'm quite sure of it)

Why not? I expected that variable ('storage_mtime') to be an internal variable to track changes... but it seems to do that sort of half?

Or am I misunderstanding the usage of the variable?