public function execute($parameters, $db) { $keyID = (int) $parameters[0]; $vCode = $db->queryField("select vCode from zz_api where keyID = :keyID", "vCode", array(":keyID" => $keyID), 0); if ($keyID == 0 && strlen($vCode) == 0) { return; } // Update lastValidation $db->execute("update zz_api set lastValidation = now() where keyID = :keyID", array(":keyID" => $keyID)); $pheal = Util::getPheal($keyID, $vCode); try { $apiKeyInfo = $pheal->ApiKeyInfo(); } catch (Exception $ex) { Log::log("Error Validating {$keyID}: " . $ex->getCode() . " " . $ex->getMessage()); Api::handleApiException($keyID, null, $ex); return; } // Clear the error code $db->execute("update zz_api set errorCode = 0 where keyID = :keyID", array(":keyID" => $keyID)); $key = $apiKeyInfo->key; $accessMask = $key->accessMask; $characterIDs = array(); if (Api::hasBits($accessMask)) { foreach ($apiKeyInfo->key->characters as $character) { $characterID = $character->characterID; $characterIDs[] = $characterID; $corporationID = $character->corporationID; $isDirector = $apiKeyInfo->key->type == "Corporation" ? "T" : "F"; $count = $db->queryField("select count(*) count from zz_api_characters where keyID = :keyID and isDirector = :isDirector and characterID = :characterID and corporationID = :corporationID", "count", array(":keyID" => $keyID, ":characterID" => $characterID, ":corporationID" => $corporationID, ":isDirector" => $isDirector), 0); if ($count == 0) { $db->execute("replace into zz_api_characters (keyID, characterID, corporationID, isDirector, cachedUntil) values (:keyID, :characterID, :corporationID, :isDirector, 0)", array(":keyID" => $keyID, ":characterID" => $characterID, ":corporationID" => $corporationID, ":isDirector" => $isDirector)); $charName = Info::getCharName($characterID, true); $corpName = Info::getCorpName($corporationID, true); $allianceID = $db->queryField("select allianceID from zz_corporations where corporationID = :corpID", "allianceID", array(":corpID" => $corporationID)); $alliName = $allianceID > 0 ? "/ " . Info::getAlliName($allianceID) : ""; $type = $isDirector == "T" ? "corp" : "char"; while (strlen($keyID) < 8) { $keyID = " " . $keyID; } Log::log("KeyID: {$keyID} ({$type}) Populating {$charName} / {$corpName} {$alliName}"); } } } // Clear entries that are no longer tied to this account if (sizeof($characterIDs) == 0) { $db->execute("delete from zz_api_characters where keyID = :keyID", array(":keyID" => $keyID)); } else { $db->execute("delete from zz_api_characters where keyID = :keyID and characterID not in (" . implode(",", $characterIDs) . ")", array(":keyID" => $keyID)); } }
public static function getWarInfo($warID) { global $mdb; $warInfo = array(); if ($warID == null) { return $warInfo; } $warInfo = $mdb->findDoc('information', ['type' => 'warID', 'id' => $warID]); $warInfo['warID'] = $warID; $agr = $warInfo['aggressor']['id']; $agrIsAlliance = self::isAlliance($agr); $agrName = $agrIsAlliance ? Info::getAlliName($agr) : Info::getCorpName($agr); $warInfo['agrName'] = $agrName; $warInfo['agrLink'] = ($agrIsAlliance ? '/alliance/' : '/corporation/') . "{$agr}/"; $dfd = $warInfo['defender']['id']; $dfdIsAlliance = self::isAlliance($dfd); $dfdName = $dfdIsAlliance ? Info::getAlliName($dfd) : Info::getCorpName($dfd); $warInfo['dfdName'] = $dfdName; $warInfo['dfdLink'] = ($dfdIsAlliance ? '/alliance/' : '/corporation/') . "{$dfd}/"; $warInfo['dscr'] = "{$agrName} vs {$dfdName}"; return $warInfo; }