triggering a function of mine on every file upload by any user

triggering a function of mine on every file upload by any user

by Patrick Scott -
Number of replies: 2

I want to execute a function of mine every time a file is uploaded.
by every time I mean not in a certain mod but any way a user can upload a file to moodle and no matter if it's via drag and drop, or through the filepicker or any other way.

I didn't find an Event or Callback for that.

is there a way to do that without modifying an of Moodle's core files?

there is a function named "process_upload" at /repository/upload/lib.php and I can modify that function but that of course would be a core modification.

I have moodle 3.8.1 installed

Average of ratings: -
In reply to Patrick Scott

Re: triggering a function of mine on every file upload by any user

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The way I can think fo to do this involved cheating, but ...

Why not write an custom Anti-virus plugin? https://docs.moodle.org/dev/Antivirus_plugins They get called every time a file is uploaded, without exception.

Obviously, you woudl not re-impleemnt virus checking. You would just make a plugin which notifies your code that a file was uploaded, and then passes on the call to the standard AV plugin.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: triggering a function of mine on every file upload by any user

by Patrick Scott -
as you suggested, I have created an antivirus plugin and do my own file checking on upload.
the cheat works great.

is there also a way to catch the event of file renaming? file updating?
the only way I currently see to catch such an event is at /repository/draftfiles_ajax.php - which is also moodle's core and I don't want to modify that file either for the same reasons.