public static function Update() { BaseApi::bootstrap(); $scope = 'Eve'; $api = 'AllianceList'; // Prepare the Pheal instance $pheal = new Pheal(); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $alliance_list = $pheal->eveScope->AllianceList(); } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $alliance_list->cached_until)) { // Really crappy method to do this I guess. But oh well. \EveEveAllianceListMemberCorporations::truncate(); foreach ($alliance_list->alliances as $alliance) { $alliance_check = \EveEveAllianceList::where('allianceID', '=', $alliance->allianceID)->first(); if (!$alliance_check) { $alliance_data = new \EveEveAllianceList(); } else { $alliance_data = $alliance_check; } $alliance_data->name = $alliance->name; $alliance_data->shortName = $alliance->shortName; $alliance_data->allianceID = $alliance->allianceID; $alliance_data->executorCorpID = $alliance->executorCorpID; $alliance_data->memberCount = $alliance->memberCount; $alliance_data->startDate = $alliance->startDate; $alliance_data->save(); $alliance_data->save(); // And repopulate the current members foreach ($alliance->memberCorporations as $corporation) { $member_corp = new \EveEveAllianceListMemberCorporations(); $member_corp->corporationID = $corporation->corporationID; $member_corp->startDate = $corporation->startDate; $alliance_data->members()->save($member_corp); } } // Set the cached entry time BaseApi::setDbCache($scope, $api, $alliance_list->cached_until); } return $alliance_list; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Account'; $api = 'AccountStatus'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Need to check that this is not a Corporation Key... // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $status_info = $pheal->accountScope->AccountStatus(); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $status_info->cached_until, $keyID)) { $check_status = \EveAccountAccountStatus::where('keyID', '=', $keyID)->first(); if (!$check_status) { $status_data = new \EveAccountAccountStatus(); } else { $status_data = $check_status; } $status_data->keyID = $keyID; $status_data->paidUntil = $status_info->paidUntil; $status_data->createDate = $status_info->createDate; $status_data->logonCount = $status_info->logonCount; $status_data->logonMinutes = $status_info->logonMinutes; $status_data->save(); // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $status_info->cached_until, $keyID); } return $status_info; }
public static function Update() { BaseApi::bootstrap(); $scope = 'Map'; $api = 'Sovereignty'; // Prepare the Pheal instance $pheal = new Pheal(); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $sovereignty = $pheal->mapScope->Sovereignty(); } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $sovereignty->cached_until)) { // Update the Database while we loop over the solarSystem results foreach ($sovereignty->solarSystems as $solarSystem) { // Find the system to check if we need to update || insert $system = \EveMapSovereignty::where('solarSystemID', '=', $solarSystem->solarSystemID)->first(); if (!$system) { $system_data = new \EveMapSovereignty(); } else { $system_data = $system; } // Update the system $system_data->solarSystemID = $solarSystem->solarSystemID; $system_data->allianceID = $solarSystem->allianceID; $system_data->factionID = $solarSystem->factionID; $system_data->solarSystemName = $solarSystem->solarSystemName; $system_data->corporationID = $solarSystem->corporationID; $system_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $sovereignty->cached_until); } return $sovereignty; }
public static function Update() { BaseApi::bootstrap(); $scope = 'Server'; $api = 'ServerStatus'; // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope)) { $lockhash = BaseApi::lockCall($api, $scope); } else { return; } // Do the call $pheal = new Pheal(); try { $server_status = $pheal->serverScope->ServerStatus(); } catch (Exception $e) { throw $e; } if (!BaseApi::checkDbCache($scope, $api, $server_status->cached_until)) { // Update the Database $existing_status = \EveServerServerStatus::find(1); if (isset($existing_status)) { // Update the ServerStatus $existing_status->currentTime = $server_status->request_time; $existing_status->serverOpen = $server_status->serverOpen; $existing_status->onlinePlayers = $server_status->onlinePlayers; $existing_status->save(); } else { // Create a ServerStatus entry \EveServerServerStatus::create(array('currentTime' => $server_status->request_time, 'serverOpen' => $server_status->serverOpen, 'onlinePlayers' => $server_status->onlinePlayers)); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $server_status->cached_until); } // Unlock the call BaseApi::unlockCall($lockhash); return $server_status; }
public static function Update() { BaseApi::bootstrap(); $scope = 'Eve'; $api = 'ConquerableStationList'; // Prepare the Pheal instance $pheal = new Pheal(); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $station_list = $pheal->eveScope->ConquerableStationList(); } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $station_list->cached_until)) { // Update the Database while we loop over the results foreach ($station_list->outposts as $outpost) { // Check if we need to update || insert $outpost_check = \EveEveConquerableStationList::where('stationID', '=', $outpost->stationID)->first(); if (!$outpost_check) { $outpost_data = new \EveEveConquerableStationList(); } else { $outpost_data = $outpost_check; } $outpost_data->stationID = $outpost->stationID; $outpost_data->stationName = $outpost->stationName; $outpost_data->stationTypeID = $outpost->stationTypeID; $outpost_data->solarSystemID = $outpost->solarSystemID; $outpost_data->corporationID = $outpost->corporationID; $outpost_data->corporationName = $outpost->corporationName; $outpost_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $station_list->cached_until); } return $station_list; }
public static function Update() { BaseApi::bootstrap(); $scope = 'Eve'; $api = 'RefTypes'; // Prepare the Pheal instance $pheal = new Pheal(); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $ref_types = $pheal->eveScope->RefTypes(); } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $ref_types->cached_until)) { // Update the Database while we loop over the results foreach ($ref_types->refTypes as $ref_type) { // Check if we need to update || insert $type_check = \EveEveRefTypes::where('refTypeID', '=', $ref_type->refTypeID)->first(); if (!$type_check) { $type_data = new \EveEveRefTypes(); } else { $type_data = $type_check; } // Update the system $type_data->refTypeID = $ref_type->refTypeID; $type_data->refTypeName = $ref_type->refTypeName; $type_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $ref_types->cached_until); } return $ref_types; }
public static function Update() { BaseApi::bootstrap(); $scope = 'Eve'; $api = 'ErrorList'; // Prepare the Pheal instance $pheal = new Pheal(); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $error_list = $pheal->eveScope->ErrorList(); } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $error_list->cached_until)) { // Update the Database while we loop over the solarSystem results foreach ($error_list->errors as $error) { // Find the system to check if we need to update || insert $error_check = \EveEveErrorList::where('errorCode', '=', $error->errorCode)->first(); if (!$error_check) { $error_data = new \EveEveErrorList(); } else { $error_data = $error_check; } // Update the system $error_data->errorCode = $error->errorCode; $error_data->errorText = $error->errorText; $error_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $error_list->cached_until); } return $error_list; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'Standings'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $standings = $pheal->charScope->Standings(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $standings->cached_until, $characterID)) { // Populate the agents standings for this character foreach ($standings->characterNPCStandings->agents as $standing) { $standing_data = \EveCharacterStandingsAgents::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first(); if (!$standing_data) { $standing_data = new \EveCharacterStandingsAgents(); } $standing_data->characterID = $characterID; $standing_data->fromID = $standing->fromID; $standing_data->fromName = $standing->fromName; $standing_data->standing = $standing->standing; $standing_data->save(); } // Populate the faction standings for this character foreach ($standings->characterNPCStandings->factions as $standing) { $standing_data = \EveCharacterStandingsFactions::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first(); if (!$standing_data) { $standing_data = new \EveCharacterStandingsFactions(); } $standing_data->characterID = $characterID; $standing_data->fromID = $standing->fromID; $standing_data->fromName = $standing->fromName; $standing_data->standing = $standing->standing; $standing_data->save(); } // Populate the NPCCorporation standings for this character foreach ($standings->characterNPCStandings->NPCCorporations as $standing) { $standing_data = \EveCharacterStandingsNPCCorporations::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first(); if (!$standing_data) { $standing_data = new \EveCharacterStandingsNPCCorporations(); } $standing_data->characterID = $characterID; $standing_data->fromID = $standing->fromID; $standing_data->fromName = $standing->fromName; $standing_data->standing = $standing->standing; $standing_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $standings->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $standings; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'MemberMedals'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $medals = $pheal->corpScope->MemberMedals(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $medals->cached_until, $corporationID)) { foreach ($medals->issuedMedals as $medal) { $medal_data = \EveCorporationMemberMedals::where('corporationID', '=', $corporationID)->where('medalID', '=', $medal->medalID)->where('characterID', '=', $medal->characterID)->first(); if (!$medal_data) { $medal_data = new \EveCorporationMemberMedals(); } $medal_data->corporationID = $corporationID; $medal_data->medalID = $medal->medalID; $medal_data->characterID = $medal->characterID; $medal_data->reason = $medal->reason; $medal_data->status = $medal->status; $medal_data->issuerID = $medal->issuerID; $medal_data->issued = $medal->issued; $medal_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $medals->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $medals; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'Notifications'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $notifications = $pheal->charScope->Notifications(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $notifications->cached_until, $characterID)) { // Loop over the list we got from the api and update the db, // remebering the messageID's for downloading the bodies too $texts = array(); foreach ($notifications->notifications as $notification) { $notification_data = \EveCharacterNotifications::where('characterID', '=', $characterID)->where('notificationID', '=', $notification->notificationID)->first(); if (!$notification_data) { $new_notification = new \EveCharacterNotifications(); $texts[] = $notification->notificationID; // Record the notificationID to download later } else { // Check if we have the body for this existing message, else // we will add it to the list to download if (!\EveCharacterNotificationTexts::where('notificationID', '=', $notification->notificationID)) { $texts[] = $notification->notificationID; } continue; } $new_notification->characterID = $characterID; $new_notification->notificationID = $notification->notificationID; $new_notification->typeID = $notification->typeID; $new_notification->senderID = $notification->senderID; $new_notification->senderName = $notification->senderName; $new_notification->sentDate = $notification->sentDate; $new_notification->read = $notification->read; $new_notification->save(); } // Split the text we need to download into chunks of 10 each. Pheal-NG will // log the whole request as a file name for chaching... // which is tooooooo looooooooooooong $texts = array_chunk($texts, 10); // Iterate over the chunks. foreach ($texts as $chunk) { try { $notification_texts = $pheal->charScope->NotificationTexts(array('characterID' => $characterID, 'ids' => implode(',', $chunk))); } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Loop over the received texts foreach ($notification_texts->notifications as $text) { // Actually, this check is pretty redundant, so maybe remove it $text_data = \EveCharacterNotificationTexts::where('notificationID', '=', $text->notificationID)->first(); if (!$text_data) { $new_text = new \EveCharacterNotificationTexts(); } else { continue; } $new_text->notificationID = $text->notificationID; $new_text->text = $text->__toString(); $new_text->save(); } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $notifications->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $notifications; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'AssetList'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $asset_list = $pheal->corpScope->AssetList(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $asset_list->cached_until, $corporationID)) { // TODO: Look as how we update this. As per https://neweden-dev.com/Character/Asset_List, the itemID // may change. So, we cant really just update existing ids. For now, we just trash all and recreate the // assets :< // Maybe do this in one big transaction? lel \EveCorporationAssetList::where('corporationID', '=', $corporationID)->delete(); \EveCorporationAssetListContents::where('corporationID', '=', $corporationID)->delete(); // Note about /corp/Locations // // We will build a list of itemID's to update the location information about // while we loop over the assets. This will be stored in location_retreive and // processed here [1] $location_retreive = array(); // Populate the assets for this corporation as well as the contents. foreach ($asset_list->assets as $asset) { // Add the asset to the location retreival array $location_retreive[] = $asset->itemID; // Process the rest of the database population $asset_data = new \EveCorporationAssetList(); $asset_data->corporationID = $corporationID; $asset_data->itemID = $asset->itemID; $asset_data->locationID = $asset->locationID; $asset_data->typeID = $asset->typeID; $asset_data->quantity = $asset->quantity; $asset_data->flag = $asset->flag; $asset_data->singleton = $asset->singleton; $asset_data->save(); // Process the contents if there are any if (isset($asset->contents)) { foreach ($asset->contents as $content) { $content_data = new \EveCorporationAssetListContents(); $content_data->corporationID = $corporationID; $content_data->itemID = $asset_data->itemID; $content_data->typeID = $content->typeID; $content_data->quantity = $content->quantity; $content_data->flag = $content->flag; $content_data->singleton = $content->singleton; $content_data->rawQuantity = isset($content->rawQuantity) ? $content->rawQuantity : 0; $asset_data->contents()->save($content_data); } } } // Now empty and process the locations as per [1] \EveCorporationAssetListLocations::where('corporationID', '=', $corporationID)->delete(); $location_retreive = array_chunk($location_retreive, 1); // Iterate over the chunks. foreach ($location_retreive as $chunk) { try { $locations = $pheal->corpScope->Locations(array('characterID' => $characters[0], 'ids' => implode(',', $chunk))); } catch (\Pheal\Exceptions\PhealException $e) { // Temp hack to check the asset list thingie // TBH, I am not 100% sure yet why the freaking call would fail for a id we **just** // got from the previous API call... if ($e->getCode() == 135 || $e->getCode() == 221) { // 135 "not the owner" | 221 "illegal page request" continue; } else { throw $e; } } // Loop over the locations, check their closest celestial // and add the data to the database foreach ($locations->locations as $location) { $closest_moon = BaseApi::findClosestMoon($location->itemID, $location->x, $location->y, $location->z); $location_data = new \EveCorporationAssetListLocations(); $location_data->corporationID = $corporationID; $location_data->itemID = $location->itemID; $location_data->itemName = $location->itemName; $location_data->x = $location->x; $location_data->y = $location->y; $location_data->z = $location->z; $location_data->mapID = $closest_moon['id']; $location_data->mapName = $closest_moon['name']; $location_data->save(); } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $asset_list->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $asset_list; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'SkillQueue'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $skill_queue = $pheal->charScope->SkillQueue(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $skill_queue->cached_until, $characterID)) { // Remove the current Queue \EveCharacterSkillQueue::where('characterID', '=', $characterID)->delete(); // Add the current queue information foreach ($skill_queue->skillqueue as $queue) { // Start a new queue entry for this character $character_data = new \EveCharacterSkillQueue(); // And populate the fields for him. $character_data->characterID = $characterID; $character_data->queuePosition = $queue->queuePosition; $character_data->typeID = $queue->typeID; $character_data->level = $queue->level; $character_data->startSP = $queue->startSP; $character_data->endSP = $queue->endSP; $character_data->startTime = strlen($queue->startTime) > 0 ? $queue->startTime : null; $character_data->endTime = strlen($queue->endTime) > 0 ? $queue->endTime : null; $character_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $skill_queue->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $skill_queue; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'MemberTracking'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $member_tracking = $pheal->corpScope->MemberTracking(array('characterID' => $characters[0], 'extended' => 1)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $member_tracking->cached_until, $corporationID)) { // Get a list of the current corporation members. Once we are done with the member // updates, we will just go and delete the members that are left in this array, assuming // that they are no longer in this corporation. $existing_members = array(); foreach (\EveCorporationMemberTracking::where('corporationID', $corporationID)->get() as $member) { $existing_members[] = $member->characterID; } // Flip the array so that the keys are the characterID's $existing_members = array_flip($existing_members); // Process the results from the API call foreach ($member_tracking->members as $member) { $member_data = \EveCorporationMemberTracking::where('characterID', '=', $member->characterID)->where('corporationID', '=', $corporationID)->first(); if (!$member_data) { $member_data = new \EveCorporationMemberTracking(); } $member_data->characterID = $member->characterID; $member_data->corporationID = $corporationID; $member_data->name = $member->name; $member_data->startDateTime = $member->startDateTime; $member_data->baseID = $member->baseID; $member_data->base = $member->base; $member_data->title = $member->title; $member_data->logonDateTime = $member->logonDateTime; $member_data->logoffDateTime = $member->logoffDateTime; $member_data->locationID = $member->locationID; $member_data->location = $member->location; $member_data->shipTypeID = $member->shipTypeID; $member_data->shipType = $member->shipType; $member_data->roles = $member->roles; $member_data->grantableRoles = $member->grantableRoles; $member_data->save(); // Remove this member from the existing members unset($existing_members[$member->characterID]); } // Next, remove the members that were not in the API call. if (count($existing_members) > 0) { \EveCorporationMemberTracking::whereIn('characterID', array_keys($existing_members))->delete(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $member_tracking->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $member_tracking; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'AccountBalance'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $account_balance = $pheal->charScope->AccountBalance(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $account_balance->cached_until, $characterID)) { // While we _know_ that there should only be one account for characters // aka account 1000, lets loop anyways. You never know what CCP might do // next :) foreach ($account_balance->accounts as $account) { $check_account = \EveCharacterAccountBalance::where('characterID', '=', $characterID)->where('accountID', '=', $account->accountID)->first(); if (!$check_account) { $account_data = new \EveCharacterAccountBalance(); } else { $account_data = $check_account; } $account_data->characterID = $characterID; $account_data->accountID = $account->accountID; $account_data->accountKey = $account->accountKey; $account_data->balance = $account->balance; $account_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $account_balance->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $account_balance; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'MarketOrders'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $market_orders = $pheal->charScope->MarketOrders(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $market_orders->cached_until, $characterID)) { foreach ($market_orders->orders as $order) { $order_data = \EveCharacterMarketOrders::where('characterID', '=', $characterID)->where('orderID', '=', $order->orderID)->first(); if (!$order_data) { $order_info = new \EveCharacterMarketOrders(); } else { $order_info = $order_data; } $order_info->characterID = $characterID; $order_info->orderID = $order->orderID; $order_info->charID = $order->charID; $order_info->stationID = $order->stationID; $order_info->volEntered = $order->volEntered; $order_info->volRemaining = $order->volRemaining; $order_info->minVolume = $order->minVolume; $order_info->orderState = $order->orderState; $order_info->typeID = $order->typeID; $order_info->range = $order->range; $order_info->duration = $order->duration; $order_info->escrow = $order->escrow; $order_info->price = $order->price; $order_info->bid = $order->bid; $order_info->issued = $order->issued; $order_info->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $market_orders->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $market_orders; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); $scope = 'Account'; $api = 'APIKeyInfo'; // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $key_info = $pheal->accountScope->APIKeyInfo(); } catch (\Pheal\Exceptions\APIException $e) { // Some API responses require some rather important actions // SeATs perspective. For eg. Expired keys, IP bans, rate // limits etc. As APIKeyInfo is probably one of the // most called eveapi Updater, we will add the // logic here to check for these types of // responses. // Source: https://api.eveonline.com/Eve/ErrorList.xml.aspx switch ($e->getCode()) { // "API key authentication failure." case 202: // "Authentication failure." // "Authentication failure." case 203: case 204: // "Authentication failure." // "Authentication failure." case 205: // "Authentication failure." // "Authentication failure." case 210: // "Authentication failure (final pass)." // "Authentication failure (final pass)." case 212: // The API is probably entirely wrong. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Invalid Corporation Key. Key owner does not fullfill role // requirements anymore." // "Invalid Corporation Key. Key owner does not fullfill role // requirements anymore." case 220: // Owner of the corporation key doesnt have hes roles anymore? BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Illegal page request! Please verify the access granted by the key you are using!." // "Illegal page request! Please verify the access granted by the key you are using!." case 221: // Not 100% sure how to handle this one. This call has no // access mask requirement... return; // "Key has expired. Contact key owner for access renewal." // "Key has expired. Contact key owner for access renewal." case 222: // We have a invalid key. Expired or deleted. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Authentication failure. Legacy API keys can no longer be // used. Please create a new key on support.eveonline.com // and make sure your application supports Customizable // API Keys." // "Authentication failure. Legacy API keys can no longer be // used. Please create a new key on support.eveonline.com // and make sure your application supports Customizable // API Keys." case 223: // The API we are working with is waaaaaay too old. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Web site database temporarily disabled." // "Web site database temporarily disabled." case 901: // The EVE API Database is apparently down, so mark the // server as 'down' in the cache so that subsequent // calls don't fail because of this. \Cache::put('eve_api_down', true, 30); return; // "EVE backend database temporarily disabled."" // "EVE backend database temporarily disabled."" case 902: // The EVE API Database is apparently down, so mark the // server as 'down' in the cache so that subsequent // calls don't fail because of this. \Cache::put('eve_api_down', true, 30); return; // "Your IP address has been temporarily blocked because it // is causing too many errors. See the cacheUntil // timestamp for when it will be opened again. // IPs that continually cause a lot of errors // in the API will be permanently banned, // please take measures to minimize // problematic API calls from your // application." // "Your IP address has been temporarily blocked because it // is causing too many errors. See the cacheUntil // timestamp for when it will be opened again. // IPs that continually cause a lot of errors // in the API will be permanently banned, // please take measures to minimize // problematic API calls from your // application." case 904: // If we are rate limited, set the status of the eveapi // server to 'down' in the cache so that subsequent // calls don't fail because of this. // Get time of IP ban in minutes, rounded up to the next whole minute $time = round(($e->cached_until_unixtime - $e->request_time_unixtime) / 60, 0, PHP_ROUND_HALF_UP); \Cache::put('eve_api_down', true, $time); return; // We got a problem we don't know what to do with, so log // and throw the exception so that the can debug it. // We got a problem we don't know what to do with, so log // and throw the exception so that the can debug it. default: \Log::error('Call to APIKeyInfo for ' . $keyID . ' failed with: ' . $e->getCode() . ':' . $e->getMessage(), array('src' => __CLASS__)); throw $e; break; } // Process a ban request as needed BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $key_info->cached_until, $keyID)) { $key_data = \EveAccountAPIKeyInfo::where('keyID', '=', $keyID)->first(); if (!$key_data) { $key_data = new \EveAccountAPIKeyInfo(); } $key_data->keyID = $keyID; $key_data->accessMask = $key_info->key->accessMask; $key_data->type = $key_info->key->type; $key_data->expires = strlen($key_info->key->expires) > 0 ? $key_info->key->expires : null; // hack much? $key_data->save(); // Check if we have any knowledge of any characters for this key. We will remove values from this // array as we move along to determine which characters we should delete that are possibly no // longer on this key $known_characters = array(); foreach (\EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->get() as $character) { $known_characters[] = $character->characterID; } $known_characters = array_flip($known_characters); // Update the key characters foreach ($key_info->key->characters as $character) { // Check if we need to update || insert $character_data = \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $character->characterID)->first(); if (!$character_data) { $character_data = new \EveAccountAPIKeyInfoCharacters(); } // else, add/update $character_data->characterID = $character->characterID; $character_data->characterName = $character->characterName; $character_data->corporationID = $character->corporationID; $character_data->corporationName = $character->corporationName; $key_data->characters()->save($character_data); // Remove this characterID from the known_characters as its still on // the key if (array_key_exists($character->characterID, $known_characters)) { unset($known_characters[$character->characterID]); } } // Delete the characters that are no longer part of this key foreach (array_flip($known_characters) as $oldcharacter) { \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $oldcharacter)->delete(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $key_info->cached_until, $keyID); } return $key_info; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'SkillInTraining'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $skill_in_training = $pheal->charScope->SkillInTraining(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $skill_in_training->cached_until, $characterID)) { $character_data = \EveCharacterSkillInTraining::where('characterID', '=', $characterID)->first(); if (!$character_data) { $character_data = new \EveCharacterSkillInTraining(); } if ($skill_in_training->skillInTraining == 1) { $character_data->characterID = $characterID; $character_data->currentTQTime = $skill_in_training->currentTQTime->_value; $character_data->trainingEndTime = $skill_in_training->trainingEndTime; $character_data->trainingStartTime = $skill_in_training->trainingStartTime; $character_data->trainingTypeID = $skill_in_training->trainingTypeID; $character_data->trainingStartSP = $skill_in_training->trainingStartSP; $character_data->trainingDestinationSP = $skill_in_training->trainingDestinationSP; $character_data->trainingToLevel = $skill_in_training->trainingToLevel; $character_data->skillInTraining = $skill_in_training->skillInTraining; $character_data->save(); } else { $character_data->characterID = $characterID; $character_data->skillInTraining = 0; $character_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $skill_in_training->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $skill_in_training; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'CorporationSheet'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $corporation_sheet = $pheal->corpScope->CorporationSheet(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID)) { $corporation_data = \EveCorporationCorporationSheet::where('corporationID', '=', $corporationID)->first(); if (!$corporation_data) { $corporation_data = new \EveCorporationCorporationSheet(); } $corporation_data->corporationID = $corporation_sheet->corporationID; $corporation_data->corporationName = $corporation_sheet->corporationName; $corporation_data->ticker = $corporation_sheet->ticker; $corporation_data->ceoID = $corporation_sheet->ceoID; $corporation_data->ceoName = $corporation_sheet->ceoName; $corporation_data->stationID = $corporation_sheet->stationID; $corporation_data->stationName = $corporation_sheet->stationName; $corporation_data->description = $corporation_sheet->description; $corporation_data->url = $corporation_sheet->url; $corporation_data->allianceID = $corporation_sheet->allianceID; $corporation_data->factionID = $corporation_sheet->factionID; $corporation_data->allianceName = $corporation_sheet->allianceName; $corporation_data->taxRate = $corporation_sheet->taxRate; $corporation_data->memberCount = $corporation_sheet->memberCount; $corporation_data->memberLimit = $corporation_sheet->memberLimit; $corporation_data->shares = $corporation_sheet->shares; $corporation_data->graphicID = $corporation_sheet->logo->graphicID; $corporation_data->shape1 = $corporation_sheet->logo->shape1; $corporation_data->shape2 = $corporation_sheet->logo->shape2; $corporation_data->shape3 = $corporation_sheet->logo->shape3; $corporation_data->color1 = $corporation_sheet->logo->color1; $corporation_data->color2 = $corporation_sheet->logo->color2; $corporation_data->color3 = $corporation_sheet->logo->color3; $corporation_data->corporationID = $corporation_sheet->corporationID; $corporation_data->save(); // Update the Divisions foreach ($corporation_sheet->divisions as $division) { $division_data = \EveCorporationCorporationSheetDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first(); if (!$division_data) { $division_data = new \EveCorporationCorporationSheetDivisions(); } $division_data->corporationID = $corporationID; $division_data->accountKey = $division->accountKey; $division_data->description = $division->description; $corporation_data->divisions()->save($division_data); } // Update the Wallet Divisions foreach ($corporation_sheet->walletDivisions as $division) { $division_data = \EveCorporationCorporationSheetWalletDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first(); if (!$division_data) { $division_data = new \EveCorporationCorporationSheetWalletDivisions(); } $division_data->corporationID = $corporationID; $division_data->accountKey = $division->accountKey; $division_data->description = $division->description; $corporation_data->walletdivisions()->save($division_data); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $corporation_sheet; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'MemberSecurity'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $member_security = $pheal->corpScope->MemberSecurity(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $member_security->cached_until, $corporationID)) { foreach ($member_security->members as $security) { // Update order: // a) roles // b) grantableRoles // c) rolesAtHQ // d) grantableRolesAtHQ // e) rolesAtBase // f) grantableRolesAtBase // g) rolesAtOther // h) grantableRolesAtOther // i) titles // // The roles get deleted, and re-inserted based on the API response. Pretty shit way of // doing it I guess :< // a) Roles Update \EveCorporationMemberSecurityRoles::where('characterID', '=', $security->characterID)->delete(); foreach ($security->roles as $role) { $roles_data = new \EveCorporationMemberSecurityRoles(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // b) grantableRoles Update \EveCorporationMemberSecurityGrantableRoles::where('characterID', '=', $security->characterID)->delete(); foreach ($security->grantableRoles as $role) { $roles_data = new \EveCorporationMemberSecurityGrantableRoles(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // c) rolesAtHQ Update \EveCorporationMemberSecurityRolesAtHQ::where('characterID', '=', $security->characterID)->delete(); foreach ($security->rolesAtHQ as $role) { $roles_data = new \EveCorporationMemberSecurityRolesAtHQ(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // d) grantableRolesAtHQ Update \EveCorporationMemberSecurityGrantableRolesAtHQ::where('characterID', '=', $security->characterID)->delete(); foreach ($security->grantableRolesAtHQ as $role) { $roles_data = new \EveCorporationMemberSecurityGrantableRolesAtHQ(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // e) rolesAtBase Update \EveCorporationMemberSecurityRolesAtBase::where('characterID', '=', $security->characterID)->delete(); foreach ($security->rolesAtBase as $role) { $roles_data = new \EveCorporationMemberSecurityRolesAtBase(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // f) grantableRolesAtBase Update \EveCorporationMemberSecurityGrantableRolesAtBase::where('characterID', '=', $security->characterID)->delete(); foreach ($security->grantableRolesAtBase as $role) { $roles_data = new \EveCorporationMemberSecurityGrantableRolesAtBase(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // g) rolesAtOther Update \EveCorporationMemberSecurityRolesAtOther::where('characterID', '=', $security->characterID)->delete(); foreach ($security->rolesAtOther as $role) { $roles_data = new \EveCorporationMemberSecurityRolesAtOther(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // h) grantableRolesAtOther Update \EveCorporationMemberSecurityGrantableRolesAtOther::where('characterID', '=', $security->characterID)->delete(); foreach ($security->grantableRolesAtOther as $role) { $roles_data = new \EveCorporationMemberSecurityGrantableRolesAtOther(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->roleID = $role->roleID; $roles_data->roleName = $role->roleName; $roles_data->save(); } // i) titles Update // DUST characters seem to not have the titles attributes in their XML's coming // from the eveapi. So lets first check if the element exists before we attempt // to update it with the new data if (isset($security->titles)) { \EveCorporationMemberSecurityTitles::where('characterID', '=', $security->characterID)->delete(); foreach ($security->titles as $role) { $roles_data = new \EveCorporationMemberSecurityTitles(); $roles_data->characterID = $security->characterID; $roles_data->corporationID = $corporationID; $roles_data->name = $security->name; $roles_data->titleID = $role->titleID; $roles_data->titleName = $role->titleName; $roles_data->save(); } } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $member_security->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $member_security; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'MailingLists'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $mailing_lists = $pheal->charScope->MailingLists(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $mailing_lists->cached_until, $characterID)) { foreach ($mailing_lists->mailingLists as $list) { $list_data = \EveCharacterMailingLists::where('characterID', '=', $characterID)->where('listID', '=', $list->listID)->first(); // Start a new \EveCharacterMailingLists instance, else, just continue. // Doesn't look like ML's can be renamed, and we want to keep old ones // to be able to lookup old ML id's. if (!$list_data) { $new_list = new \EveCharacterMailingLists(); } else { continue; } $new_list->characterID = $characterID; $new_list->listID = $list->listID; $new_list->displayName = $list->displayName; $new_list->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $mailing_lists->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $mailing_lists; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'MemberSecurityLog'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $member_security_log = $pheal->corpScope->MemberSecurityLog(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $member_security_log->cached_until, $corporationID)) { foreach ($member_security_log->roleHistory as $log) { // Generate a log hash to lookup $loghash = md5(implode(',', array($log->changeTime, $log->characterID, $log->roleLocationType))); $log_data = \EveCorporationMemberSecurityLog::where('hash', '=', $loghash)->first(); if (!$log_data) { $log_data = new \EveCorporationMemberSecurityLog(); } else { // We already have this log entry recorded, so just move along continue; } // Record the log entry $log_data->corporationID = $corporationID; $log_data->characterID = $log->characterID; $log_data->characterName = $log->characterName; $log_data->changeTime = $log->changeTime; $log_data->issuerID = $log->issuerID; $log_data->issuerName = $log->issuerName; $log_data->roleLocationType = $log->roleLocationType; $log_data->hash = $loghash; $log_data->save(); // Generate the oldRoles & newRoles entries. Well just make some // lazy ass json entries. $oldRoles = array(); foreach ($log->oldRoles as $entry) { $oldRoles[$entry->roleID] = $entry->roleName; } $newRoles = array(); foreach ($log->newRoles as $entry) { $newRoles[$entry->roleID] = $entry->roleName; } // Save the log details $entry_data = new \EveCorporationMemberSecurityLogDetails(); $entry_data->hash = $loghash; $entry_data->oldRoles = json_encode($oldRoles); $entry_data->newRoles = json_encode($newRoles); $log_data->details()->save($entry_data); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $member_security_log->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $member_security_log; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'CharacterSheet'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $character_sheet = $pheal->charScope->CharacterSheet(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $character_sheet->cached_until, $characterID)) { $character_data = \EveCharacterCharacterSheet::where('characterID', '=', $characterID)->first(); if (!$character_data) { $new_data = new \EveCharacterCharacterSheet(); } else { $new_data = $character_data; } $new_data->characterID = $character_sheet->characterID; $new_data->name = $character_sheet->name; $new_data->DoB = $character_sheet->DoB; $new_data->race = $character_sheet->race; $new_data->bloodLine = $character_sheet->bloodLine; $new_data->ancestry = $character_sheet->ancestry; $new_data->gender = $character_sheet->gender; $new_data->corporationName = $character_sheet->corporationName; $new_data->corporationID = $character_sheet->corporationID; $new_data->balance = $character_sheet->balance; $new_data->intelligence = $character_sheet->attributes->intelligence; $new_data->memory = $character_sheet->attributes->memory; $new_data->charisma = $character_sheet->attributes->charisma; $new_data->perception = $character_sheet->attributes->perception; $new_data->willpower = $character_sheet->attributes->willpower; // New stuff from Phoebe $new_data->homeStationID = $character_sheet->homeStationID; $new_data->factionName = $character_sheet->factionName; $new_data->factionID = $character_sheet->factionID; $new_data->freeRespecs = $character_sheet->freeRespecs; $new_data->cloneJumpDate = $character_sheet->cloneJumpDate; $new_data->lastRespecDate = $character_sheet->lastRespecDate; $new_data->lastTimedRespec = $character_sheet->lastTimedRespec; $new_data->remoteStationDate = $character_sheet->remoteStationDate; $new_data->jumpActivation = $character_sheet->jumpActivation; $new_data->jumpFatigue = $character_sheet->jumpFatigue; $new_data->jumpLastUpdate = $character_sheet->jumpLastUpdate; // Save the information $new_data->save(); // Update the characters skills foreach ($character_sheet->skills as $skill) { $skill_data = \EveCharacterCharacterSheetSkills::where('characterID', '=', $characterID)->where('typeID', '=', $skill->typeID)->first(); if (!$skill_data) { $skill_info = new \EveCharacterCharacterSheetSkills(); } else { $skill_info = $skill_data; } $skill_info->characterID = $characterID; $skill_info->typeID = $skill->typeID; $skill_info->skillpoints = $skill->skillpoints; $skill_info->level = $skill->level; $skill_info->published = $skill->published; $new_data->skills()->save($skill_info); } // Update the Jump Clones. // First thing we need to do is clear out all of the known clones for // this character. We cant really say that clones will remain, so to // be safe, clear all of the clones, and populate the new ones. // So, lets get to the deletion part. We need to keep in mind that a characterID // my have multiple jumpClones. Each clone in turn may have multiple implants // which in turn are linked back to a jumpClone and then to a chacterID \EveCharacterCharacterSheetJumpClones::where('characterID', $characterID)->delete(); \EveCharacterCharacterSheetJumpCloneImplants::where('characterID', $characterID)->delete(); // Next, loop over the clones we got in the API response foreach ($character_sheet->jumpClones as $jump_clone) { $clone_data = new \EveCharacterCharacterSheetJumpClones(); $clone_data->jumpCloneID = $jump_clone->jumpCloneID; $clone_data->characterID = $characterID; $clone_data->typeID = $jump_clone->typeID; $clone_data->locationID = $jump_clone->locationID; $clone_data->cloneName = $jump_clone->cloneName; $clone_data->save(); } // With the jump clones populated, we move on to the implants per // jump clone. foreach ($character_sheet->jumpCloneImplants as $jump_clone_implants) { $implant_data = new \EveCharacterCharacterSheetJumpCloneImplants(); $implant_data->jumpCloneID = $jump_clone_implants->jumpCloneID; $implant_data->characterID = $characterID; $implant_data->typeID = $jump_clone_implants->typeID; $implant_data->typeName = $jump_clone_implants->typeName; $implant_data->save(); } // Finally, we update the character with the implants that they have. // Again, we can not assume that the implants they had in the // previous update is the same as the current, so, delete // everything and populate again. \EveCharacterCharacterSheetImplants::where('characterID', $characterID)->delete(); // Now, loop over the implants from the API response and populate them. foreach ($character_sheet->implants as $implant) { $implant_data = new \EveCharacterCharacterSheetImplants(); $implant_data->characterID = $characterID; $implant_data->typeID = $implant->typeID; $implant_data->typeName = $implant->typeName; $implant_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $character_sheet->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $character_sheet; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'Contracts'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $contracts = $pheal->corpScope->Contracts(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Before we start looping over the contracts, we need to add some more // logic to this Updater. The ContractItems call seems to be flaky // in the sense that when we call the corp/Contracts API, we get // a list of contractID's. These ID's are checked for existence // in the database and updated accordingly. If its a new // contract, we call ContractItems to get the details. // This is where shit falls apart and :ccp: thiks its // clever to error out for ID's we *JUST* got back. // // So, to reduce the chances of getting the calling IP banned due to // ~reasons~, we will have a local counter to limit the amount of // errors caused by this this call. If we hit this limit, we // return the function, and wait for the next run to update // again. We will also run banCall() so that the global // error counter is also aware of this. $error_limit = 25; // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $contracts->cached_until, $corporationID)) { // Loop over the contracts and update foreach ($contracts->contractList as $contract) { $contract_data = \EveCorporationContracts::where('corporationID', '=', $corporationID)->where('contractID', '=', $contract->contractID)->first(); // If we an existing contract that we are just going to update, then dont bother // running /char/ContractItems. I *think* this will be the same all the time // and can only change by creating a new contract if (!$contract_data) { $new_data = new \EveCorporationContracts(); $get_items = true; // [1] } else { $new_data = $contract_data; $get_items = false; } $new_data->corporationID = $corporationID; $new_data->contractID = $contract->contractID; $new_data->issuerID = $contract->issuerID; $new_data->issuerCorpID = $contract->issuerCorpID; $new_data->assigneeID = $contract->assigneeID; $new_data->acceptorID = $contract->acceptorID; $new_data->startStationID = $contract->startStationID; $new_data->endStationID = $contract->endStationID; $new_data->type = $contract->type; $new_data->status = $contract->status; $new_data->title = strlen($contract->title) > 0 ? $contract->title : null; $new_data->forCorp = $contract->forCorp; $new_data->availability = $contract->availability; $new_data->dateIssued = $contract->dateIssued; $new_data->dateExpired = strlen($contract->dateExpired) > 0 ? $contract->dateExpired : null; $new_data->dateAccepted = strlen($contract->dateAccepted) > 0 ? $contract->dateAccepted : null; $new_data->numDays = $contract->numDays; $new_data->dateCompleted = strlen($contract->dateCompleted) > 0 ? $contract->dateCompleted : null; $new_data->price = $contract->price; $new_data->reward = $contract->reward; $new_data->collateral = $contract->collateral; $new_data->buyout = $contract->buyout; $new_data->volume = $contract->volume; $new_data->save(); // [1] New contracts will have their 'items' updated too. Do it if ($get_items) { try { $contracts_items = $pheal->corpScope->ContractItems(array('characterID' => $characters[0], 'contractID' => $contract->contractID)); // :ccp: Seems to give you a list of ID's for a call, and then // complain seconds later that the itemID is incorrect. This // after we *just* got it from them! ffs. Anyways, we will // process banning here so that the global error counter // in the \Cache::has('eve_api_error_count') can inc // and we dont cause too many exceptions. // // We will also dec the $error_limit and break if we hit 0. } catch (\Pheal\Exceptions\APIException $e) { // Dec $error_limit $error_limit--; // Process the banning for the update of the global eve_api_error_count BaseApi::banCall('ContractItems', $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); // Check the state of the $error_limit and decide what to do if ($error_limit <= 0) { return; } else { continue; } } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Loop over the items in contracts and save it foreach ($contracts_items->itemList as $item) { $items = new \EveCorporationContractsItems(); $items->corporationID = $corporationID; $items->contractID = $contract->contractID; $items->recordID = $item->recordID; $items->typeID = $item->typeID; $items->quantity = $item->quantity; $items->rawQuantity = isset($item->rawQuantity) ? $item->rawQuantity : null; $items->singleton = $item->singleton; $items->included = $item->included; $new_data->items()->save($items); } } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $contracts->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $contracts; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'AssetList'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $asset_list = $pheal->charScope->AssetList(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $asset_list->cached_until, $characterID)) { // TODO: Look as how we update this. As per https://neweden-dev.com/Character/Asset_List, the itemID // may change. So, we cant really just update existing ids. For now, we just trash all and recreate the // assets :< // Maybe do this in one big transaction? lel \EveCharacterAssetList::where('characterID', '=', $characterID)->delete(); \EveCharacterAssetListContents::where('characterID', '=', $characterID)->delete(); // Populate the assets for this character as well as the contents. foreach ($asset_list->assets as $asset) { $asset_data = new \EveCharacterAssetList(); $asset_data->characterID = $characterID; $asset_data->itemID = $asset->itemID; $asset_data->locationID = $asset->locationID; $asset_data->typeID = $asset->typeID; $asset_data->quantity = $asset->quantity; $asset_data->flag = $asset->flag; $asset_data->singleton = $asset->singleton; $asset_data->save(); // Process the contents if there are any if (isset($asset->contents)) { foreach ($asset->contents as $content) { $content_data = new \EveCharacterAssetListContents(); $content_data->characterID = $characterID; $content_data->itemID = $asset_data->itemID; $content_data->typeID = $content->typeID; $content_data->quantity = $content->quantity; $content_data->flag = $content->flag; $content_data->singleton = $content->singleton; $content_data->rawQuantity = isset($content->rawQuantity) ? $content->rawQuantity : 0; $asset_data->contents()->save($content_data); } } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $asset_list->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $asset_list; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'IndustryJobs'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $industry_jobs = $pheal->corpScope->IndustryJobs(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $industry_jobs->cached_until, $corporationID)) { // Populate the jobs for this character foreach ($industry_jobs->jobs as $job) { $job_data = \EveCorporationIndustryJobs::where('corporationID', '=', $corporationID)->where('jobID', '=', $job->jobID)->first(); if (!$job_data) { $job_data = new \EveCorporationIndustryJobs(); } $job_data->corporationID = $corporationID; $job_data->jobID = $job->jobID; $job_data->outputLocationID = $job->outputLocationID; $job_data->installerID = $job->installerID; $job_data->runs = $job->runs; $job_data->activityID = $job->activityID; $job_data->installerName = $job->installerName; $job_data->facilityID = $job->facilityID; $job_data->solarSystemID = $job->solarSystemID; $job_data->solarSystemName = $job->solarSystemName; $job_data->stationID = $job->stationID; $job_data->blueprintID = $job->blueprintID; $job_data->blueprintTypeID = $job->blueprintTypeID; $job_data->blueprintTypeName = $job->blueprintTypeName; $job_data->blueprintLocationID = $job->blueprintLocationID; $job_data->cost = $job->cost; $job_data->teamID = $job->teamID; $job_data->licensedRuns = $job->licensedRuns; $job_data->probability = $job->probability; $job_data->productTypeID = $job->productTypeID; $job_data->productTypeName = $job->productTypeName; $job_data->status = $job->status; $job_data->timeInSeconds = $job->timeInSeconds; $job_data->startDate = $job->startDate; $job_data->endDate = $job->endDate; $job_data->pauseDate = $job->pauseDate; $job_data->completedDate = $job->completedDate; $job_data->completedCharacterID = $job->completedCharacterID; $job_data->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $industry_jobs->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $industry_jobs; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Char'; $api = 'ContactList'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // Next, start our loop over the characters and upate the database foreach ($characters as $characterID) { // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $contact_list = $pheal->charScope->ContactList(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $contact_list->cached_until, $characterID)) { // The ContactList API will potentially return the characters: // a) personal contacts, // b) corporation contacts, // c) alliance contracts. // TODO: Think about maybe doing this in a transaction? // First, the personal contacts // Remove the current contacts \EveCharacterContactList::where('characterID', '=', $characterID)->delete(); // Loop over the list we got from the api and update the db foreach ($contact_list->contactList as $contact) { $new_contact = new \EveCharacterContactList(); $new_contact->characterID = $characterID; $new_contact->contactID = $contact->contactID; $new_contact->contactName = $contact->contactName; $new_contact->inWatchlist = $contact->inWatchlist == True ? 1 : 0; $new_contact->standing = $contact->standing; $new_contact->contactTypeID = $contact->contactTypeID; $new_contact->save(); } // Second, the corporate contacts // Remove the current contacts \EveCharacterContactListCorporate::where('characterID', '=', $characterID)->delete(); // Loop over the list we got from the api and update the db foreach ($contact_list->corporateContactList as $contact) { $new_contact = new \EveCharacterContactListCorporate(); $new_contact->characterID = $characterID; $new_contact->contactID = $contact->contactID; $new_contact->contactName = $contact->contactName; $new_contact->standing = $contact->standing; $new_contact->contactTypeID = $contact->contactTypeID; $new_contact->save(); } // Third, the alliance contacts // Remove the current contacts \EveCharacterContactListAlliance::where('characterID', '=', $characterID)->delete(); // Loop over the list we got from the api and update the db foreach ($contact_list->allianceContactList as $contact) { $new_contact = new \EveCharacterContactListAlliance(); $new_contact->characterID = $characterID; $new_contact->contactID = $contact->contactID; $new_contact->contactName = $contact->contactName; $new_contact->standing = $contact->standing; $new_contact->contactTypeID = $contact->contactTypeID; $new_contact->save(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $contact_list->cached_until, $characterID); } } // Unlock the call BaseApi::unlockCall($lockhash); return $contact_list; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = 'StarbaseList'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $starbase_list = $pheal->corpScope->StarbaseList(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $starbase_list->cached_until, $corporationID)) { // So for this call I dont think we should just trash all of the posses and their // details. Instead, cause I'm bad, well get all of the current posses for the corp // and delete the values that we know of. The resulting array will be the ones we delete // as they are probably removed/killed posses $old_starbases = array(); foreach (\EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->get() as $item) { $old_starbases[] = $item->itemID; } // Arrayflip hax to get the starbaseID's as keys $old_starbases = array_flip($old_starbases); // <-- help a noob please :< // Next, loop over the starbases from the API and populate/update the db foreach ($starbase_list->starbases as $starbase) { $starbase_data = \EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->where('itemID', '=', $starbase->itemID)->first(); if (!$starbase_data) { $starbase_data = new \EveCorporationStarbaseList(); } $starbase_data->corporationID = $corporationID; $starbase_data->itemID = $starbase->itemID; $starbase_data->typeID = $starbase->typeID; $starbase_data->locationID = $starbase->locationID; $starbase_data->moonID = $starbase->moonID; $starbase_data->state = $starbase->state; $starbase_data->stateTimestamp = $starbase->stateTimestamp; $starbase_data->onlineTimestamp = $starbase->onlineTimestamp; $starbase_data->standingOwnerID = $starbase->standingOwnerID; $starbase_data->save(); // Update the old_starbases list by removing the ones that still // exist if (array_key_exists($starbase->itemID, $old_starbases)) { unset($old_starbases[$starbase->itemID]); } } // Delete old starbases if there are any if (count($old_starbases) > 0) { // Delete the old starbase... foreach (array_flip($old_starbases) as $starbase_id) { \EveCorporationStarbaseList::where('itemID', '=', $starbase_id)->delete(); } // ... and its details foreach (array_flip($old_starbases) as $starbase_id) { \EveCorporationStarbaseDetail::where('itemID', '=', $starbase_id)->delete(); } } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $starbase_list->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $starbase_list; }
public static function Update($characterID, $keyID = null, $vCode = null) { BaseApi::bootstrap(); // Check arguements if (!is_int($characterID)) { throw new \Exception('Character is required and must be a integer'); } if (isset($keyID)) { BaseApi::validateKeyPair($keyID, $vCode); } $scope = 'Eve'; $api = 'CharacterInfo'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $character_info = $pheal->eveScope->CharacterInfo(array('characterID' => $characterID)); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get character information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (Exception $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $character_info->cached_until, $characterID)) { // Update the \EveEveCharacterInfo $character_check = \EveEveCharacterInfo::where('characterID', '=', $character_info->characterID)->first(); if (!$character_check) { $character = new \EveEveCharacterInfo(); } else { $character = $character_check; } $character->characterID = $character_info->characterID; $character->characterName = $character_info->characterName; $character->race = $character_info->race; $character->bloodline = $character_info->bloodline; $character->accountBalance = $character_info->accountBalance; $character->skillPoints = $character_info->skillPoints; $character->nextTrainingEnds = $character_info->nextTrainingEnds; $character->shipName = $character_info->shipName; $character->shipTypeID = $character_info->shipTypeID; $character->shipTypeName = $character_info->shipTypeName; $character->corporationID = $character_info->corporationID; $character->corporation = $character_info->corporation; $character->corporationDate = $character_info->corporationDate; $character->allianceID = $character_info->allianceID; $character->alliance = $character_info->alliance; $character->allianceDate = $character_info->allianceDate; $character->lastKnownLocation = $character_info->lastKnownLocation; $character->securityStatus = $character_info->securityStatus; $character->save(); // Update \EveEveCharacterInfoEmploymentHistory foreach ($character_info->employmentHistory as $employment) { $employment_record_check = $character->employment()->where('recordID', '=', $employment->recordID)->first(); if (!$employment_record_check) { $employment_entry = new \EveEveCharacterInfoEmploymentHistory(); } else { $employment_entry = $employment_record_check; } $employment_entry->recordID = $employment->recordID; $employment_entry->corporationID = $employment->corporationID; $employment_entry->startDate = $employment->startDate; // Add/update the emplyment entry for this character $character->employment()->save($employment_entry); } // Set the cached entry time BaseApi::setDbCache($scope, $api, $character_info->cached_until, $characterID); } return $character_info; }