/** * @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; }