Example #1
0
 /**
  * Constrói e persiste informações relevantes sobre a transação através
  * do Modelo Logger
  *
  * @param Model $Model
  * @param string $action
  */
 protected function logQuery(Model $Model, $action = 'create')
 {
     // Se não houver modelo configurado para salvar o log, aborta
     if ($this->checkLogModels() === false) {
         CakeLog::write(LOG_WARNING, __d('auditable', 'You need to define AuditableConfig::$Logger'));
         return;
     }
     $diff = $this->getDiff($Model, $action);
     // Caso não haja alterações/registro criado/excluído, não cria log
     if (empty($diff)) {
         return;
     }
     $encoded = $this->buildEncodedMessage($action, $diff);
     $statement = $this->getQuery($Model, $action);
     $toSave = array('Logger' => array('responsible_id' => $this->activeResponsibleId ?: 0, 'model_alias' => $Model->alias, 'model_id' => $Model->id, 'type' => $this->typesEnum[$action] ?: 0), 'LogDetail' => array('difference' => $encoded, 'statement' => $statement));
     $this->QueryLogSource->disable($this->Logger);
     // Salva a entrada nos logs. Caso haja falha, usa o Log default do Cake para registrar a falha
     if ($this->Logger->saveAssociated($toSave) === false) {
         CakeLog::write(LOG_WARNING, sprintf(__d('auditable', "Can't save log entry for statement: \"%s'\""), $statement));
     }
     $this->QueryLogSource->enable($this->Logger);
 }
Example #2
0
 public function saveAssociated($data = null, $options = array())
 {
     foreach ($data as $alias => $modelData) {
         if (!empty($this->hasAndBelongsToMany[$alias])) {
             $habtm = array();
             $Model = ClassRegistry::init($this->hasAndBelongsToMany[$alias]['className']);
             foreach ($modelData as $modelDatum) {
                 if (empty($modelDatum['id'])) {
                     $Model->create();
                 }
                 $Model->save($modelDatum);
                 $habtm[] = empty($modelDatum['id']) ? $Model->getInsertID() : $modelDatum['id'];
             }
             $data[$alias] = array($alias => $habtm);
         }
     }
     return parent::saveAssociated($data, $options);
 }
 public function saveAssociated($data = null, $options = array())
 {
     $this->useMasterDb();
     return parent::saveAssociated($data, $options);
 }