Example #1
0
 /**
  * @param string                   $messagePrefix
  * @param EveApiReadWriteInterface $data
  *
  * @return string
  * @throws \LogicException
  */
 protected function createEveApiMessage(string $messagePrefix, EveApiReadWriteInterface $data) : string
 {
     $mess = $messagePrefix . ' Eve API %1$s/%2$s';
     $subs = [lcfirst($data->getEveApiSectionName()), $data->getEveApiName()];
     if ($data->hasEveApiArgument('keyID')) {
         $mess .= ' for keyID = %3$s';
         $subs[] = $data->getEveApiArgument('keyID');
         if ($data->hasEveApiArgument('characterID')) {
             $mess .= ' and characterID = %4$s';
             $subs[] = $data->getEveApiArgument('characterID');
         } elseif ($data->hasEveApiArgument('corporationID')) {
             $mess .= ' and corporationID = %4$s';
             $subs[] = $data->getEveApiArgument('corporationID');
         }
     }
     return vsprintf($mess, $subs);
 }
Example #2
0
 /**
  * @param EveApiReadWriteInterface $data
  * @param EveApiRetrieverInterface $retrievers
  * @param EveApiPreserverInterface $preservers
  * @param int                      $interval
  *
  * @return bool
  * @throws \LogicException
  */
 public function oneShot(EveApiReadWriteInterface $data, EveApiRetrieverInterface $retrievers, EveApiPreserverInterface $preservers, &$interval)
 {
     $ids = $data->getEveApiArgument('ids');
     if (null === $ids || '' === $ids) {
         $mess = sprintf('Data is missing required "ids" parameter for %1$s/%2$s', strtolower($this->getSectionName()), $this->getApiName());
         $this->getLogger()->warning($mess);
         return false;
     }
     return parent::oneShot($data, $retrievers, $preservers, $interval);
 }
Example #3
0
 /**
  * @param EveApiReadWriteInterface $data
  *
  * @return void
  * @throws \LogicException
  */
 protected function preserveToStarbaseDetail(EveApiReadWriteInterface $data)
 {
     $tableName = 'corpStarbaseDetail';
     $ownerID = $this->extractOwnerID($data->getEveApiArguments());
     $starbaseID = $data->getEveApiArgument('itemID');
     $sql = $this->getCsq()->getDeleteFromStarbaseDetailTables($tableName, $ownerID, $starbaseID);
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
     $this->getPdo()->exec($sql);
     $columnDefaults = ['ownerID' => $ownerID, 'itemID' => $starbaseID, 'onlineTimestamp' => '1970-01-01 00:00:01', 'state' => '0', 'stateTimestamp' => '1970-01-01 00:00:01'];
     $xPath = '//result/child::*[not(*|@*|self::dataTime)]';
     $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
     $this->valuesPreserveData($elements, $columnDefaults, $tableName);
 }
Example #4
0
 /**
  * @param EveApiReadWriteInterface $data
  * @param int                      $interval
  *
  * @throws LogicException
  * @return bool
  */
 protected function isEveApiXmlError(EveApiReadWriteInterface $data, &$interval)
 {
     $xml = $data->getEveApiXml();
     if (false === $xml) {
         return false;
     }
     if (false === strpos($xml, '<error')) {
         return false;
     }
     $simple = new SimpleXMLElement($xml);
     if (!isset($simple->error[0])) {
         return false;
     }
     $code = (int) $simple->error[0]['code'];
     $mess = sprintf('Eve Error (%3$s): Received from API %1$s/%2$s - %4$s', strtolower($this->getSectionName()), $this->getApiName(), $code, (string) $simple->error[0]);
     if ($code < 200) {
         if (strpos($mess, 'retry after') !== false) {
             $interval = strtotime(substr($mess, -19) . '+00:00') - time();
         }
         $this->getLogger()->warning($mess);
         return true;
     }
     if ($code < 300) {
         // API key errors.
         $mess .= ' for keyID: ' . $data->getEveApiArgument('keyID');
         $this->getLogger()->error($mess);
         $interval = 86400;
         return true;
     }
     if ($code > 903 && $code < 905) {
         // Major application or Yapeal error.
         $this->getLogger()->alert($mess);
         $interval = 86400;
         return true;
     }
     $this->getLogger()->warning($mess);
     $interval = 300;
     return true;
 }
Example #5
0
 /**
  * @param EveApiReadWriteInterface $data
  *
  * @return static Fluent interface.
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 protected function updateCachedUntil(EveApiReadWriteInterface $data)
 {
     if ('' === $data->getEveApiXml()) {
         return $this;
     }
     $currentTime = (string) (new \SimpleXMLElement($data->getEveApiXml()))->currentTime[0];
     if ('' === $currentTime) {
         return $this;
     }
     $dateTime = gmdate('Y-m-d H:i:s', strtotime($currentTime . '+00:00') + $data->getCacheInterval());
     $row = ['accountKey' => $data->hasEveApiArgument('accountKey') ? $data->getEveApiArgument('accountKey') : '0', 'apiName' => $data->getEveApiName(), 'expires' => $dateTime, 'ownerID' => $this->extractOwnerID($data->getEveApiArguments()), 'sectionName' => $data->getEveApiSectionName()];
     $sql = $this->getCsq()->getUpsert('utilCachedUntil', array_keys($row), 1);
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
     $pdo = $this->getPdo();
     $pdo->beginTransaction();
     $context = [];
     $success = false;
     try {
         $pdo->prepare($sql)->execute(array_values($row));
         $pdo->commit();
         $success = true;
     } catch (\PDOException $exc) {
         $pdo->rollBack();
         $context = ['exception' => $exc];
     }
     $mess = $success ? 'Updated cached until date/time of' : 'Could NOT update cached until date/time of';
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $this->createEveApiMessage($mess, $data), $context);
     return $this;
 }