Example #1
0
 public function write($event)
 {
     if ($this->_db === null) {
         throw new Zend_Log_Exception('Database adapter is null');
     }
     if ($this->_table === null) {
         throw new Zend_Log_Exception('Db table is null');
     }
     $dataToInsert = array();
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     // Sprawdzamy czy możemy zrobić update zamiast insertu.
     $dataToUpdate = array();
     if ($event['event_code'] == 'customerSynchronize') {
         $session = new Logic_Synchronizer_Session();
         $id = $session->getLastLogId();
         if ($id && ($row = $this->_table->findOne($id))) {
             $columnMapForUpdate = $row->getLogColumnMappingForUpdate();
             if (count($columnMapForUpdate) > 0) {
                 foreach ($columnMapForUpdate as $columnName => $fieldKey) {
                     $dataToUpdate[$columnName] = $event[$fieldKey];
                 }
                 $row->updateColumnsMappedForUpdate($dataToUpdate);
                 $row->save();
                 return;
             }
         }
         $id = $this->_table->insert($dataToInsert);
         $session->setLastLogId($id);
     } else {
         parent::write($event);
     }
 }