/** * Retuns a GlobalPriceData object. Tries caches and instantiates new objects if necessary. * * @param int $typeId of requested market data typeId * @param int $maxPriceDataAge maximum global price data age. * * @return \iveeCore\GlobalPriceData * @throws \iveeCore\Exceptions\NoPriceDataAvailableException if there is no price data available for the typeId */ public static function getById($typeId, $maxPriceDataAge = null) { if (is_null($maxPriceDataAge)) { $maxPriceDataAge = Config::getMaxPriceDataAge(); } if (!isset(static::$instancePool)) { static::init(); } try { return static::$instancePool->getItem(static::getClassHierarchyKeyPrefix() . (int) $typeId); } catch (KeyNotFoundInCacheException $e) { //go to DB $typeClass = Config::getIveeClassName(static::getClassNick()); $type = new $typeClass((int) $typeId, $maxPriceDataAge); //store object in instance pool static::$instancePool->setItem($type); return $type; } }
/** * Performs market price data update for specified regions, for all items that need updating (depending on * maxPriceDataAge). * * @param array $regionIds of the regions that should be updated * @param bool $verbose whether info should be printed to console * * @return void */ protected function updatePrices(array $regionIds, $verbose) { if (!isset($this->marketProcessor)) { $crestMarketProcessorClass = Config::getIveeClassName('CrestMarketProcessor'); $this->marketProcessor = new $crestMarketProcessorClass($this->endpointHandler); } if ($verbose) { echo get_called_class() . " starting market prices update\n"; } //get the cutoff timestamp for determining what price data age is too old $cutoffTs = time() - Config::getMaxPriceDataAge(); foreach ($regionIds as $regionId) { $idsToUpdate = static::getTypeIdsToUpdate($regionId, $cutoffTs, 'lastPriceUpdate', $this->endpointHandler); if (count($idsToUpdate) > 0) { if ($verbose) { echo 'Updating price data for ' . count($idsToUpdate) . ' market types in regionId=' . $regionId . PHP_EOL; } $this->marketProcessor->runPriceBatch($idsToUpdate, array($regionId), $verbose); } else { if ($verbose) { echo 'No prices to update for market types in regionId=' . $regionId . PHP_EOL; } } } }
/** * Constructor. Use getByIdAndRegion() instead. * * @param int $typeId of type * @param int $regionId of the region * @param int $maxPriceDataAge for the market prices, used for setting cache expiry * @param array $data to be used instead of DB lookup * * @throws \iveeCore\Exceptions\NotOnMarketException if requested type is not on market * @throws \iveeCore\Exceptions\NoPriceDataAvailableException if no region market data is found */ protected function __construct($typeId, $regionId, $maxPriceDataAge, array $data = null) { $this->id = (int) $typeId; $this->regionId = (int) $regionId; $type = Type::getById($this->id); if (!$type->onMarket()) { $this->throwNotOnMarketException($type); } //set data to object, fetching from DB if necessary $this->setData($data); if (is_null($maxPriceDataAge)) { $maxPriceDataAge = Config::getMaxPriceDataAge(); } if ($this->lastPriceUpdate + $maxPriceDataAge > time()) { $this->expiry = $this->lastPriceUpdate + $maxPriceDataAge; } else { $this->expiry = time() + 1800; } //if the data somehow is too old, cache it for another half hour }