public function parse() { /** * Добавляем валидаторы, которые проверяют возможность обработки * данного файла */ $this->addValidator(new SV\TagsValidator($this, ['Shipment' => 'Id', 'Event' => 'Code', 'MANH_TPM_Shipment' => 'Timestamp'])); $this->addValidator(new SV\EventStatusValidator($this)); $result = $this->runValidators(); if (false === $result['success']) { /** * test point 1. File validation failed. */ $this->saveImportLog($this->getImportName(), $result['message'], self::STATUS_ERR); return; } #$this->addWorkers(new W\TimeBufferWorkers($this)); $shipmentId = $this->getValueByAttribute('Shipment', 'Id'); $code = $this->getValueByAttribute('Event', 'Code'); $events = $this->getEventsByShipmentId($shipmentId, self::SHIPMENT_SHIPPED); if (false == $events && $code == self::SHIPMENT_SHIPPED) { $event = new SM\Event(); $event->setExternalId($shipmentId); $event->setEventCode($code); $event->setFilename($this->_filename); $event->setCheckSum(md5_file($this->_filename)); $event->setSystemName(self::SYSTEM_EEM); $event->setOccurredAt($this->getDateByAttribute('Event', 'DateTime')); $event->setExternalCreatedAt($this->getDateByAttribute('MANH_TPM_Shipment', 'Timestamp')); $event->setConfirmationAt(new \DateTime()); $event->setDestinationPath($this->getDistinationPath()); /** * additional fields */ $event->setCustomNumber1($this->getValueByAttribute('EventLocation', 'OrgInternalId')); $event->setCustomNumber2($this->getValueByAttribute('EventLocation', 'InternalId')); $event->setCustomNumber3($this->getValueByAttribute('EventRefLocation', 'OrgInternalId')); $event->setCustomNumber4($this->getValueByAttribute('EventRefLocation', 'InternalId')); try { $this->_em->getConnection()->beginTransaction(); $this->importShipment($shipmentId); $this->_em->getConnection()->commit(); $event->setStatus(self::STATUS_EVENT_READY); } catch (\Exception $ex) { $this->_em->getConnection()->rollback(); $event->setStatus(self::STATUS_EVENT_ERROR); $event->setDescription($ex->getMessage()); } $this->_em->persist($event); $this->_em->flush(); $this->_em->clear(); $this->clear(); } else { $message = "Incorrect event received from SM. Filename: {$this->getFileName()} . Time: " . date('H:i:s d.m.Y', time()); $this->saveImportLog($this->getImportName(), $message, self::STATUS_ERR); @mail('ivan.popov@panalpina.com,stanislav.biryukov@panalpina.com', 'Incorrect event received from SM', $message); } }