/** * Runs the price batch update process for selected market types and regions. This is done with parallel async CURL * calls and DB submission + committing in batches. * * @param array $typeIds of the market types * @param array $regionIds of the marget regions * @param bool $verbose whether the items currently being updated should be printed to console * * @return void */ public function runPriceBatch(array $typeIds, array $regionIds, $verbose = false) { $this->verboseBatch = $verbose; foreach (array_unique($regionIds) as $regionId) { $this->endpointHandler->getMultiMarketOrders($typeIds, $regionId, function (Response $response) { $this->processOrderResponse($response); }, function (Response $response) { print_r($response); //TODO }, false); //overwrite existing array to ensure cleanup of potentially unprocessed single responses $this->orderResponseBuffer = []; } $this->commitSql(); }
/** * Returns an array with all solar system hrefs. When response time is critical, using this call is not recommended * due to it causing over 1100 calls to CREST when not already cached. * * @return array in the form solarSystemId => href */ public function getSolarSystemHrefs() { $dataKey = 'gathered:solarSystemHrefs'; try { $dataObj = $this->client->getCache()->getItem($dataKey); } catch (\iveeCore\Exceptions\KeyNotFoundInCacheException $e) { //instantiate data object $cacheableArrayClass = Config::getIveeClassName('CacheableArray'); $dataObj = new $cacheableArrayClass($dataKey, time() + 24 * 3600); //run the async queries $this->client->asyncGetMultiEndpointResponses($this->getConstellationHrefs(), function (Response $res) use($dataObj) { foreach ($res->content->systems as $system) { $dataObj->data[EndpointHandler::parseTrailingIdFromUrl($system->href)] = $system->href; } }, null, static::CONSTELLATION_REPRESENTATION); $this->client->getCache()->setItem($dataObj); } return $dataObj->data; }
/** * Fetches the typeIds of the items that need updating in a region * * @param int $regionId to be checked * @param int $cutoffTs the unix timestamp to be used to decide if data is too old * @param string $dateColumn the DB column to check the timestamp on, either 'lastHistUpdate' or 'lastPriceUpdate' * @param \iveeCrest\EndpointHandler $eph to be used * * @return array */ protected static function getTypeIdsToUpdate($regionId, $cutoffTs, $dateColumn, EndpointHandler $eph) { //get matket typeIds from CREST $marketTypeIds = array_keys($eph->getMarketTypeHrefs()); //get the subset Ids that need updating and are not Dust-only $res = static::$sde->query("SELECT typeID\n FROM invTypes\n WHERE typeID IN (" . implode(', ', $marketTypeIds) . ")\n AND typeID < 350000\n AND typeID NOT IN (\n SELECT typeID\n FROM " . Config::getIveeDbName() . ".trackedMarketData\n WHERE regionID = " . (int) $regionId . "\n AND " . $dateColumn . " > '" . date('Y-m-d H:i:s', $cutoffTs) . "'\n )\n ORDER BY typeID ASC;"); $ret = []; while ($tmp = $res->fetch_array(MYSQL_NUM)) { $ret[] = (int) $tmp[0]; } return $ret; }
/** * Fetches the data from CREST. * * @param \iveeCrest\EndpointHandler $eph to be used * * @return array */ protected static function getData(EndpointHandler $eph) { //we dont set the cache flag because the data normally won't be read again return $eph->getMarketPrices(false); }
public function testHandler() { $this->assertTrue($this->handler->verifyAccessToken() instanceof stdClass); $this->assertTrue($this->handler->tokenDecode() instanceof stdClass); $this->assertTrue(is_array($this->handler->getMarketTypes())); $this->assertTrue(is_array($this->handler->getMarketTypeHrefs())); $this->assertTrue(is_array($this->handler->getRegions())); $this->assertTrue($this->handler->getRegion(10000002) instanceof stdClass); $this->assertTrue(is_array($this->handler->getConstellationHrefs())); $this->assertTrue($this->handler->getConstellation(21000316) instanceof stdClass); $this->assertTrue(is_array($this->handler->getSolarSystemHrefs())); $this->assertTrue($this->handler->getSolarSystem(31000054) instanceof stdClass); $this->assertTrue($this->handler->getMarketOrders(34, 10000002) instanceof stdClass); $this->assertTrue(is_array($this->handler->getMarketHistory(34, 10000002))); $this->assertTrue(is_array($this->handler->getIndustrySystems())); $this->assertTrue(is_array($this->handler->getMarketPrices())); $this->assertTrue(is_array($this->handler->getIndustryFacilities())); $this->assertTrue(is_array($this->handler->getItemGroups())); $this->assertTrue($this->handler->getItemGroup(40) instanceof stdClass); $this->assertTrue(is_array($this->handler->getAlliances())); $this->assertTrue($this->handler->getAlliance(99000652) instanceof stdClass); $this->assertTrue(is_array($this->handler->getItemTypes())); $this->assertTrue($this->handler->getType(35) instanceof stdClass); $this->assertTrue(is_array($this->handler->getItemCategories())); $this->assertTrue($this->handler->getItemCategory(5) instanceof stdClass); $this->assertTrue(is_array($this->handler->getMarketGroups())); $this->assertTrue($this->handler->getMarketGroup(2) instanceof stdClass); $this->assertTrue(is_array($this->handler->getMarketGroupTypes(2))); $this->assertTrue(is_array($this->handler->getTournaments())); $this->assertTrue($this->handler->getWar(1) instanceof stdClass); $this->assertTrue($this->handler->getKillmail('http://public-crest.eveonline.com/killmails/30290604/787fb3714062f1700560d4a83ce32c67640b1797/') instanceof stdClass); }