示例#1
0
 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;
     }
 }
示例#2
0
 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;
 }