Skip to content
Permalink
Browse files

Fix for breaking ESI changes: Resolve entity IDs using universe/names

  • Loading branch information...
Salvoxia committed Jun 19, 2018
1 parent 0f35526 commit 12431ca96e790eae2692601a25bdea85eb668dad
Showing with 3 additions and 143 deletions.
  1. +3 −10 common/includes/class.esiparser.php
  2. +0 −133 common/includes/esi/class.helpers.php
@@ -813,16 +813,9 @@ protected function getEntityIds($EsiKill)
if(!is_null($factionId) && !in_array($factionId, $factionIds)) $factionIds[] = $factionId;
}
// using universe/names endpoint
// $entityIds = array_merge($characterIds, $corporationIds, $allianceIds);
// $idToNameMap = ESI_Helpers::resolveEntityIds($entityIds);
// using separate endpoints (slower, but more reliable in case CCP messes with universe/names again)
$characterIdNameMap = ESI_Helpers::resolveCharacterIds($characterIds);
$corporationIdNameMap = ESI_Helpers::resolveCorporationIds($corporationIds);
$allianceIdNameMap = ESI_Helpers::resolveAllianceIds($allianceIds);
// merge mappings
$idToNameMap = $characterIdNameMap + $corporationIdNameMap + $allianceIdNameMap;
// using universe/names endpoint
$entityIds = array_merge($characterIds, $corporationIds, $allianceIds);
$idToNameMap = ESI_Helpers::resolveEntityIds($entityIds);
// now resolve factions
foreach($factionIds as $factionId)
@@ -181,139 +181,6 @@ public static function resolveEntityIds($entityIds)
}
/**
* The same as {@link ESI_Helpers::resolveEntityIds($entityIds)}, but
* only works for character IDs and uses a different ESI endpoint.
*
* @param int[] $characterIds an array of entity IDs
* @return array an indexed array, using the input IDs as index
*
* @throws \Swagger\Client\ApiException on ESI communication error
*/
public static function resolveCharacterIds($characterIds)
{
self::initCacheHandler();
// create mapping
$idNameMapping = array();
// resolve as many IDs as possible using local cache
self::resolveEntityIdsFromCache($characterIds, $idNameMapping);
// create ESI client
$EdkEsi = new ESI();
// bulk resolve character IDs
$CharacterApi = new CharacterApi($EdkEsi);
while(count($characterIds) > 0)
{
// since this is a GET call, we need to observe the maximum URL length;
// however, the endpoint only accepts < 100 IDs (manually tested with corporation endpoint, not documented) IDs at once, which will
// keep us below the URL length limit
$characterIdsForSingleCall = array();
while(count($characterIdsForSingleCall) <= 90 && count($characterIds) > 0)
{
$characterId = array_pop($characterIds);
$characterIdsForSingleCall[] = $characterId;
}
$characterNames = $CharacterApi->getCharactersNames($characterIdsForSingleCall);
foreach($characterNames as $characterName)
{
$idNameMapping[$characterName->getCharacterId()] = $characterName->getCharacterName();
self::putIdNameMappingIntoCache($characterName->getCharacterId(), $characterName->getCharacterName(), 'character');
}
}
return $idNameMapping;
}
/**
* The same as {@link ESI_Helpers::resolveEntityIds($entityIds)}, but
* only works for corporation IDs and uses a different ESI endpoint.
*
* @param int[] $corporationIds an array of entity IDs
* @return array an indexed array, using the input IDs as index
*
* @throws \Swagger\Client\ApiException on ESI communication error
*/
public static function resolveCorporationIds($corporationIds)
{
self::initCacheHandler();
// create mapping
$idNameMapping = array();
// resolve as many IDs as possible using local cache
self::resolveEntityIdsFromCache($corporationIds, $idNameMapping);
// create ESI client
$EdkEsi = new ESI();
$CorporationApi = new CorporationApi($EdkEsi);
while(count($corporationIds) > 0)
{
// since this is a GET call, we need to observe the maximum URL length;
// however, the endpoint only accepts < 100 IDs (manually tested with corporation endpoint, not documented) IDs at once, which will
// keep us below the URL length limit
$corporationIdsForSingleCall = array();
while(count($corporationIdsForSingleCall) <= 90 && count($corporationIds) > 0)
{
$corporationId = array_pop($corporationIds);
$corporationIdsForSingleCall[] = $corporationId;
}
$corporationNames = $CorporationApi->getCorporationsNames($corporationIdsForSingleCall);
foreach($corporationNames as $corporationName)
{
$idNameMapping[$corporationName->getCorporationId()] = $corporationName->getCorporationName();
self::putIdNameMappingIntoCache($corporationName->getCorporationId(), $corporationName->getCorporationName(), 'corporation');
}
}
return $idNameMapping;
}
/**
* The same as {@link ESI_Helpers::resolveEntityIds($entityIds)}, but
* only works for alliance IDs and uses a different ESI endpoint.
*
* @param int[] $allianceIds an array of entity IDs
* @return array an indexed array, using the input IDs as index
*
* @throws \Swagger\Client\ApiException on ESI communication error
*/
public static function resolveAllianceIds($allianceIds)
{
self::initCacheHandler();
// create mapping
$idNameMapping = array();
// resolve as many IDs as possible using local cache
self::resolveEntityIdsFromCache($allianceIds, $idNameMapping);
// create ESI client
$EdkEsi = new ESI();
$AllianceApi = new AllianceApi($EdkEsi);
while(count($allianceIds) > 0)
{
// since this is a GET call, we need to observe the maximum URL length;
// however, the endpoint only accepts < 100 IDs (manually tested with corporation endpoint, not documented) IDs at once, which will
// keep us below the URL length limit
$allianceIdsForSingleCall = array();
while(count($allianceIdsForSingleCall) <= 90 && count($allianceIds) > 0)
{
$allianceId = array_pop($allianceIds);
$allianceIdsForSingleCall[] = $allianceId;
}
$allianceNames = $AllianceApi->getAlliancesNames($allianceIdsForSingleCall);
foreach($allianceNames as $allianceName)
{
$idNameMapping[$allianceName->getAllianceId()] = $allianceName->getAllianceName();
self::putIdNameMappingIntoCache($allianceName->getAllianceId(), $allianceName->getAllianceName(), 'alliance');
}
}
return $idNameMapping;
}
/**
* Tries to look up the given entity IDs in the local cache to resolve to a name.
* <br>

0 comments on commit 12431ca

Please sign in to comment.
You can’t perform that action at this time.