Beispiel #1
0
 /**
  * @param EveApiReadWriteInterface $data
  *
  * @return self
  */
 public function retrieveEveApi(EveApiReadWriteInterface $data)
 {
     $mess = sprintf('Started filesystem retrieve for %1$s/%2$s', $data->getEveApiSectionName(), $data->getEveApiName());
     $this->getLogger()->debug($mess);
     try {
         $cachePath = $this->getSectionCachePath($data->getEveApiSectionName());
         $this->checkUsableCachePath($cachePath);
         $cacheFile = $cachePath . $data->getEveApiName() . $data->getHash() . '.xml';
         $this->checkUsableCacheFile($cacheFile);
         $this->prepareConnection($cacheFile);
         $result = $this->readXmlData($cacheFile);
         $this->__destruct();
         if ($this->isExpired($result)) {
             $mess = sprintf('Deleting expired cache file %1$s', $cacheFile);
             $this->getLogger()->debug($mess);
             @unlink($cacheFile);
             return $this;
         }
     } catch (YapealRetrieverException $exc) {
         $mess = 'Could NOT get XML data';
         $this->getLogger()->debug($mess, ['exception' => $exc]);
         return $this;
     }
     $data->setEveApiXml($result);
     return $this;
 }
Beispiel #2
0
 /**
  * @param EveApiReadWriteInterface $data
  *
  * @return string|false
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 private function getXmlFileContents(EveApiReadWriteInterface $data)
 {
     // BaseSection/ApiHash.xml
     $cacheFile = sprintf('%1$s%2$s/%3$s%4$s.xml', $this->getCachePath(), ucfirst($data->getEveApiSectionName()), ucfirst($data->getEveApiName()), $data->getHash());
     if (false === ($xml = $this->safeFileRead($cacheFile))) {
         $messagePrefix = sprintf('Failed to read XML file %s during the retrieval of', $cacheFile);
         $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($messagePrefix, $data));
         return false;
     }
     if ('' === $xml) {
         $messagePrefix = sprintf('Received an empty XML file %s during the retrieval of', $cacheFile);
         $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::NOTICE, $this->createEveApiMessage($messagePrefix, $data));
         return false;
     }
     $data->setEveApiXml($xml);
     if ($this->isExpired($data)) {
         $this->deleteWithRetry($cacheFile);
         return false;
     }
     $messagePrefix = sprintf('Using cached XML file %s during the retrieval of', $cacheFile);
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->createEveApiMessage($messagePrefix, $data));
     return $xml;
 }
Beispiel #3
0
 /**
  * @param EveApiReadWriteInterface $data
  *
  * @return bool
  * @throws \DomainException
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @throws \UnexpectedValueException
  */
 protected function releaseApiLock(EveApiReadWriteInterface $data) : bool
 {
     $sql = $this->getCsq()->getApiLockRelease(crc32($data->getHash()));
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
     $context = [];
     $success = false;
     try {
         $success = (bool) $this->getPdo()->query($sql)->fetchColumn();
     } catch (\PDOException $exc) {
         $context = ['exception' => $exc];
     }
     $mess = $success ? 'Released lock for' : 'Could NOT release lock for';
     $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $this->createEveApiMessage($mess, $data), $context);
     return $success;
 }