/** * updated the character log entry for a user character by IGB Header data * @param int $ttl cache time in seconds * @throws \Exception */ public function updateCharacterLog($ttl = 0) { $headerData = Controller\CcpApiController::getIGBHeaderData(); // check if IGB Data is available if (!empty($headerData->values)) { $f3 = self::getF3(); // check if system has changed since the last call // current location is stored (global) to avoid unnecessary DB calls $sessionCharacterKey = 'LOGGED.user.character.id_' . $headerData->values['charid']; if ($f3->exists($sessionCharacterKey)) { // cache data exists $cacheData = $f3->get($sessionCharacterKey); } else { // new cache data $cacheData = ['systemId' => 0, 'shipId' => 0]; } if ($cacheData['systemId'] != $headerData->values['solarsystemid'] || $cacheData['shipId'] != $headerData->values['shiptypeid']) { $cacheData['systemId'] = (int) $headerData->values['solarsystemid']; $cacheData['shipId'] = (int) $headerData->values['shiptypeid']; // character has changed system, or character just logged on $character = self::getNew('CharacterModel'); $character->getById((int) $headerData->values['charid']); if ($character->dry()) { // this can happen if a valid user plays the game with a not registered character // whose API is not registered -> save new character or update character data $corporationId = array_key_exists('corpid', $headerData->values) ? $headerData->values['corpid'] : null; $allianceId = array_key_exists('allianceid', $headerData->values) ? $headerData->values['allianceid'] : null; // check if corp exists if (!is_null($corporationId)) { $corporation = self::getNew('CorporationModel'); $corporation->getById((int) $corporationId); if ($corporation->dry()) { $corporation->id = $corporationId; $corporation->name = $headerData->values['corpname']; $corporation->save(); } } // check if ally exists if (!is_null($allianceId)) { $alliance = self::getNew('AllianceModel'); $alliance->getById((int) $allianceId); if ($alliance->dry()) { $alliance->id = $allianceId; $alliance->name = $headerData->values['alliancename']; $alliance->save(); } } $character->id = (int) $headerData->values['charid']; $character->name = $headerData->values['charname']; $character->corporationId = $corporationId; $character->allianceId = $allianceId; $character->save(); } // check if this character has an active log if (!($characterLog = $character->getLog())) { $characterLog = self::getNew('CharacterLogModel'); } // set character log values $characterLog->characterId = $character; $characterLog->systemId = (int) $headerData->values['solarsystemid']; $characterLog->systemName = $headerData->values['solarsystemname']; $characterLog->shipId = (int) $headerData->values['shiptypeid']; $characterLog->shipName = $headerData->values['shipname']; $characterLog->shipTypeName = $headerData->values['shiptypename']; $characterLog->save(); // clear cache for the characterModel as well $character->clearCacheData(); // cache character log information $f3->set($sessionCharacterKey, $cacheData, $ttl); } } }
/** * @return int */ public function updateCharacters() { $apiController = new Controller\CcpApiController(); return $apiController->updateCharacters($this); }