Skip to content

lingo/silverstripe_filelistener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SilverStripe FileListener

Allows you to register for notifications about changes to File or Image objects and their subclasses.

Usage

     FileListenerDecorator::register_listener($className, $staticMethodName, $eventType);

Event Types:

You can register a listener for any of these events, or use all to listen to any event type.

  • create
  • update
  • delete
  • all

Your class provides a static method which will receive the updated record AFTER writing. Example:

    public static function on_file_notify($file, $event)

This will be called for each changed File (or subclass) object, with $event set to the relevant event type (create|update|delete).

This static method may inspect the changedFields and decide how to process the changes.

CAVEAT: Do not write() any File objects within your static method, results are not guaranteed to be pretty!