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($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 = '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) { // To start processing this API Updater, lets take a moment and // examine a sample XML for a kill (taken 2014-12-04 15:24:40): // <rowset name="kills" key="killID" columns="killID,solarSystemID,killTime,moonID"> // <row killID="4" solarSystemID="3" killTime="2013-11-30 14:36:00" moonID="0"> // <victim characterID="9" characterName="J" corporationID="9" corporationName="S" allianceID="9" allianceName="I" factionID="0" factionName="" damageTaken="48243" shipTypeID="33475" /> // <rowset name="attackers" columns="characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID"> // <row characterID="1" characterName="K" corporationID="8" corporationName="T" allianceID="1" allianceName="T" factionID="0" factionName="" securityStatus="0.88117301707494" damageDone="11610" finalBlow="1" weaponTypeID="2905" shipTypeID="11198" /> // </rowset> // <rowset name="items" columns="typeID,flag,qtyDropped,qtyDestroyed,singleton"> // <row typeID="15331" flag="5" qtyDropped="5" qtyDestroyed="18" singleton="0" /> // <row typeID="2510" flag="5" qtyDropped="100" qtyDestroyed="0" singleton="0" /> // </rowset> // </row> // </rowset> // Based on the above, we can see we have 3 sections that need to be kept up to date. // We also need to think about scenarios where we have 2 API's, where the one will // reflect a kill as a loss, and the other as a kill. For that reason we keep // a seperate table to map characterID<->killID, and then record the kill // and all the details seperately. That way, we only store the specific // killID and its details once, and it can be called by iether the // killer or the loser. // It is also possible to do 'Journal Walking' on the killmails, meaning that we can // pull all the history as far back as 2560 [1] entries. With that in mind, we // will set a MAX_INT value as a starting point, and then grab the fromID in // the responses to start the walking backwards while updating the db. $row_count = 1000; // 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 = 'KillMails'; 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); // Here we will start a infinite loop for the Journal Walking to take // place. Once we receive less entrues than the expected $row_count // we know we reached the end of the walk and can safely break // out of the loop. Some database cached_until checks are // actually not done here. We are relying entirely on // pheal-ng to handle it. $first_request = true; $from_id = PHP_INT_MAX; while (true) { // Check if this is the first request. If so, don't use a fromID. try { if ($first_request) { $kill_mails = $pheal->charScope->KillMails(array('characterID' => $characterID, 'rowCount' => $row_count)); // flip the first_request as those that get processed from here need to be from the `fromID` $first_request = false; } else { $kill_mails = $pheal->charScope->KillMails(array('characterID' => $characterID, 'rowCount' => $row_count, 'fromID' => $from_id)); } } 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; } // With $kill_mails now populated, get started in updating the database // with all of the information that we now have. While we update the // database, we also need to check that we get the lowest possible // $from_id (killID) for the Journal Walking to occur foreach ($kill_mails->kills as $kill) { // Ensure $from_id is at its lowest $from_id = min($kill->killID, $from_id); // With all of that work done, we can finally get to actually // populating the database with data! // Determine if we already know about this killID for this characterID $character_kill_mail = \EveCharacterKillMails::where('characterID', $characterID)->where('killID', $kill->killID)->first(); // If we know about it, assume we have all the details already recorded, // otherwise we will record it if (!$character_kill_mail) { $character_kill_mail = new \EveCharacterKillMails(); } else { continue; } $character_kill_mail->characterID = $characterID; $character_kill_mail->killID = $kill->killID; $character_kill_mail->save(); // With record of the killmail, check if we have the details recorded // for it. If we do, we assume the attackers and items will be the // same and not need any update $killmail_detail = \EveCharacterKillMailDetail::where('killID', $kill->killID)->first(); // The same as the killmail record for a character applies here. If // we already know about it, asssume that it is up to date and // continue with the next killmail. if (!$killmail_detail) { $killmail_detail = new \EveCharacterKillMailDetail(); } else { continue; } // Assuming we got all the way here, its safe to assume we want to // record the details for this killmail. $killmail_detail->killID = $kill->killID; $killmail_detail->solarSystemID = $kill->solarSystemID; $killmail_detail->killTime = $kill->killTime; $killmail_detail->moonID = $kill->moonID; $killmail_detail->characterID = $kill->victim->characterID; $killmail_detail->characterName = $kill->victim->characterName; $killmail_detail->corporationID = $kill->victim->corporationID; $killmail_detail->corporationName = $kill->victim->corporationName; $killmail_detail->allianceID = $kill->victim->allianceID; $killmail_detail->allianceName = $kill->victim->allianceName; $killmail_detail->factionID = $kill->victim->factionID; $killmail_detail->factionName = $kill->victim->factionName; $killmail_detail->damageTaken = $kill->victim->damageTaken; $killmail_detail->shipTypeID = $kill->victim->shipTypeID; $killmail_detail->save(); // Update the attackers foreach ($kill->attackers as $attacker) { $attacker_information = new \EveCharacterKillMailAttackers(); // $attacker_information->killID = $kill->killID; $attacker_information->characterID = $attacker->characterID; $attacker_information->characterName = $attacker->characterName; $attacker_information->corporationID = $attacker->corporationID; $attacker_information->corporationName = $attacker->corporationName; $attacker_information->allianceID = $attacker->allianceID; $attacker_information->allianceName = $attacker->allianceName; $attacker_information->factionID = $attacker->factionID; $attacker_information->factionName = $attacker->factionName; $attacker_information->securityStatus = $attacker->securityStatus; $attacker_information->damageDone = $attacker->damageDone; $attacker_information->finalBlow = $attacker->finalBlow; $attacker_information->weaponTypeID = $attacker->weaponTypeID; $attacker_information->shipTypeID = $attacker->shipTypeID; // Add the attacker information to the killmail $killmail_detail->attackers()->save($attacker_information); } // Finally, update the dropped items foreach ($kill->items as $item) { $item_information = new \EveCharacterKillMailItems(); // $item_information->killID = $kill->killID; $item_information->flag = $item->flag; $item_information->qtyDropped = $item->qtyDropped; $item_information->qtyDestroyed = $item->qtyDestroyed; $item_information->singleton = $item->singleton; // Add the item information to the killmail $killmail_detail->items()->save($item_information); } } // Check how many entries we got back. If it is less than $row_count, we know we have // walked back the entire journal if (count($kill_mails->kills) < $row_count) { break; } // Break the while loop } } // Unlock the call BaseApi::unlockCall($lockhash); return $kill_mails; }
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 = 'Corp'; $api = 'StarbaseDetail'; 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); // We now need to loop over the starbases that we have for this corporation // and update the details as needed. foreach (\EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->get() as $starbase) { // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $starbase_detail = $pheal->corpScope->StarbaseDetail(array('characterID' => $characters[0], 'itemID' => $starbase->itemID)); } catch (\Pheal\Exceptions\APIException $e) { // In the odd chance that we get a old/invalid ID, catch only that error // else go boom if ($e->getCode() == 114) { \Log::error('API Exception caught but continuing. Error: ' . $e->getCode() . ': ' . $e->getMessage(), array('src' => __CLASS__)); continue; } // I suspect that there is a caching specific thing here that I don't understand. I know // this is a bad thing, but for now, just continue when this occurs, and write a entry // to the application log about it. // // Error: 221: Illegal page request! Please verify the access granted by the key you are using! // ^~~~ this after we just got the starbase list... :( if ($e->getCode() == 221) { \Log::error('API Exception caught but continuing. Error: ' . $e->getCode() . ': ' . $e->getMessage(), array('src' => __CLASS__)); continue; } // Lastly, go boom as something out of the ordinary is wrong. throw $e; } catch (\Pheal\Exceptions\PhealException $e) { // Lets add some information to the original exception and raise it $new_error = $e->getMessage() . ' - Current starbaseID: ' . $starbase->itemID; throw new \Exception($new_error, $e->getCode()); } // Update the details $starbase_data = \EveCorporationStarbaseDetail::where('corporationID', '=', $corporationID)->where('itemID', '=', $starbase->itemID)->first(); if (!$starbase_data) { $starbase_data = new \EveCorporationStarbaseDetail(); } $starbase_data->corporationID = $corporationID; $starbase_data->itemID = $starbase->itemID; // Fromt he outer loop $starbase_data->state = $starbase_detail->state; $starbase_data->stateTimestamp = $starbase_detail->stateTimestamp; $starbase_data->onlineTimestamp = $starbase_detail->onlineTimestamp; $starbase_data->usageFlags = $starbase_detail->generalSettings->usageFlags; $starbase_data->deployFlags = $starbase_detail->generalSettings->deployFlags; $starbase_data->allowCorporationMembers = $starbase_detail->generalSettings->allowCorporationMembers; $starbase_data->allowAllianceMembers = $starbase_detail->generalSettings->allowAllianceMembers; $starbase_data->useStandingsFrom = $starbase_detail->combatSettings->useStandingsFrom->ownerID; $starbase_data->onStandingDrop = $starbase_detail->combatSettings->onStandingDrop->standing; $starbase_data->onStatusDropEnabled = $starbase_detail->combatSettings->onStatusDrop->enabled; $starbase_data->onStatusDropStanding = $starbase_detail->combatSettings->onStatusDrop->standing; $starbase_data->onAggression = $starbase_detail->combatSettings->onAggression->enabled; $starbase_data->onCorporationWar = $starbase_detail->combatSettings->onCorporationWar->enabled; // Add the fuel to the various fields foreach ($starbase_detail->fuel as $fuel) { if ($fuel->typeID == 16275) { $starbase_data->strontium = $fuel->quantity; } // Four different fuel block typeIDs // 4051 Caldari Fuel Block // 4246 Minmatar Fuel Block // 4247 Amarr Fuel Block // 4312 Gallente Fuel Block if (in_array($fuel->typeID, array('4051', '4246', '4247', '4312'))) { $starbase_data->fuelBlocks = $fuel->quantity; } // Various starbase charters // 24592 Amarr Empire Starbase Charter // 24593 Caldari State Starbase Charter // 24594 Gallente Federation Starbase Charter // 24595 Minmatar Republic Starbase Charter // 24596 Khanid Kingdom Starbase Charter // 24597 Ammatar Mandate Starbase Charter if (in_array($fuel->typeID, array('24592', '24593', '24594', '24595', '24596', '24597'))) { $starbase_data->starbaseCharter = $fuel->quantity; } } $starbase_data->save(); } // Unlock the call BaseApi::unlockCall($lockhash); return null; }
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 = '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) { $row_count = 500; // 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 = 'WalletTransactions'; 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); // Prepare blank wallet_transactions to start $wallet_transactions = null; // Next, start our loop over the wallet divisions for this corporation foreach (\EveCorporationAccountBalance::where('corporationID', '=', $corporationID)->get() as $walletdivision) { // Start a infinite loop for the Journal Walking. We will break out of this once // we have reached the end of the records that we can get // TODO: This needs a lot more brain thingies applied in order to figure out how // we are going to go about the database cached_untill timer. For now, we will just // ignore the DB level one and rely entirely on pheal-ng to cache the XML's $first_request = true; $from_id = PHP_INT_MAX; // Use the maximum size for this PHP arch while (true) { // Do the actual API call. pheal-ng actually handles some internal // caching too. try { if ($first_request) { $wallet_transactions = $pheal->corpScope->WalletTransactions(array('characterID' => $characters[0], 'rowCount' => $row_count, 'accountKey' => $walletdivision->accountKey)); // flip the first_request as those that get processed from here need to be from the `fromID` $first_request = false; } else { $wallet_transactions = $pheal->corpScope->WalletTransactions(array('characterID' => $characters[0], 'rowCount' => $row_count, 'accountKey' => $walletdivision->accountKey, 'fromID' => $from_id)); } } 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; } // Process the transactions foreach ($wallet_transactions->transactions as $transaction) { // Ensure that $from_id is at its lowest $from_id = min($transaction->transactionID, $from_id); // Generate a transaction hash. It would seem that refID's could possibly be cycled. $transaction_hash = md5(implode(',', array($corporationID, $walletdivision->accountKey, $transaction->transactionDateTime, $transaction->clientID, $transaction->transactionID))); // In order try try and relieve some strain on the database, we will // cache the hashes that we find we have knowledge of. The main // goal of this is to make the lookups faster, and leave // MySQL to do stuff it should rather be doing // First, find thee entry in the cache. The cache key is determined // as: <transaction hash + corporationID + apitype> if (!\Cache::has($transaction_hash . $corporationID . $api)) { // If the $transaction_hash is not in the Cache, ask the database // if it knows about it. Again, if it exists, we will continue, // but we will also add a new Cache entry to make the next // lookip faster $transaction_data = \EveCorporationWalletTransactions::where('corporationID', '=', $corporationID)->where('hash', '=', $transaction_hash)->first(); // Check if the database found the entry. if (!$transaction_data) { $transaction_data = new \EveCorporationWalletTransactions(); } else { // This entry exists in the database. Put a new Cache entry // so that the next lookup may be faster. This cache // entry will live for 1 week. \Cache::put($transaction_hash . $corporationID . $api, true, 60 * 24 * 7); // Continue to the next transaction continue; } $transaction_data->corporationID = $corporationID; $transaction_data->hash = $transaction_hash; $transaction_data->accountKey = $walletdivision->accountKey; $transaction_data->transactionID = $transaction->transactionID; $transaction_data->transactionDateTime = $transaction->transactionDateTime; $transaction_data->quantity = $transaction->quantity; $transaction_data->typeName = $transaction->typeName; $transaction_data->typeID = $transaction->typeID; $transaction_data->price = $transaction->price; $transaction_data->clientID = $transaction->clientID; $transaction_data->clientName = $transaction->clientName; $transaction_data->stationID = $transaction->stationID; $transaction_data->stationName = $transaction->stationName; $transaction_data->transactionType = $transaction->transactionType; $transaction_data->transactionFor = $transaction->transactionFor; $transaction_data->journalTransactionID = $transaction->journalTransactionID; $transaction_data->clientTypeID = $transaction->clientTypeID; $transaction_data->save(); } else { // This entry already exists as the hash is cached. continue; } } // Check how many entries we got back. If it us less that $row_count, we know we have // walked back the entire journal if (count($wallet_transactions->transactions) < $row_count) { break; } // Break the while loop } } // Unlock the call BaseApi::unlockCall($lockhash); return $wallet_transactions; }
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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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($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; }