Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. class CustomDataObjectLog extends DataExtension {
  2.    
  3.     private $logged;
  4.  
  5.     /**
  6.      * Logga $msg mediante l'apposito controller
  7.      *
  8.      * @param String $msg
  9.      */
  10.     private function zlog($msg = null) {
  11.        
  12.         // Evito di loggare se l'ho già fatto
  13.         if ($this->logged !== TRUE) {
  14.             Debug::log('LOGGO');
  15.             // Verifica necessaria ad evitare loop infiniti
  16.             // e coerenza semantica
  17.             $class = get_class($this->owner);
  18.             if ($class !== 'Log'
  19.                             && $class !== 'DataObject'
  20.                             && $this->owner instanceof DataObject) {
  21.  
  22.                 // Creo il Log
  23.                 $log = new Log();
  24.                 $log->doLog($msg, $this->owner);
  25.                 $this->logged = TRUE;
  26.             }
  27.         } else {
  28.             Debug::log('NON LOGGO');
  29.         }
  30.     }
  31.  
  32.     /**
  33.      * Prima della scrittura sul db
  34.      */
  35.     public function onBeforeWrite() {
  36.         parent::onBeforeWrite();
  37.     }
  38.  
  39.     /**
  40.      * Dopo la scrittura sul db
  41.      */
  42.     public function onAfterWrite() {
  43.         parent::onAfterWrite();
  44.         $this->zlog('Write');
  45.     }
  46.  
  47.     /**
  48.      * Prima della cancellazione sul db
  49.      */
  50.     public function onBeforeDelete() {
  51.         parent::onBeforeDelete();
  52.     }
  53.  
  54.     /**
  55.      * Dopo la cancellazione sul db
  56.      */
  57.     public function onAfterDelete() {
  58.         parent::onAfterDelete();
  59.         $this->zlog('Delete');
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement