Пример #1
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function preserveEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) : EveApiEventInterface
 {
     if (!$this->shouldPreserve()) {
         return $event;
     }
     $this->setYem($yem);
     $data = $event->getData();
     $xml = $data->getEveApiXml();
     if ('' === $xml) {
         return $event->setHandledSufficiently();
     }
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     $this->getPdo()->beginTransaction();
     try {
         foreach ($this->getPreserveTos() as $preserveTo) {
             $this->{$preserveTo}($data);
         }
         $this->getPdo()->commit();
     } catch (\PDOException $exc) {
         $mess = 'Failed to upsert data of';
         $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEveApiMessage($mess, $data), ['exception' => $exc]);
         $this->getPdo()->rollBack();
         return $event;
     }
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getFinishedEventMessage($data, $eventName));
     return $event->setHandledSufficiently();
 }
Пример #2
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 public function validateEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) : EveApiEventInterface
 {
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     if ('' === ($xml = $data->getEveApiXml())) {
         $messagePrefix = 'Given empty XML during the validation of';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($messagePrefix, $data));
         return $event;
     }
     if (false !== strpos($xml, '<!DOCTYPE html')) {
         $messagePrefix = 'Received HTML error doc instead of XML data during the validation of';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($messagePrefix, $data));
         // Cache received error html.
         $apiName = $data->getEveApiName();
         $data->setEveApiName('Invalid_' . $apiName);
         $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error');
         $data->setEveApiName($apiName);
         return $event;
     }
     if (false === ($xsdContents = $this->getXsdFileContents($data))) {
         return $event;
     }
     libxml_clear_errors();
     libxml_use_internal_errors(true);
     $dom = $this->getDom();
     if (false === $dom->loadXML($xml)) {
         $messagePrefix = 'DOM could not load XML during the validation of';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEveApiMessage($messagePrefix, $data));
         $this->checkLibXmlErrors($data, $yem);
         libxml_use_internal_errors(false);
         return $event;
     }
     if (false === $dom->schemaValidateSource($xsdContents)) {
         $messagePrefix = 'DOM schema could not validate XML during the validation of';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEveApiMessage($messagePrefix, $data));
         // Cache error causing XML.
         $apiName = $data->getEveApiName();
         $data->setEveApiName('Invalid_' . $apiName);
         $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error');
         $data->setEveApiName($apiName);
         $this->checkLibXmlErrors($data, $yem);
         libxml_use_internal_errors(false);
         return $event;
     }
     if (false === $this->checkForValidDateTimes($dom, $data)) {
         return $event;
     }
     libxml_use_internal_errors(false);
     $messagePrefix = 'Successfully validated the XML during the validation of';
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $this->createEveApiMessage($messagePrefix, $data));
     // Check for XML error element.
     if (false !== strpos($data->getEveApiXml(), '<error ')) {
         $this->emitEvents($data, 'start', 'Yapeal.Xml.Error');
         return $event;
     }
     return $event->setHandledSufficiently();
 }
Пример #3
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \Yapeal\Exception\YapealDatabaseException
  */
 public function startEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     if (!$this->hasYem()) {
         $this->setYem($yem);
     }
     $data = $event->getData();
     $apiName = $data->getEveApiName();
     $data->setEveApiName('StarbaseList');
     // Insure Starbase list has already been updated first so we have current list to get details with.
     $this->emitEvents($data, 'start');
     $data->setEveApiName($apiName)->setEveApiXml('');
     return parent::startEveApi($event->setData($data), $eventName, $yem);
 }
Пример #4
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \Yapeal\Exception\YapealDatabaseException
  */
 public function startEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     if (!$this->hasYem()) {
         $this->setYem($yem);
     }
     $data = $event->getData();
     $apiName = $data->getEveApiName();
     $data->setEveApiName($apiName . 'History');
     // Insure history has already been updated first so current data overwrites old data.
     $this->emitEvents($data, 'start');
     $data->setEveApiName($apiName)->setEveApiXml('');
     return parent::startEveApi($event->setData($data), $eventName, $yem);
 }
Пример #5
0
 /**
  * Method that is called for retrieve event.
  *
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 public function retrieveEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     if (!$this->shouldRetrieve()) {
         return $event;
     }
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     if (false === ($xml = $this->getXmlFileContents($data))) {
         return $event;
     }
     $data->setEveApiXml($xml);
     $mess = 'Successfully retrieved the XML of';
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->createEveApiMessage($mess, $data));
     return $event->setData($data)->eventHandled();
 }
Пример #6
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 public function transformEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     // Pretty up the XML to make other processing easier.
     $data->setEveApiXml($this->getTidy()->repairString($data->getEveApiXml()));
     $xml = $this->addYapealProcessingInstructionToXml($data)->performTransform($data);
     if (false === $xml) {
         return $event;
     }
     // Pretty up the transformed XML.
     $data->setEveApiXml($this->getTidy()->repairString($xml));
     $messagePrefix = 'Successfully transformed the XML of';
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $this->createEveApiMessage($messagePrefix, $data));
     return $event->setHandledSufficiently();
 }
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function processXmlError(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     $simple = new \SimpleXMLElement($data->getEveApiXml());
     /** @noinspection PhpUndefinedFieldInspection */
     $errorText = (string) $simple->error[0];
     /** @noinspection PhpUndefinedFieldInspection */
     if (isset($simple->error[0]['code'])) {
         /** @noinspection PhpUndefinedFieldInspection */
         $code = (int) $simple->error[0]['code'];
         $mess = sprintf('Received XML error: (%1$s) "%2$s" during', $code, $errorText);
     } else {
         $mess = sprintf('Received XML error with no code attribute: "%1$s" during', $errorText);
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName));
         return $event;
     }
     if ($code < 200) {
         if (false !== strpos($mess, 'retry after')) {
             $data->setCacheInterval(strtotime(substr($mess, -19) . '+00:00') - time());
         }
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName));
     } elseif ($code < 300) {
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::ERROR, $this->createEventMessage($mess, $data, $eventName));
         $data->setCacheInterval(86400);
     } elseif ($code > 903 && $code < 905) {
         // Major application or Yapeal error.
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::ALERT, $this->createEventMessage($mess, $data, $eventName));
         $data->setCacheInterval(86400);
     } else {
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName));
         $data->setCacheInterval(300);
     }
     $apiName = $data->getEveApiName();
     $data->setEveApiName('Error_' . $apiName);
     // Cache error XML.
     $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error');
     $data->setEveApiName($apiName);
     return $event->setData($data)->setHandledSufficiently();
 }
Пример #8
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function createSql(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) : EveApiEventInterface
 {
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     // Only work with raw unaltered XML data.
     if (false !== strpos($data->getEveApiXml(), '<?yapeal.parameters.json')) {
         return $event->setHandledSufficiently();
     }
     $this->sectionName = $data->getEveApiSectionName();
     $this->apiName = $data->getEveApiName();
     $outputFile = sprintf('%1$s%2$s/Create%3$s.%4$s.sql', $this->getRelativeBaseDir(), ucfirst($this->sectionName), ucfirst($this->apiName), $this->getPlatform());
     // Nothing to do if NOT overwriting and file exists.
     if (false === $this->isOverwrite() && is_file($outputFile)) {
         return $event->setHandledSufficiently();
     }
     $sxi = new \SimpleXMLIterator($data->getEveApiXml());
     $this->tables = [];
     $this->processValueOnly($sxi, $this->apiName);
     $this->processRowset($sxi, $this->apiName);
     $tCount = count($this->tables);
     if (0 === $tCount) {
         $mess = 'No SQL tables to create for';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($mess, $data));
         return $event->setHandledSufficiently();
     }
     ksort($this->tables);
     list($mSec, $sec) = explode(' ', microtime());
     $context = ['className' => lcfirst($this->apiName), 'tables' => $this->tables, 'sectionName' => lcfirst($this->sectionName), 'version' => gmdate('YmdHis', $sec) . substr($mSec, 1, 4)];
     $contents = $this->getContentsFromTwig($eventName, $data, $context);
     if (false === $contents) {
         return $event;
     }
     if (false === $this->safeFileWrite($outputFile, $contents)) {
         $yem->triggerLogEvent($eventName, Logger::WARNING, $this->getFailedToWriteFileMessage($data, $outputFile));
         return $event;
     }
     return $event->setHandledSufficiently();
 }
Пример #9
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function createXsd(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) : EveApiEventInterface
 {
     $this->setYem($yem);
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     // Only work with raw unaltered XML data.
     if (false !== strpos($data->getEveApiXml(), '<?yapeal.parameters.json')) {
         return $event->setHandledSufficiently();
     }
     $this->sectionName = $data->getEveApiSectionName();
     $this->apiName = $data->getEveApiName();
     $outputFile = sprintf('%1$s%2$s/%3$s.xsd', $this->getRelativeBaseDir(), ucfirst($this->sectionName), ucfirst($this->apiName));
     // Nothing to do if NOT overwriting and file exists.
     if (false === $this->isOverwrite() && is_file($outputFile)) {
         return $event;
     }
     $xml = $data->getEveApiXml();
     if ('' === $xml) {
         return $event->setHandledSufficiently();
     }
     $sxi = new \SimpleXMLIterator($xml);
     $this->tables = [];
     $this->processValueOnly($sxi, lcfirst($this->apiName));
     $this->processRowset($sxi);
     list($mSec, $sec) = explode(' ', microtime());
     $context = ['className' => lcfirst($this->apiName), 'tables' => $this->tables, 'sectionName' => lcfirst($this->sectionName), 'version' => gmdate('YmdHis', $sec) . sprintf('.%0-3s', floor($mSec * 1000))];
     $contents = $this->getContentsFromTwig($eventName, $data, $context);
     if (false === $contents) {
         return $event;
     }
     $contents = $this->getTidy()->repairString($contents);
     if (false === $this->safeFileWrite($outputFile, $contents)) {
         $yem->triggerLogEvent($eventName, Logger::WARNING, $this->getFailedToWriteFileMessage($data, $outputFile));
         return $event;
     }
     return $event->setHandledSufficiently();
 }
Пример #10
0
 /**
  * @param EveApiEventInterface $event
  * @param string               $eventName
  * @param MediatorInterface    $yem
  *
  * @return EveApiEventInterface
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  * @throws \Yapeal\Exception\YapealDatabaseException
  */
 public function startEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem)
 {
     if (!$this->hasYem()) {
         $this->setYem($yem);
     }
     $data = $event->getData();
     $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__));
     try {
         $records = $this->getActive($data);
     } catch (\PDOException $exc) {
         $mess = 'Could NOT get a list of active owners during the processing of';
         $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEveApiMessage($mess, $data), ['exception' => $exc]);
         return $event;
     }
     if (0 === count($records)) {
         $mess = 'No active owners found during the processing of';
         $yem->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $this->createEveApiMessage($mess, $data));
         $this->emitEvents($data, 'end');
         return $event->setHandledSufficiently();
     }
     if (0 !== count($this->accountKeys)) {
         $records = $this->processAccountKeys($records);
     }
     foreach ($records as $arguments) {
         $aClone = clone $data;
         if (false !== $arguments) {
             $aClone->setEveApiArguments($arguments);
             if (0 === strpos($data->getEveApiName(), 'Wallet')) {
                 $aClone->addEveApiArgument('rowCount', '2560');
             }
         }
         if ($this->cachedUntilIsNotExpired($aClone)) {
             $event->setHandledSufficiently();
             continue;
         }
         if ($this->oneShot($aClone)) {
             $event->setHandledSufficiently();
         }
     }
     return $event;
 }