/**
  * @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);
 }
Beispiel #2
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;
 }