public function parse() { /** * Добавляем валидаторы, которые проверяют возможность обработки * данного файла */ $this->addValidator(new SV\TagsValidator($this, ['Booking' => 'Id', 'Event' => 'Id'])); $result = $this->runValidators(); if (false === $result['success']) { /** * test point 1. File validation failed. */ $this->saveImportLog($this->getImportName(), $result['message'], self::STATUS_ERR); return; } $bookingId = $this->getValueByAttribute('Booking', 'Id'); $code = $this->getValueByAttribute('Event', 'Code'); $trackingId = $this->getValueByAttribute('EventInfo', 'TrackingId'); $event = new SM\Event(); $event->setExternalId($trackingId); $event->setInternalId($bookingId); $event->setEventCode($code); $event->setFilename($this->_filename); $event->setCheckSum(md5_file($this->_filename)); $event->setSystemName(self::SYSTEM_TOOL); if (false == $this->getEventsByShipmentId($trackingId)) { $event->setStatus(self::STATUS_EVENT_READY); } else { $lastEvent = $this->getLastEventByExternalId($trackingId); if (null !== $lastEvent->getTransferredAt()) { $lastTransferred = false; //т.к. нам надо установить временной интервал задержки, то добавим эту конструкцию $now = new \DateTime(); $diff = $now->diff($lastEvent->getTransferredAt()); $interval = (int) $diff->format('%i'); if ($interval > self::TIME_LIMIT_FOR_TRANSFER_MINUTES) { $lastTransferred = true; } if (true === $lastTransferred) { $event->setStatus(self::STATUS_EVENT_READY); $event->setDescription("Last event ID " . $lastEvent->getId() . ",sent at " . $lastEvent->getConfirmationAt()->format('Y/m/d H:i')); } else { $event->setStatus(self::STATUS_LAST_EVENT_NOT_SEND); $event->setDescription("Time left less then " . self::TIME_LIMIT_FOR_TRANSFER_MINUTES); } } else { $event->setStatus(self::STATUS_LAST_EVENT_NOT_SEND); $event->setDescription("Last event ID " . $lastEvent->getId() . " didn't send"); } } $event->setExternalCreatedAt($this->getDateByAttribute('Event', 'DateTime')); $event->setConfirmationAt(new \DateTime()); $event->setOccurredAt(new \DateTime()); $event->setDestinationPath($this->getDistinationPath()); $this->_em->persist($event); $this->_em->flush(); $this->_em->clear(); $this->clear(); }
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); } }
public function parse() { /** * Добавляем валидаторы, которые проверяют возможность обработки * данного файла */ $this->addValidator(new SV\TagsValidator($this, ['MANH_TPM_Order' => 'Id', 'Order' => 'Id', 'PartnerVisibility' => 'Flag'])); $this->addValidator(new SV\POValidator($this)); $result = $this->runValidators(); if (false === $result['success']) { $this->saveImportLog($this->getImportName(), $result['message'], self::STATUS_ERR); return; } $shipmentId = $this->getValueByAttribute('Order', 'Id'); $code = 'P' . $this->getValueByAttribute('Event', 'Code'); $event = new SM\Event(); $event->setExternalId($shipmentId); $event->setEventCode($code); $event->setFilename($this->_filename); $event->setCheckSum(md5_file($this->_filename)); $event->setSystemName(self::SYSTEM_PO); $event->setOccurredAt(new \DateTime()); $event->setExternalCreatedAt($this->getDateByAttribute('MANH_TPM_Order', 'Timestamp')); $event->setConfirmationAt(new \DateTime()); $event->setDestinationPath($this->getDistinationPath()); try { $this->importPO(); $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(); }
protected function execute(InputInterface $input, OutputInterface $output) { try { $container = $this->getContainer(); $doctrine = $this->getContainer()->get('doctrine'); $em = $doctrine->getManager(); $messages = $doctrine->getRepository('SportmasterBundle:Message')->findByStatus('created'); $countGeneratedMessages = 0; $output->writeln(''); foreach ($messages as $message) { $class = Export\EventGenerateFactory::getInstance($message->getEventCode()); $entity = new $class($message->getHbl(), $container); $filename = $entity->export(); $output->writeln('<info>File generated successfully:</info> ' . $filename); $message->setStatus('generated'); $event = new SM\Event(); $event->setExternalId($message->getMbl()); $event->setEventCode($message->getEventCode()); $event->setFilename($filename); $event->setCheckSum(md5_file($filename)); $event->setSystemName('SCA'); $event->setOccurredAt(new \Datetime()); $event->setExternalCreatedAt(new \Datetime()); $event->setConfirmationAt(new \DateTime()); $event->setDestinationPath($entity->getDistinationPath()); $event->setStatus(1); $em->persist($event); $em->flush(); $countGeneratedMessages++; } $output->writeln(''); $output->writeln("<info>The {$countGeneratedMessages} messages was generated successfully"); } catch (\Exception $ex) { echo $ex->getMessage(); } }