Bigfixes
This commit is contained in:
@@ -13,10 +13,11 @@ class Access extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
*/
|
||||
function beforeroute() {
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute();
|
||||
parent::beforeroute($f3);
|
||||
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
|
||||
@@ -12,11 +12,11 @@ use Model;
|
||||
class Connection extends \Controller\AccessController{
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
*/
|
||||
function beforeroute() {
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute();
|
||||
parent::beforeroute($f3);
|
||||
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
@@ -56,8 +56,25 @@ class Connection extends \Controller\AccessController{
|
||||
$connection = Model\BasicModel::getNew('ConnectionModel');
|
||||
$connection->getById( (int)$connectionData['id'] );
|
||||
|
||||
// search if systems are neighbors
|
||||
$routeController = new Route();
|
||||
$route = $routeController->findRoute($connectionData['sourceName'], $connectionData['targetName'], 1);
|
||||
|
||||
if($route['routePossible'] == true){
|
||||
// systems are next to each other
|
||||
$connectionData['scope'] = 'stargate';
|
||||
$connectionData['type'] = ['stargate'];
|
||||
}elseif($connectionData['scope'] == 'stargate'){
|
||||
// connection scope changed -> this can not be a stargate
|
||||
$connectionData['scope'] = 'wh';
|
||||
$connectionData['type'] = ['wh_fresh'];
|
||||
}
|
||||
|
||||
$connectionData['mapId'] = $map;
|
||||
|
||||
// "updated" should not be set by client e.g. after manual drag&drop
|
||||
unset($connectionData['updated']);
|
||||
|
||||
$connection->setData($connectionData);
|
||||
|
||||
if( $connection->isValid() ){
|
||||
|
||||
@@ -18,13 +18,14 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
*/
|
||||
function beforeroute() {
|
||||
function beforeroute($f3) {
|
||||
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
|
||||
parent::beforeroute();
|
||||
parent::beforeroute($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +153,7 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
if( isset($formData['id']) ){
|
||||
|
||||
$user = $this->_getUser();
|
||||
$user = $this->_getUser(0);
|
||||
|
||||
if($user){
|
||||
$map = Model\BasicModel::getNew('MapModel');
|
||||
@@ -171,12 +172,15 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
// share map between users -> set access
|
||||
if(isset($formData['mapUsers'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessUsers = array_slice( $formData['mapUsers'], 0, $f3->get('PATHFINDER.MAX_SHARED_USER') );
|
||||
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
$tempUser = Model\BasicModel::getNew('UserModel');
|
||||
|
||||
foreach((array)$formData['mapUsers'] as $userId){
|
||||
foreach($accessUsers as $userId){
|
||||
$tempUser->getById( (int)$userId );
|
||||
|
||||
if(
|
||||
@@ -205,12 +209,15 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
// share map between corporations -> set access
|
||||
if(isset($formData['mapCorporations'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAX_SHARED_CORPORATION') );
|
||||
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
$tempCorporation = Model\BasicModel::getNew('CorporationModel');
|
||||
|
||||
foreach((array)$formData['mapCorporations'] as $corporationId){
|
||||
foreach($accessCorporations as $corporationId){
|
||||
$tempCorporation->getById( (int)$corporationId );
|
||||
|
||||
if(
|
||||
@@ -240,12 +247,15 @@ class Map extends \Controller\AccessController {
|
||||
|
||||
// share map between alliances -> set access
|
||||
if(isset($formData['mapAlliances'])){
|
||||
// avoid abuse -> respect share limits
|
||||
$accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAX_SHARED_ALLIANCE') );
|
||||
|
||||
// clear map access. In case something has removed from access list
|
||||
$map->clearAccess();
|
||||
|
||||
$tempAlliance = Model\BasicModel::getNew('AllianceModel');
|
||||
|
||||
foreach((array)$formData['mapAlliances'] as $allianceId){
|
||||
foreach($accessAlliances as $allianceId){
|
||||
$tempAlliance->getById( (int)$allianceId );
|
||||
|
||||
if(
|
||||
@@ -265,10 +275,10 @@ class Map extends \Controller\AccessController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reload the same map model (refresh)
|
||||
// this makes sure all data is up2date
|
||||
$map->getById( $map->id );
|
||||
$map->getById( $map->id, 0 );
|
||||
|
||||
|
||||
$return->mapData = $map->getData();
|
||||
|
||||
@@ -323,7 +333,6 @@ class Map extends \Controller\AccessController {
|
||||
$mapData = (array)$f3->get('POST.mapData');
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
@@ -487,71 +496,71 @@ class Map extends \Controller\AccessController {
|
||||
$cacheKey = null;
|
||||
|
||||
$return = (object) [];
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
$return->error = [];
|
||||
|
||||
if($user){
|
||||
|
||||
// update current location (IGB data)
|
||||
$user->updateCharacterLog();
|
||||
|
||||
if( !empty($f3->get('POST.mapIds')) ){
|
||||
$mapIds = (array)$f3->get('POST.mapIds');
|
||||
// check if data for specific system is requested
|
||||
$systemData = (array)$f3->get('POST.systemData');
|
||||
|
||||
// if data is requested extend the cache key in order to get new data
|
||||
$requestSystemData = (object) [];
|
||||
$requestSystemData->mapId = isset($systemData['mapId']) ? (int) $systemData['mapId'] : 0;
|
||||
$requestSystemData->systemId = isset($systemData['systemData']['id']) ? (int) $systemData['systemData']['id'] : 0;
|
||||
$user = $this->_getUser();
|
||||
|
||||
// the maps are cached per user
|
||||
$cacheKey = 'user_data_' . $user->id . '_' . $requestSystemData->systemId;
|
||||
if($user){
|
||||
// update current location (IGB data)
|
||||
$user->updateCharacterLog(60 * 5);
|
||||
|
||||
if( $f3->exists($cacheKey) === false ){
|
||||
// if data is requested extend the cache key in order to get new data
|
||||
$requestSystemData = (object) [];
|
||||
$requestSystemData->mapId = isset($systemData['mapId']) ? (int) $systemData['mapId'] : 0;
|
||||
$requestSystemData->systemId = isset($systemData['systemData']['id']) ? (int) $systemData['systemData']['id'] : 0;
|
||||
|
||||
// get user Data for each map
|
||||
$activeMaps = $user->getMaps(5);
|
||||
// IMPORTANT for now -> just update a single map (save performance)
|
||||
$mapIds = array_slice($mapIds, 0, 1);
|
||||
|
||||
foreach($activeMaps as $mapModel){
|
||||
$return->mapUserData[] = $mapModel->getUserData();
|
||||
// the maps are cached per map (this must be changed if multiple maps
|
||||
// will be allowed in future...
|
||||
$tempId = $mapIds[0];
|
||||
$cacheKey = 'user_data_' . $tempId . '_' . $requestSystemData->systemId;
|
||||
|
||||
// request signature data for a system if user has map access!
|
||||
if( $mapModel->id === $requestSystemData->mapId ){
|
||||
$system = $mapModel->getSystem( $requestSystemData->systemId );
|
||||
if( $f3->exists($cacheKey) === false ){
|
||||
foreach($mapIds as $mapId){
|
||||
$map = $user->getMap($mapId);
|
||||
|
||||
if( !is_null($system) ){
|
||||
// data for the current selected system
|
||||
$return->system = $system->getData();
|
||||
$return->system->signatures = $system->getSignaturesData();
|
||||
if( !is_null($map) ){
|
||||
$return->mapUserData[] = $map->getUserData();
|
||||
|
||||
|
||||
// request signature data for a system if user has map access!
|
||||
if( $map->id === $requestSystemData->mapId ){
|
||||
$system = $map->getSystem( $requestSystemData->systemId );
|
||||
|
||||
if( !is_null($system) ){
|
||||
// data for the current selected system
|
||||
$return->system = $system->getData();
|
||||
$return->system->signatures = $system->getSignaturesData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cache response
|
||||
if( !is_null($cacheKey) ){
|
||||
// cache response
|
||||
$f3->set($cacheKey, $return, $responseTTL);
|
||||
}else{
|
||||
// get from cache
|
||||
// this should happen if a user has multiple program instances running
|
||||
// with the same main char
|
||||
$return = $f3->get($cacheKey);
|
||||
}
|
||||
|
||||
// get current user data -> this should not be cached because each user has different personal data
|
||||
// even if they have multiple characters using the same map!
|
||||
$return->userData = $user->getData();
|
||||
}else{
|
||||
// get from cache
|
||||
// this should happen if a user has multiple program instances running
|
||||
// with the same main char
|
||||
$return = $f3->get($cacheKey);
|
||||
// user logged of
|
||||
$return->error[] = $this->getUserLoggedOffError();
|
||||
}
|
||||
|
||||
// add data that is not cacheable -----------------------------------------
|
||||
|
||||
// get current user data -> this should not be cached because each user has different personal data
|
||||
// even if they have multiple characters using the same map!
|
||||
$return->userData = $user->getData();
|
||||
|
||||
}else{
|
||||
// user logged of
|
||||
$return->error[] = $this->getUserLoggedOffError();
|
||||
}
|
||||
|
||||
|
||||
echo json_encode( $return );
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,6 @@ use Model;
|
||||
*/
|
||||
class Route extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* search depth for recursive route search (5000 would be best but slow)
|
||||
* -> in reality there are no routes > 100 jumps between systems
|
||||
*/
|
||||
const ROUTE_SEARCH_DEPTH = 5000;
|
||||
|
||||
/**
|
||||
* cache time for static jump data
|
||||
* @var int
|
||||
@@ -277,11 +271,14 @@ class Route extends \Controller\AccessController {
|
||||
|
||||
/**
|
||||
* find a route between two systems (system names)
|
||||
* $searchDepth for recursive route search (5000 would be best but slow)
|
||||
* -> in reality there are no routes > 100 jumps between systems
|
||||
* @param $systemFrom
|
||||
* @param $systemTo
|
||||
* @param int $searchDepth
|
||||
* @return array
|
||||
*/
|
||||
private function findRoute($systemFrom, $systemTo){
|
||||
public function findRoute($systemFrom, $systemTo, $searchDepth = 5000){
|
||||
|
||||
$routeData = [
|
||||
'routePossible' => false,
|
||||
@@ -299,27 +296,14 @@ class Route extends \Controller\AccessController {
|
||||
// jump counter
|
||||
$jumpNum = 0;
|
||||
|
||||
// check if the system we are looking for is a direct neighbour
|
||||
foreach( $this->jumpArray[$from] as $n ) {
|
||||
if( isset($this->jumpArray[$from]) ){
|
||||
|
||||
if ($n == $to) {
|
||||
$jumpNum = 2;
|
||||
|
||||
$jumpNode = [
|
||||
'system' => $n,
|
||||
'security' => $this->getSystemInfoBySystemId($this->idArray[$n], 'trueSec')
|
||||
];
|
||||
// check if the system we are looking for is a direct neighbour
|
||||
foreach( $this->jumpArray[$from] as $n ) {
|
||||
|
||||
$routeData['route'][] = $jumpNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// system is not a direct neighbour -> search recursive its neighbours
|
||||
if ($jumpNum == 0) {
|
||||
foreach( $this->graph_find_path( $this->jumpArray, $from, $to, self::ROUTE_SEARCH_DEPTH ) as $n ) {
|
||||
|
||||
if ($jumpNum > 0) {
|
||||
if ($n == $to) {
|
||||
$jumpNum = 2;
|
||||
|
||||
$jumpNode = [
|
||||
'system' => $n,
|
||||
@@ -327,25 +311,42 @@ class Route extends \Controller\AccessController {
|
||||
];
|
||||
|
||||
$routeData['route'][] = $jumpNode;
|
||||
break;
|
||||
}
|
||||
$jumpNum++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($jumpNum > 0) {
|
||||
// route found
|
||||
$routeData['routePossible'] = true;
|
||||
// system is not a direct neighbour -> search recursive its neighbours
|
||||
if ($jumpNum == 0) {
|
||||
foreach( $this->graph_find_path( $this->jumpArray, $from, $to, $searchDepth ) as $n ) {
|
||||
|
||||
$jumpNode = [
|
||||
'system' => $from,
|
||||
'security' => $this->getSystemInfoBySystemId($this->idArray[$from], 'trueSec')
|
||||
];
|
||||
if ($jumpNum > 0) {
|
||||
|
||||
// insert "from" system on top
|
||||
array_unshift($routeData['route'], $jumpNode);
|
||||
} else {
|
||||
// route not found
|
||||
$routeData['routePossible'] = true;
|
||||
$jumpNode = [
|
||||
'system' => $n,
|
||||
'security' => $this->getSystemInfoBySystemId($this->idArray[$n], 'trueSec')
|
||||
];
|
||||
|
||||
$routeData['route'][] = $jumpNode;
|
||||
}
|
||||
$jumpNum++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($jumpNum > 0) {
|
||||
// route found
|
||||
$routeData['routePossible'] = true;
|
||||
|
||||
$jumpNode = [
|
||||
'system' => $from,
|
||||
'security' => $this->getSystemInfoBySystemId($this->idArray[$from], 'trueSec')
|
||||
];
|
||||
|
||||
// insert "from" system on top
|
||||
array_unshift($routeData['route'], $jumpNode);
|
||||
} else {
|
||||
// route not found
|
||||
$routeData['routePossible'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// route jumps
|
||||
|
||||
@@ -14,10 +14,11 @@ class Signature extends \Controller\AccessController{
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
*/
|
||||
function beforeroute() {
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute();
|
||||
parent::beforeroute($f3);
|
||||
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
|
||||
@@ -63,11 +63,11 @@ class System extends \Controller\AccessController {
|
||||
private $limitQuery = "";
|
||||
|
||||
/**
|
||||
* event handler
|
||||
* @param $f3
|
||||
*/
|
||||
function beforeroute() {
|
||||
function beforeroute($f3) {
|
||||
|
||||
parent::beforeroute();
|
||||
parent::beforeroute($f3);
|
||||
|
||||
// set header for all routes
|
||||
header('Content-type: application/json');
|
||||
@@ -88,38 +88,42 @@ class System extends \Controller\AccessController {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get static system Data from CCPs Static DB export
|
||||
* @param $systemId
|
||||
* search column for IDs can be (solarSystemID, regionID, constellationID)
|
||||
* @param array $columnIDs
|
||||
* @return null
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _getSystemModelById($systemId){
|
||||
protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){
|
||||
|
||||
$systemModels = [];
|
||||
|
||||
// switch DB
|
||||
$this->setDB('CCP');
|
||||
|
||||
|
||||
$this->whereQuery = "WHERE
|
||||
map_sys.solarSystemID = " . (int)$systemId . "";
|
||||
|
||||
$this->limitQuery = "Limit 1";
|
||||
map_sys." . $column . " IN (" . implode(',', $columnIDs) . ")";
|
||||
|
||||
$query = $this->_getQuery();
|
||||
|
||||
$rows = $this->f3->get('DB')->exec($query, null, 30);
|
||||
$rows = $this->f3->get('DB')->exec($query, null, 60 * 60 * 24);
|
||||
|
||||
// format result
|
||||
$mapper = new Mapper\CcpSystemsMapper($rows);
|
||||
|
||||
$ccpData = $mapper->getData();
|
||||
$ccpSystemsData = $mapper->getData();
|
||||
|
||||
// switch DB
|
||||
$this->setDB('PF');
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
$system->setData(reset($ccpData));
|
||||
|
||||
return $system;
|
||||
foreach($ccpSystemsData as $ccpSystemData){
|
||||
$system = Model\BasicModel::getNew('SystemModel');
|
||||
$system->setData($ccpSystemData);
|
||||
$systemModels[] = $system;
|
||||
}
|
||||
|
||||
return $systemModels;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +226,7 @@ class System extends \Controller\AccessController {
|
||||
$systemData['mapId'] = $map;
|
||||
|
||||
// get static system data (CCP DB)
|
||||
$systemModel = $this->_getSystemModelById($systemData['systemId']);
|
||||
$systemModel = array_values( $this->_getSystemModelByIds([$systemData['systemId']]) )[0];
|
||||
|
||||
$systemModel->createdCharacterId = $activeCharacter->characterId;
|
||||
|
||||
@@ -323,6 +327,46 @@ class System extends \Controller\AccessController {
|
||||
echo json_encode($graphData);
|
||||
}
|
||||
|
||||
/**
|
||||
* get system data for all systems within a constellation
|
||||
* @param $f3
|
||||
* @param $params
|
||||
*/
|
||||
public function constellationData($f3, $params){
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
$return->systemData = [];
|
||||
|
||||
$constellationId = 0;
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
// check for search parameter
|
||||
if( isset($params['arg1']) ){
|
||||
$constellationId = (int)$params['arg1'];
|
||||
}
|
||||
|
||||
$cacheKey = 'CACHE_CONSTELLATION_SYSTEMS_' . self::formatHiveKey($constellationId);
|
||||
|
||||
if($f3->exists($cacheKey)){
|
||||
$return->systemData = $f3->get($cacheKey);
|
||||
}else{
|
||||
if($constellationId > 0){
|
||||
$systemModels = $this->_getSystemModelByIds([$constellationId], 'constellationID');
|
||||
|
||||
foreach($systemModels as $systemModel){
|
||||
$return->systemData[] = $systemModel->getData();
|
||||
}
|
||||
|
||||
$f3->set($cacheKey, $return->systemData, $f3->get('PATHFINDER.CACHE.CONSTELLATION_SYSTEMS') );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,21 +22,23 @@ class User extends Controller\Controller{
|
||||
|
||||
$return = (object) [];
|
||||
|
||||
$loginSuccess = false;
|
||||
$user = null;
|
||||
|
||||
if($data['loginData']){
|
||||
$loginData = $data['loginData'];
|
||||
$loginSuccess = $this->logUserIn( $loginData['userName'], $loginData['userPassword'] );
|
||||
$user = $this->logUserIn( $loginData['userName'], $loginData['userPassword'] );
|
||||
}
|
||||
|
||||
// set "vague" error
|
||||
if($loginSuccess !== true){
|
||||
|
||||
if(is_null($user)){
|
||||
$return->error = [];
|
||||
$loginError = (object) [];
|
||||
$loginError->type = 'login';
|
||||
$return->error[] = $loginError;
|
||||
}else{
|
||||
// update/check api data
|
||||
$user->updateApiData();
|
||||
|
||||
// route user to map app
|
||||
$return->reroute = $f3->get('BASE') . $f3->alias('map');
|
||||
}
|
||||
@@ -48,10 +50,9 @@ class User extends Controller\Controller{
|
||||
* core function for user login
|
||||
* @param $userName
|
||||
* @param $password
|
||||
* @return bool
|
||||
* @return Model\UserModel|null
|
||||
*/
|
||||
private function logUserIn($userName, $password){
|
||||
$loginSuccess = false;
|
||||
|
||||
// try to verify user
|
||||
$user = $this->_verifyUser($userName, $password);
|
||||
@@ -65,16 +66,19 @@ class User extends Controller\Controller{
|
||||
$this->f3->set('SESSION.user.name', $user->name);
|
||||
$this->f3->set('SESSION.user.id', $user->id);
|
||||
|
||||
|
||||
// save user login information
|
||||
$user->touch('lastLogin');
|
||||
$user->save();
|
||||
|
||||
// update/check api data
|
||||
// $this->_updateCharacterData();
|
||||
$loginSuccess = true;
|
||||
// save log
|
||||
$logText = "id: %s, name: %s, ip: %s";
|
||||
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.LOGIN') )->write(
|
||||
sprintf($logText, $user->id, $user->name, $this->f3->get('IP'))
|
||||
);
|
||||
}
|
||||
|
||||
return $loginSuccess;
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,30 +104,42 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* delete the character log entry for the current active (main) character
|
||||
* @param $f3
|
||||
*/
|
||||
public function deleteLog(){
|
||||
public function deleteLog($f3){
|
||||
|
||||
$user = $this->_getUser();
|
||||
if($user){
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
if($activeUserCharacter){
|
||||
$character = $activeUserCharacter->getCharacter();
|
||||
|
||||
if($activeUserCharacter){
|
||||
$character = $activeUserCharacter->getCharacter();
|
||||
if($characterLog = $character->getLog()){
|
||||
$characterLog->erase();
|
||||
$characterLog->save();
|
||||
|
||||
if(is_object($character->characterLog)){
|
||||
$character->characterLog->erase();
|
||||
$character->save();
|
||||
$character->clearCacheData();
|
||||
|
||||
// delete log cache key as well
|
||||
$f3->clear('LOGGED.user.character.id_' . $characterLog->characterId->id . '.systemId');
|
||||
$f3->clear('LOGGED.user.character.id_' . $characterLog->characterId->id . '.shipId');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* log the current user out + clear character system log data
|
||||
* @param $f3
|
||||
*/
|
||||
public function logOut(){
|
||||
$this->deleteLog();
|
||||
public function logOut($f3){
|
||||
$this->deleteLog($f3);
|
||||
|
||||
return parent::logOut();
|
||||
return parent::logOut($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,73 +300,42 @@ class User extends Controller\Controller{
|
||||
// get all existing API models for this user
|
||||
$apiModels = $user->getAPIs();
|
||||
|
||||
// check if the user already has a main character
|
||||
// if not -> save the next best character as main
|
||||
$mainUserCharacter = $user->getMainUserCharacter();
|
||||
|
||||
foreach($settingsData['keyId'] as $i => $keyId){
|
||||
$api = null;
|
||||
$userCharacters = [];
|
||||
|
||||
// search for existing API model
|
||||
foreach($apiModels as $key => $apiModel){
|
||||
if($apiModel->keyId == $keyId){
|
||||
$api = $apiModel;
|
||||
// get existing characters in case api model already exists
|
||||
$userCharacters = $api->getUserCharacters();
|
||||
|
||||
// make sure model is up2data -> cast()
|
||||
$api->cast();
|
||||
unset($apiModels[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(is_null($api)){
|
||||
// new API Key
|
||||
$api = Model\BasicModel::getNew('UserApiModel');
|
||||
$api->userId = $user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$api->keyId = $keyId;
|
||||
$api->vCode = $settingsData['vCode'][$i];
|
||||
|
||||
// check each API Model if valid
|
||||
$newUserCharacters = $api->requestCharacters();
|
||||
// -----
|
||||
$api->save();
|
||||
|
||||
if(empty($newUserCharacters)){
|
||||
$characterCount = $api->updateCharacters();
|
||||
|
||||
if($characterCount == 0){
|
||||
// no characters found -> return warning
|
||||
$characterError = (object) [];
|
||||
$characterError->type = 'warning';
|
||||
$characterError->keyId = $api->keyId;
|
||||
$characterError->vCode = $api->vCode;
|
||||
$characterError->message = 'No characters found';
|
||||
$characterError->message = 'API verification failed. No Characters found for KeyId ' . $api->keyId;
|
||||
$return->error[] = $characterError;
|
||||
}else{
|
||||
$api->save();
|
||||
// find existing character
|
||||
foreach($newUserCharacters as $newUserCharacter){
|
||||
|
||||
$matchedUserCharacter = $newUserCharacter;
|
||||
|
||||
foreach($userCharacters as $key => $userCharacter){
|
||||
if($userCharacter->characterId->id == $newUserCharacter->characterId->id){
|
||||
// user character fond -> update this one
|
||||
$matchedUserCharacter = $userCharacter;
|
||||
unset($userCharacters[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$matchedUserCharacter->apiId = $api;
|
||||
$matchedUserCharacter->userId = $user;
|
||||
|
||||
$matchedUserCharacter->save();
|
||||
}
|
||||
}
|
||||
|
||||
// delete characters that are no longer in this API
|
||||
foreach($userCharacters as $userCharacter){
|
||||
print_r('delete Character: ' . $userCharacter->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,19 +344,22 @@ class User extends Controller\Controller{
|
||||
$apiModel->delete();
|
||||
}
|
||||
|
||||
// set main character if no main character exists
|
||||
if(is_null($mainUserCharacter)){
|
||||
$user->setMainCharacterId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// set main character
|
||||
if( isset($settingsData['mainCharacterId']) ){
|
||||
$user->setMainCharacterId((int)$settingsData['mainCharacterId']);
|
||||
}
|
||||
|
||||
// check if the user already has a main character
|
||||
// if not -> save the next best character as main
|
||||
$mainUserCharacter = $user->getMainUserCharacter();
|
||||
|
||||
// set main character if no main character exists
|
||||
if(is_null($mainUserCharacter)){
|
||||
$user->setMainCharacterId();
|
||||
}
|
||||
|
||||
// save/update user model
|
||||
// this will fail if model validation fails!
|
||||
$user->save();
|
||||
@@ -385,9 +373,8 @@ class User extends Controller\Controller{
|
||||
}
|
||||
|
||||
// get fresh updated user object
|
||||
$user = $this->_getUser();
|
||||
$user = $this->_getUser(0);
|
||||
$newUserData = $user->getData();
|
||||
|
||||
}
|
||||
}catch(Exception\ValidationException $e){
|
||||
$validationError = (object) [];
|
||||
|
||||
Reference in New Issue
Block a user