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) { // 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 = 'Corp'; $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; } // 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); // 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 = 9223372036854775807; while (true) { // Check if this is the first request. If so, don't use a fromID. try { if ($first_request) { $kill_mails = $pheal->corpScope->KillMails(array('characterID' => $characters[0], '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->corpScope->KillMails(array('characterID' => $characters[0], '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 $corporation_kill_mail = \EveCorporationKillMails::where('corporationID', $corporationID)->where('killID', $kill->killID)->first(); // If we know about it, assume we have all the details already recorded, // otherwise we will record it if (!$corporation_kill_mail) { $corporation_kill_mail = new \EveCorporationKillMails(); } else { continue; } $corporation_kill_mail->corporationID = $corporationID; $corporation_kill_mail->killID = $kill->killID; $corporation_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 = \EveCorporationKillMailDetail::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 \EveCorporationKillMailDetail(); } 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 \EveCorporationKillMailAttackers(); // $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 \EveCorporationKillMailItems(); // $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 = '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 = '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 function getDeleteKey($keyID, $delete_all_info = false) { // Ensure that this user may access the data for $keyID if (!\Auth::isSuperUser()) { if (!in_array($keyID, Session::get('valid_keys'))) { App::abort(404); } } // Ensure the user is allowed to delete this key if (!\Auth::hasAccess('key_manager')) { App::abort(404); } // Get the full key and vCode $key = SeatKey::where('keyID', $keyID)->first(); if (!$key) { App::abort(404); } // Based on delete_all_info, we will either just delete the key, // or all of the information associated with it switch ((bool) $delete_all_info) { case true: // Check if we can determine if this is a corporation or account/char key. $type = \EveAccountAPIKeyInfo::where('keyID', $keyID)->pluck('type'); // Check if the type is set if ($type) { // For corporation keys, we will delete corporation stuff, duhr if ($type == "Corporation") { // Most of the data for corporations is stored with the corporationID // as key. To get this ID, we need to find the character attached to // this key, and then the corporation for that character $characters = BaseApi::findKeyCharacters($keyID); $corporationID = BaseApi::findCharacterCorporation($characters[0]); // With the corporationID now known, go ahead and cleanup the database \EveCorporationAccountBalance::where('corporationID', $corporationID)->delete(); \EveCorporationAssetList::where('corporationID', $corporationID)->delete(); \EveCorporationAssetListContents::where('corporationID', $corporationID)->delete(); \EveCorporationAssetListLocations::where('corporationID', $corporationID)->delete(); \EveCorporationContactListAlliance::where('corporationID', $corporationID)->delete(); \EveCorporationContactListCorporate::where('corporationID', $corporationID)->delete(); \EveCorporationContracts::where('corporationID', $corporationID)->delete(); \EveCorporationContractsItems::where('corporationID', $corporationID)->delete(); \EveCorporationCorporationSheet::where('corporationID', $corporationID)->delete(); \EveCorporationCorporationSheetDivisions::where('corporationID', $corporationID)->delete(); \EveCorporationCorporationSheetWalletDivisions::where('corporationID', $corporationID)->delete(); \EveCorporationIndustryJobs::where('corporationID', $corporationID)->delete(); \EveCorporationMarketOrders::where('corporationID', $corporationID)->delete(); \EveCorporationMedals::where('corporationID', $corporationID)->delete(); \EveCorporationMemberMedals::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityGrantableRoles::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityGrantableRolesAtBase::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityGrantableRolesAtHQ::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityGrantableRolesAtOther::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityLog::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityRoles::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityRolesAtBase::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityRolesAtHQ::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityRolesAtOther::where('corporationID', $corporationID)->delete(); \EveCorporationMemberSecurityTitles::where('corporationID', $corporationID)->delete(); \EveCorporationMemberTracking::where('corporationID', $corporationID)->delete(); \EveCorporationShareholderCharacters::where('corporationID', $corporationID)->delete(); \EveCorporationShareholderCorporations::where('corporationID', $corporationID)->delete(); \EveCorporationStandingsAgents::where('corporationID', $corporationID)->delete(); \EveCorporationStandingsFactions::where('corporationID', $corporationID)->delete(); \EveCorporationStandingsNPCCorporations::where('corporationID', $corporationID)->delete(); \EveCorporationStarbaseDetail::where('corporationID', $corporationID)->delete(); \EveCorporationStarbaseList::where('corporationID', $corporationID)->delete(); \EveCorporationWalletJournal::where('corporationID', $corporationID)->delete(); \EveCorporationWalletTransactions::where('corporationID', $corporationID)->delete(); } else { // And for character stuff, we delete character stuff // Here we need to be careful now. It may happen that we have more than 1 key // for a character, so we have to be aware of this. It adds a factor of // complexity to the whole thing. $characters = BaseApi::findKeyCharacters($keyID); // Now that we know about all of the characters, we will loop over them and check // that we only have 1 key for them. If more than one keys have this character, we will // simply ignore the cleanup and add a message about it foreach ($characters as $id => $character) { // Check how many keys know about this character if (\EveAccountAPIKeyInfoCharacters::where('characterID', $character)->count() > 1) { // Write a log entry about this \Log::warning('Character ' . $character . ' is recorded on another key and will not been cleaned up'); // Remove this character from $characters unset($characters[$id]); } } // So we now have an array of characterID's that can be cleaned up. Lets do that if (count($characters) > 0) { \EveCharacterAccountBalance::whereIn('characterID', $characters)->delete(); \EveCharacterAssetList::whereIn('characterID', $characters)->delete(); \EveCharacterAssetListContents::whereIn('characterID', $characters)->delete(); \EveCharacterCharacterSheet::whereIn('characterID', $characters)->delete(); \EveCharacterCharacterSheetSkills::whereIn('characterID', $characters)->delete(); \EveCharacterContactList::whereIn('characterID', $characters)->delete(); \EveCharacterContactListAlliance::whereIn('characterID', $characters)->delete(); \EveCharacterContactListCorporate::whereIn('characterID', $characters)->delete(); \EveCharacterContactNotifications::whereIn('characterID', $characters)->delete(); \EveCharacterContracts::whereIn('characterID', $characters)->delete(); \EveCharacterContractsItems::whereIn('characterID', $characters)->delete(); \EveCharacterIndustryJobs::whereIn('characterID', $characters)->delete(); // Intentionally ignoring the mail related information as this has a lot of overlap // and is almost always usefull \EveCharacterMarketOrders::whereIn('characterID', $characters)->delete(); \EveCharacterPlanetaryColonies::whereIn('characterID', $characters)->delete(); \EveCharacterPlanetaryLinks::whereIn('characterID', $characters)->delete(); \EveCharacterPlanetaryPins::whereIn('characterID', $characters)->delete(); \EveCharacterPlanetaryRoutes::whereIn('characterID', $characters)->delete(); \EveCharacterResearch::whereIn('characterID', $characters)->delete(); \EveCharacterSkillInTraining::whereIn('characterID', $characters)->delete(); \EveCharacterSkillQueue::whereIn('characterID', $characters)->delete(); \EveCharacterStandingsAgents::whereIn('characterID', $characters)->delete(); \EveCharacterStandingsFactions::whereIn('characterID', $characters)->delete(); \EveCharacterStandingsNPCCorporations::whereIn('characterID', $characters)->delete(); \EveCharacterUpcomingCalendarEvents::whereIn('characterID', $characters)->delete(); \EveCharacterWalletJournal::whereIn('characterID', $characters)->delete(); \EveCharacterWalletTransactions::whereIn('characterID', $characters)->delete(); } } // Finally, delete the key and redirect $key->delete(); // Delete the information that we have for this key too \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete(); \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete(); return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted'); } else { // So, we are unable to determine the key type, so maybe this is // a invalid one or whatever. Just get rid of it. // Delete the API Key $key->delete(); // Delete the information that we have for this key too \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete(); \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete(); return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted'); } break; case false: // Delete the API Key $key->delete(); // Delete the information that we have for this key too \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete(); \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete(); return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted'); break; } }
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 = '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 = '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 = '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 = 'Corp'; $api = 'CorporationSheet'; if (BaseApi::isBannedCall($api, $scope, $keyID)) { return; } // Get the characters for this key $characters = BaseApi::findKeyCharacters($keyID); // Check if this key has any characters associated with it if (!$characters) { return; } // Lock the call so that we are the only instance of this running now() // If it is already locked, just return without doing anything if (!BaseApi::isLockedCall($api, $scope, $keyID)) { $lockhash = BaseApi::lockCall($api, $scope, $keyID); } else { return; } // So I think a corporation key will only ever have one character // attached to it. So we will just use that characterID for auth // things, but the corporationID for locking etc. $corporationID = BaseApi::findCharacterCorporation($characters[0]); // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $corporation_sheet = $pheal->corpScope->CorporationSheet(array('characterID' => $characters[0])); } catch (\Pheal\Exceptions\APIException $e) { // If we cant get account status information, prevent us from calling // this API again BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID)) { $corporation_data = \EveCorporationCorporationSheet::where('corporationID', '=', $corporationID)->first(); if (!$corporation_data) { $corporation_data = new \EveCorporationCorporationSheet(); } $corporation_data->corporationID = $corporation_sheet->corporationID; $corporation_data->corporationName = $corporation_sheet->corporationName; $corporation_data->ticker = $corporation_sheet->ticker; $corporation_data->ceoID = $corporation_sheet->ceoID; $corporation_data->ceoName = $corporation_sheet->ceoName; $corporation_data->stationID = $corporation_sheet->stationID; $corporation_data->stationName = $corporation_sheet->stationName; $corporation_data->description = $corporation_sheet->description; $corporation_data->url = $corporation_sheet->url; $corporation_data->allianceID = $corporation_sheet->allianceID; $corporation_data->factionID = $corporation_sheet->factionID; $corporation_data->allianceName = $corporation_sheet->allianceName; $corporation_data->taxRate = $corporation_sheet->taxRate; $corporation_data->memberCount = $corporation_sheet->memberCount; $corporation_data->memberLimit = $corporation_sheet->memberLimit; $corporation_data->shares = $corporation_sheet->shares; $corporation_data->graphicID = $corporation_sheet->logo->graphicID; $corporation_data->shape1 = $corporation_sheet->logo->shape1; $corporation_data->shape2 = $corporation_sheet->logo->shape2; $corporation_data->shape3 = $corporation_sheet->logo->shape3; $corporation_data->color1 = $corporation_sheet->logo->color1; $corporation_data->color2 = $corporation_sheet->logo->color2; $corporation_data->color3 = $corporation_sheet->logo->color3; $corporation_data->corporationID = $corporation_sheet->corporationID; $corporation_data->save(); // Update the Divisions foreach ($corporation_sheet->divisions as $division) { $division_data = \EveCorporationCorporationSheetDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first(); if (!$division_data) { $division_data = new \EveCorporationCorporationSheetDivisions(); } $division_data->corporationID = $corporationID; $division_data->accountKey = $division->accountKey; $division_data->description = $division->description; $corporation_data->divisions()->save($division_data); } // Update the Wallet Divisions foreach ($corporation_sheet->walletDivisions as $division) { $division_data = \EveCorporationCorporationSheetWalletDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first(); if (!$division_data) { $division_data = new \EveCorporationCorporationSheetWalletDivisions(); } $division_data->corporationID = $corporationID; $division_data->accountKey = $division->accountKey; $division_data->description = $division->description; $corporation_data->walletdivisions()->save($division_data); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $corporation_sheet; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); // Set key scopes and check if the call is banned $scope = 'Corp'; $api = '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; } // 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 { $contact_list = $pheal->corpScope->ContactList(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, $contact_list->cached_until, $corporationID)) { // The ContactList API will potentially return the corporations: // a) corporation contacts, // b) alliance contracts. // TODO: Think about maybe doing this in a transaction? // First, the corporate contacts // Remove the current contacts \EveCorporationContactListCorporate::where('corporationID', '=', $corporationID)->delete(); // Loop over the list we got from the api and update the db foreach ($contact_list->corporateContactList as $contact) { $new_contact = new \EveCorporationContactListCorporate(); $new_contact->corporationID = $corporationID; $new_contact->contactID = $contact->contactID; $new_contact->contactName = $contact->contactName; $new_contact->standing = $contact->standing; $new_contact->contactTypeID = $contact->contactTypeID; $new_contact->save(); } // Second, the alliance contacts // Remove the current contacts \EveCorporationContactListAlliance::where('corporationID', '=', $corporationID)->delete(); // Loop over the list we got from the api and update the db foreach ($contact_list->allianceContactList as $contact) { $new_contact = new \EveCorporationContactListAlliance(); $new_contact->corporationID = $corporationID; $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, $corporationID); } // Unlock the call BaseApi::unlockCall($lockhash); return $contact_list; }
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 = '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; }