diff --git a/app/config.ini b/app/config.ini index 35714b33..cc4bbf54 100644 --- a/app/config.ini +++ b/app/config.ini @@ -1,5 +1,8 @@ ; Global Framework Config +[SERVER] +SERVER_NAME = PATHFINDER + [globals] ; Default Verbosity level of the stack trace. ; Assign values between 0 to 3 for increasing verbosity levels. Check (environment.ini) config for overwriting diff --git a/app/cron.ini b/app/cron.ini index 123aab6e..9eb31085 100644 --- a/app/cron.ini +++ b/app/cron.ini @@ -5,20 +5,26 @@ web = TRUE [CRON.presets] ; run every minute -instant = * * * * * +instant = * * * * * -; run on EVE downtime 11:00 GMT/UTC -downtime = 0 11 * * * +; 12 times per hour (each 5min) +fiveMinutes = */5 * * * * ; 6 times per hour (each 10min) -sixthHour = */10 * * * * +tenMinutes = */10 * * * * ; 2 times per hour (each 30min) -halfHour = */30 * * * * +halfHour = */30 * * * * + +; run on EVE downtime 11:00 GMT/UTC +downtime = 0 11 * * * [CRON.jobs] +; delete expired connections (e.g. EOL) +deleteConnections = Cron\MapUpdate->deleteConnections, @fiveMinutes + ; delete character log data -deleteLogData = Cron\CharacterUpdate->deleteLogData, @sixthHour +deleteLogData = Cron\CharacterUpdate->deleteLogData, @tenMinutes ; delete expired signatures deleteSignatures = Cron\MapUpdate->deleteSignatures, @halfHour diff --git a/app/lib/db/cortex.php b/app/lib/db/cortex.php index cfc9a138..78f035fb 100644 --- a/app/lib/db/cortex.php +++ b/app/lib/db/cortex.php @@ -1074,11 +1074,16 @@ class Cortex extends Cursor { if ($this->emit('beforeerase')===false) return false; if ($this->fieldConf) { - foreach($this->fieldConf as $field => $conf) - if (isset($conf['has-many']) && - $conf['has-many']['hasRel']=='has-many') - $this->set($field,null); - $this->save(); + $changed = false; + foreach($this->fieldConf as $field => $conf){ + if (isset($conf['has-many']) && $conf['has-many']['hasRel']=='has-many'){ + $this->set($field,null); + $changed = true; + } + } + if($changed){ + $this->save(); + } } $this->mapper->erase(); $this->emit('aftererase'); diff --git a/app/main/controller/api/map.php b/app/main/controller/api/map.php index 08850a10..4350ce13 100644 --- a/app/main/controller/api/map.php +++ b/app/main/controller/api/map.php @@ -168,20 +168,27 @@ class Map extends Controller\AccessController { // get max number of shared entities per map ------------------------------------------------------------------ $maxSharedCount = [ - 'character' => $f3->get('PATHFINDER.MAP.PRIVATE.MAX_SHARED'), - 'corporation' => $f3->get('PATHFINDER.MAP.CORPORATION.MAX_SHARED'), - 'alliance' => $f3->get('PATHFINDER.MAP.ALLIANCE.MAX_SHARED'), + 'character' => $f3->get('PATHFINDER.MAP.PRIVATE.MAX_SHARED'), + 'corporation' => $f3->get('PATHFINDER.MAP.CORPORATION.MAX_SHARED'), + 'alliance' => $f3->get('PATHFINDER.MAP.ALLIANCE.MAX_SHARED'), ]; $return->maxSharedCount = $maxSharedCount; // get activity log options per map --------------------------------------------------------------------------- $activityLogging = [ - 'character' => $f3->get('PATHFINDER.MAP.PRIVATE.ACTIVITY_LOGGING'), - 'corporation' => $f3->get('PATHFINDER.MAP.CORPORATION.ACTIVITY_LOGGING'), - 'alliance' => $f3->get('PATHFINDER.MAP.ALLIANCE.ACTIVITY_LOGGING'), + 'character' => $f3->get('PATHFINDER.MAP.PRIVATE.ACTIVITY_LOGGING'), + 'corporation' => $f3->get('PATHFINDER.MAP.CORPORATION.ACTIVITY_LOGGING'), + 'alliance' => $f3->get('PATHFINDER.MAP.ALLIANCE.ACTIVITY_LOGGING'), ]; $return->activityLogging = $activityLogging; + // route search config ---------------------------------------------------------------------------------------- + $return->routeSearch = [ + 'defaultCount' => $this->getF3()->get('PATHFINDER.ROUTE.SEARCH_DEFAULT_COUNT'), + 'maxDefaultCount' => $this->getF3()->get('PATHFINDER.ROUTE.MAX_Default_COUNT'), + 'limit' => $this->getF3()->get('PATHFINDER.ROUTE.LIMIT'), + ]; + // get program routes ----------------------------------------------------------------------------------------- $return->routes = [ 'ssoLogin' => $this->getF3()->alias( 'sso', ['action' => 'requestAuthorization'] ) @@ -374,28 +381,34 @@ class Map extends Controller\AccessController { // share map between characters -> set access if(isset($formData['mapCharacters'])){ + // remove character corporation (re-add later) + $accessCharacters = array_diff($formData['mapCharacters'], [$activeCharacter->_id]); + // avoid abuse -> respect share limits - $accessCharacters = array_slice( $formData['mapCharacters'], 0, $f3->get('PATHFINDER.MAP.PRIVATE.MAX_SHARED') ); + $maxShared = max($f3->get('PATHFINDER.MAP.PRIVATE.MAX_SHARED') - 1, 0); + $accessCharacters = array_slice($accessCharacters, 0, $maxShared); - // clear map access. In case something has removed from access list - $map->clearAccess(); + if($accessCharacters){ + // clear map access. In case something has removed from access list + $map->clearAccess(); - /** - * @var $tempCharacter Model\CharacterModel - */ - $tempCharacter = Model\BasicModel::getNew('CharacterModel'); + /** + * @var $tempCharacter Model\CharacterModel + */ + $tempCharacter = Model\BasicModel::getNew('CharacterModel'); - foreach($accessCharacters as $characterId){ - $tempCharacter->getById( (int)$characterId ); + foreach($accessCharacters as $characterId){ + $tempCharacter->getById( (int)$characterId ); - if( - !$tempCharacter->dry() && - $tempCharacter->shared == 1 // check if map shared is enabled - ){ - $map->setAccess($tempCharacter); + if( + !$tempCharacter->dry() && + $tempCharacter->shared == 1 // check if map shared is enabled + ){ + $map->setAccess($tempCharacter); + } + + $tempCharacter->reset(); } - - $tempCharacter->reset(); } } @@ -411,28 +424,34 @@ class Map extends Controller\AccessController { // share map between corporations -> set access if(isset($formData['mapCorporations'])){ + // remove character corporation (re-add later) + $accessCorporations = array_diff($formData['mapCorporations'], [$corporation->_id]); + // avoid abuse -> respect share limits - $accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAP.CORPORATION.MAX_SHARED') ); + $maxShared = max($f3->get('PATHFINDER.MAP.CORPORATION.MAX_SHARED') - 1, 0); + $accessCorporations = array_slice($accessCorporations, 0, $maxShared); - // clear map access. In case something has removed from access list - $map->clearAccess(); + if($accessCorporations){ + // clear map access. In case something has removed from access list + $map->clearAccess(); - /** - * @var $tempCorporation Model\CorporationModel - */ - $tempCorporation = Model\BasicModel::getNew('CorporationModel'); + /** + * @var $tempCorporation Model\CorporationModel + */ + $tempCorporation = Model\BasicModel::getNew('CorporationModel'); - foreach($accessCorporations as $corporationId){ - $tempCorporation->getById( (int)$corporationId ); + foreach($accessCorporations as $corporationId){ + $tempCorporation->getById( (int)$corporationId ); - if( - !$tempCorporation->dry() && - $tempCorporation->shared == 1 // check if map shared is enabled - ){ - $map->setAccess($tempCorporation); + if( + !$tempCorporation->dry() && + $tempCorporation->shared == 1 // check if map shared is enabled + ){ + $map->setAccess($tempCorporation); + } + + $tempCorporation->reset(); } - - $tempCorporation->reset(); } } @@ -448,30 +467,35 @@ class Map extends Controller\AccessController { // share map between alliances -> set access if(isset($formData['mapAlliances'])){ + // remove character alliance (re-add later) + $accessAlliances = array_diff($formData['mapAlliances'], [$alliance->_id]); + // avoid abuse -> respect share limits - $accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAP.ALLIANCE.MAX_SHARED') ); + $maxShared = max($f3->get('PATHFINDER.MAP.ALLIANCE.MAX_SHARED') - 1, 0); + $accessAlliances = array_slice($accessAlliances, 0, $maxShared); - // clear map access. In case something has removed from access list - $map->clearAccess(); + if($accessAlliances){ + // clear map access. In case something has removed from access list + $map->clearAccess(); - /** - * @var $tempAlliance Model\AllianceModel - */ - $tempAlliance = Model\BasicModel::getNew('AllianceModel'); + /** + * @var $tempAlliance Model\AllianceModel + */ + $tempAlliance = Model\BasicModel::getNew('AllianceModel'); - foreach($accessAlliances as $allianceId){ - $tempAlliance->getById( (int)$allianceId ); + foreach($accessAlliances as $allianceId){ + $tempAlliance->getById( (int)$allianceId ); - if( - !$tempAlliance->dry() && - $tempAlliance->shared == 1 // check if map shared is enabled - ){ - $map->setAccess($tempAlliance); + if( + !$tempAlliance->dry() && + $tempAlliance->shared == 1 // check if map shared is enabled + ){ + $map->setAccess($tempAlliance); + } + + $tempAlliance->reset(); } - - $tempAlliance->reset(); } - } // the alliance of the current user should always have access diff --git a/app/main/controller/api/route.php b/app/main/controller/api/route.php index 2210c64c..73ac4463 100644 --- a/app/main/controller/api/route.php +++ b/app/main/controller/api/route.php @@ -491,6 +491,9 @@ class Route extends Controller\AccessController { */ $map = Model\BasicModel::getNew('MapModel'); + // limit max search routes to max limit + array_splice($routesData, $f3->get('PATHFINDER.ROUTE.LIMIT')); + foreach($routesData as $key => $routeData){ // mapIds are optional. If mapIds is empty or not set // route search is limited to CCPs static data @@ -537,6 +540,7 @@ class Route extends Controller\AccessController { $returnRoutData = [ 'systemFromData' => $routeData['systemFromData'], 'systemToData' => $routeData['systemToData'], + 'skipSearch' => (bool) $routeData['skipSearch'], 'maps' => $mapData, 'mapIds' => $mapIds ]; @@ -544,7 +548,10 @@ class Route extends Controller\AccessController { // add filter options for each route as well $returnRoutData += $filterData; - if(count($mapIds) > 0){ + if( + !$returnRoutData['skipSearch'] && + count($mapIds) > 0 + ){ $systemFrom = $routeData['systemFromData']['name']; $systemTo = $routeData['systemToData']['name']; diff --git a/app/main/controller/api/signature.php b/app/main/controller/api/signature.php index 03795fab..3d2c8cb4 100644 --- a/app/main/controller/api/signature.php +++ b/app/main/controller/api/signature.php @@ -97,7 +97,7 @@ class Signature extends Controller\AccessController { // this key should not be saved (it is an obj) unset($data['updated']); - $system->getById( (int)$data['systemId']); + $system->getById( (int)$data['systemId'], 0); if( !$system->dry() ){ // update/save signature diff --git a/app/main/controller/api/user.php b/app/main/controller/api/user.php index 552d078d..6721f5e4 100644 --- a/app/main/controller/api/user.php +++ b/app/main/controller/api/user.php @@ -264,21 +264,9 @@ class User extends Controller\Controller{ // sharing config ------------------------------------------------------------- if(isset($formData['share'])){ - $privateSharing = 0; - $corporationSharing = 0; - $allianceSharing = 0; - - if(isset($formData['privateSharing'])){ - $privateSharing = 1; - } - - if(isset($formData['corporationSharing'])){ - $corporationSharing = 1; - } - - if(isset($formData['allianceSharing'])){ - $allianceSharing = 1; - } + $privateSharing = (int)$formData['privateSharing']; + $corporationSharing = (int)$formData['corporationSharing']; + $allianceSharing = (int)$formData['allianceSharing']; // update private/corp/ally $corporation = $activeCharacter->getCorporation(); @@ -298,6 +286,13 @@ class User extends Controller\Controller{ $activeCharacter->save(); } + // character config ----------------------------------------------------------- + if(isset($formData['character'])){ + $activeCharacter->logLocation = (int)$formData['logLocation']; + + $activeCharacter->save(); + } + // get fresh updated user object $newUserData = $user->getData(); } diff --git a/app/main/cron/mapupdate.php b/app/main/cron/mapupdate.php index 6ca8912f..39dc5cfd 100644 --- a/app/main/cron/mapupdate.php +++ b/app/main/cron/mapupdate.php @@ -8,6 +8,7 @@ namespace cron; use DB; +use Model; class MapUpdate { @@ -62,6 +63,48 @@ class MapUpdate { $log->write( sprintf(self::LOG_TEXT_MAPS, __FUNCTION__, $deletedMapsCount) ); } + /** + * delete expired connections (EOL connections) + * >> php index.php "/cron/deleteConnections" + * @param \Base $f3 + */ + function deleteConnections(\Base $f3){ + $eolExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_EOL'); + + if($eolExpire > 0){ + $pfDB = DB\Database::instance()->getDB('PF'); + + $sql = "SELECT + `con`.`id` + FROM + `connection` `con` INNER JOIN + `map` ON + `map`.`id` = `con`.`mapId` + WHERE + `map`.`deleteExpiredConnections` = :deleteExpiredConnections AND + TIMESTAMPDIFF(SECOND, `con`.`eolUpdated`, NOW() ) > :expire_time + "; + + $connectionsData = $pfDB->exec($sql, [ + 'deleteExpiredConnections' => 1, + 'expire_time' => $eolExpire + ]); + + if($connectionsData){ + /** + * @var $connection Model\ConnectionModel + */ + $connection = Model\BasicModel::getNew('ConnectionModel'); + foreach($connectionsData as $data){ + $connection->getById( (int)$data['id'] ); + if( !$connection->dry() ){ + $connection->erase(); + } + } + } + } + } + /** * delete all expired signatures on "inactive" systems * >> php index.php "/cron/deleteSignatures" @@ -84,7 +127,6 @@ class MapUpdate { $pfDB->exec($sqlDeleteExpiredSignatures, ['lifetime' => $signatureExpire]); } - } } \ No newline at end of file diff --git a/app/main/model/alliancemapmodel.php b/app/main/model/alliancemapmodel.php index 9cb3a89e..f8e29c5d 100644 --- a/app/main/model/alliancemapmodel.php +++ b/app/main/model/alliancemapmodel.php @@ -49,9 +49,7 @@ class AllianceMapModel extends BasicModel { * see parent */ public function clearCacheData(){ - parent::clearCacheData(); - - // clear map cache as well + // clear map cache $this->mapId->clearCacheData(); } diff --git a/app/main/model/alliancemodel.php b/app/main/model/alliancemodel.php index 76f414e6..b762fa49 100644 --- a/app/main/model/alliancemodel.php +++ b/app/main/model/alliancemodel.php @@ -41,7 +41,7 @@ class AllianceModel extends BasicModel { /** * get all alliance data - * @return array + * @return \stdClass */ public function getData(){ $allianceData = (object) []; diff --git a/app/main/model/basicmodel.php b/app/main/model/basicmodel.php index 959d0f98..ca541765 100644 --- a/app/main/model/basicmodel.php +++ b/app/main/model/basicmodel.php @@ -92,6 +92,11 @@ abstract class BasicModel extends \DB\Cortex { */ protected $fieldChanges = []; + /** + * default TTL for getData(); cache + */ + const DEFAULT_CACHE_TTL = 120; + public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0){ $this->addStaticFieldConfig(); @@ -105,7 +110,6 @@ abstract class BasicModel extends \DB\Cortex { $this->afterinsert(function($self, $pkeys){ $self->afterInsertEvent($self, $pkeys); - $self->clearCacheData(); }); // update events ------------------------------------------------------------------------------------ @@ -115,7 +119,6 @@ abstract class BasicModel extends \DB\Cortex { $this->afterupdate( function($self, $pkeys){ $self->afterUpdateEvent($self, $pkeys); - $self->clearCacheData(); }); // erase events ------------------------------------------------------------------------------------- @@ -318,6 +321,14 @@ abstract class BasicModel extends \DB\Cortex { return $valid; } + /** + * get key for for all objects in this table + * @return string + */ + private function getTableCacheKey(){ + return $this->dataCacheKeyPrefix .'.' . strtoupper($this->table); + } + /** * get the cache key for this model * ->do not set a key if the model is not saved! @@ -329,14 +340,12 @@ abstract class BasicModel extends \DB\Cortex { // set a model unique cache key if the model is saved if( $this->id > 0){ + $cacheKey = $this->getTableCacheKey(); + // check if there is a given key prefix // -> if not, use the standard key. // this is useful for caching multiple data sets according to one row entry - - $cacheKey = $this->dataCacheKeyPrefix; - $cacheKey .= '.' . strtoupper($this->table); - - if($dataCacheTableKeyPrefix){ + if( !empty($dataCacheTableKeyPrefix) ){ $cacheKey .= '.' . $dataCacheTableKeyPrefix . '_'; }else{ $cacheKey .= '.ID_'; @@ -353,13 +362,14 @@ abstract class BasicModel extends \DB\Cortex { * @return \stdClass|null */ protected function getCacheData($dataCacheKeyPrefix = ''){ - - $cacheKey = $this->getCacheKey($dataCacheKeyPrefix); $cacheData = null; + // table cache exists + // -> check cache for this row data + $cacheKey = $this->getCacheKey($dataCacheKeyPrefix); + if( !is_null($cacheKey) ){ $f3 = self::getF3(); - if( $f3->exists($cacheKey) ){ $cacheData = $f3->get( $cacheKey ); } @@ -374,15 +384,14 @@ abstract class BasicModel extends \DB\Cortex { * @param string $dataCacheKeyPrefix * @param int $data_ttl */ - public function updateCacheData($cacheData, $dataCacheKeyPrefix = '', $data_ttl = 300){ - + public function updateCacheData($cacheData, $dataCacheKeyPrefix = '', $data_ttl = self::DEFAULT_CACHE_TTL){ $cacheDataTmp = (array)$cacheData; // check if data should be cached // and cacheData is not empty if( $data_ttl > 0 && - !empty( $cacheDataTmp ) + !empty($cacheDataTmp) ){ $cacheKey = $this->getCacheKey($dataCacheKeyPrefix); @@ -394,13 +403,30 @@ abstract class BasicModel extends \DB\Cortex { /** * unset the getData() cache for this object + * -> see also clearCacheDataWithPrefix(), for more information */ public function clearCacheData(){ $cacheKey = $this->getCacheKey(); + $this->clearCache($cacheKey); + } - if( !is_null($cacheKey) ){ + /** + * unset object cached data by prefix + * -> primarily used by object cache with multiple data caches + * @param string $dataCacheKeyPrefix + */ + public function clearCacheDataWithPrefix($dataCacheKeyPrefix = ''){ + $cacheKey = $this->getCacheKey($dataCacheKeyPrefix); + $this->clearCache($cacheKey); + } + + /** + * unset object cached data (if exists) + * @param $cacheKey + */ + private function clearCache($cacheKey){ + if( !empty($cacheKey) ){ $f3 = self::getF3(); - if( $f3->exists($cacheKey) ){ $f3->clear($cacheKey); } diff --git a/app/main/model/characterlogmodel.php b/app/main/model/characterlogmodel.php index 2d9b8dc2..dc6e0cb8 100644 --- a/app/main/model/characterlogmodel.php +++ b/app/main/model/characterlogmodel.php @@ -16,14 +16,6 @@ class CharacterLogModel extends BasicModel { protected $table = 'character_log'; - /** - * caching for relational data - * -> 5s matches REST API - Expire: Header-Data - * for "Location" calls - * @var int - */ - protected $rel_ttl = 5; - protected $fieldConf = [ 'active' => [ 'type' => Schema::DT_BOOL, @@ -203,6 +195,45 @@ class CharacterLogModel extends BasicModel { return $systemId; } + /** + * Event "Hook" function + * return false will stop any further action + * @param self $self + * @param $pkeys + */ + public function afterInsertEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * return false will stop any further action + * @param self $self + * @param $pkeys + */ + public function afterUpdateEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * can be overwritten + * @param self $self + * @param $pkeys + */ + public function afterEraseEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * see parent + */ + public function clearCacheData(){ + // clear character "LOG" cache + // -> character data without "LOG" has not changed! + $this->characterId->clearCacheDataWithPrefix(CharacterModel::DATA_CACHE_KEY_LOG); + } + /** * update session data for active character * @param int $systemId diff --git a/app/main/model/charactermapmodel.php b/app/main/model/charactermapmodel.php index fadb8793..1ca0366f 100644 --- a/app/main/model/charactermapmodel.php +++ b/app/main/model/charactermapmodel.php @@ -49,9 +49,7 @@ class CharacterMapModel extends BasicModel { * see parent */ public function clearCacheData(){ - parent::clearCacheData(); - - // clear map cache as well + // clear map cache $this->mapId->clearCacheData(); } diff --git a/app/main/model/charactermodel.php b/app/main/model/charactermodel.php index b81089b5..e5f2bb6b 100644 --- a/app/main/model/charactermodel.php +++ b/app/main/model/charactermodel.php @@ -16,6 +16,11 @@ class CharacterModel extends BasicModel { protected $table = 'character'; + /** + * cache key prefix for getData(); result WITH log data + */ + const DATA_CACHE_KEY_LOG = 'LOG'; + protected $fieldConf = [ 'lastLogin' => [ 'type' => Schema::DT_TIMESTAMP, @@ -84,6 +89,11 @@ class CharacterModel extends BasicModel { 'nullable' => false, 'default' => 0 ], + 'logLocation' => [ + 'type' => Schema::DT_BOOL, + 'nullable' => false, + 'default' => 1 + ], 'userCharacter' => [ 'has-one' => ['Model\UserCharacterModel', 'characterId'] ], @@ -107,19 +117,20 @@ class CharacterModel extends BasicModel { $cacheKeyModifier = ''; // check if there is cached data + // -> IMPORTANT: $addCharacterLogData is optional! -> therefore we need 2 cache keys! if($addCharacterLogData){ - $cacheKeyModifier = strtoupper($this->table) . '_LOG'; + $cacheKeyModifier = self::DATA_CACHE_KEY_LOG; } - $characterData = $this->getCacheData($cacheKeyModifier); if(is_null($characterData)){ - // no cached character data found + $characterData = (object) []; $characterData->id = $this->id; $characterData->name = $this->name; $characterData->shared = $this->shared; + $characterData->logLocation = $this->logLocation; if($addCharacterLogData){ if($logModel = $this->getLog()){ @@ -140,7 +151,7 @@ class CharacterModel extends BasicModel { // max caching time for a system // the cached date has to be cleared manually on any change // this includes system, connection,... changes (all dependencies) - $this->updateCacheData($characterData, $cacheKeyModifier, 10); + $this->updateCacheData($characterData, $cacheKeyModifier); } return $characterData; @@ -180,6 +191,56 @@ class CharacterModel extends BasicModel { return $accessToken; } + public function set_logLocation($logLocation){ + $logLocation = (bool)$logLocation; + if( + !$logLocation && + $logLocation !== $this->logLocation && + $this->hasLog() + ){ + $this->getLog()->erase(); + } + + return $logLocation; + } + + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterInsertEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterUpdateEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterEraseEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * see parent + */ + public function clearCacheData(){ + parent::clearCacheData(); + + // clear data with "log" as well! + parent::clearCacheDataWithPrefix(self::DATA_CACHE_KEY_LOG); + } + /** * check whether this character has already a user assigned to it * @return bool @@ -188,6 +249,14 @@ class CharacterModel extends BasicModel { return is_object($this->userCharacter); } + /** + * check whether this character has an active location log + * @return bool + */ + public function hasLog(){ + return is_object($this->characterLog); + } + /** * check whether this character has a corporation * @return bool @@ -341,29 +410,32 @@ class CharacterModel extends BasicModel { * @return $this */ public function updateLog($additionalOptions = []){ - // Try to pull data from CREST - $ssoController = new Sso(); - $logData = $ssoController->getCharacterLocationData($this->getAccessToken(), $additionalOptions); + //check if log update is enabled for this user + if( $this->logLocation ){ + // Try to pull data from CREST + $ssoController = new Sso(); + $logData = $ssoController->getCharacterLocationData($this->getAccessToken(), $additionalOptions); - if($logData['timeout'] === false){ - if( empty($logData['system']) ){ - // character is not in-game - if(is_object($this->characterLog)){ - // delete existing log - $this->characterLog->erase(); - $this->save(); - } - }else{ - // character is currently in-game - if( !$characterLog = $this->getLog() ){ - // create new log - $characterLog = $this->rel('characterLog'); - $characterLog->characterId = $this->_id; - } - $characterLog->setData($logData); - $characterLog->save(); + if($logData['timeout'] === false){ + if( empty($logData['system']) ){ + // character is not in-game + if( $this->hasLog() ){ + // delete existing log + $this->characterLog->erase(); + $this->save(); + } + }else{ + // character is currently in-game + if( !$characterLog = $this->getLog() ){ + // create new log + $characterLog = $this->rel('characterLog'); + $characterLog->characterId = $this->_id; + } + $characterLog->setData($logData); + $characterLog->save(); - $this->characterLog = $characterLog; + $this->characterLog = $characterLog; + } } } @@ -445,7 +517,7 @@ class CharacterModel extends BasicModel { public function getLog(){ $characterLog = false; if( - is_object($this->characterLog) && + $this->hasLog() && !$this->characterLog->dry() ){ $characterLog = &$this->characterLog; diff --git a/app/main/model/connectionmodel.php b/app/main/model/connectionmodel.php index 70a6abe6..0b50281c 100644 --- a/app/main/model/connectionmodel.php +++ b/app/main/model/connectionmodel.php @@ -224,8 +224,7 @@ class ConnectionModel extends BasicModel{ * @param $pkeys */ public function afterInsertEvent($self, $pkeys){ - parent::afterInsertEvent($self, $pkeys); - + $self->clearCacheData(); $self->logActivity('connectionCreate'); } @@ -236,8 +235,7 @@ class ConnectionModel extends BasicModel{ * @param $pkeys */ public function afterUpdateEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); - + $self->clearCacheData(); $self->logActivity('connectionUpdate'); } @@ -248,8 +246,7 @@ class ConnectionModel extends BasicModel{ * @param $pkeys */ public function afterEraseEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); - + $self->clearCacheData(); $self->logActivity('connectionDelete'); } @@ -302,9 +299,6 @@ class ConnectionModel extends BasicModel{ * see parent */ public function clearCacheData(){ - parent::clearCacheData(); - - // clear map cache as well $this->mapId->clearCacheData(); } diff --git a/app/main/model/corporationmapmodel.php b/app/main/model/corporationmapmodel.php index 0cac06d2..35a16e50 100644 --- a/app/main/model/corporationmapmodel.php +++ b/app/main/model/corporationmapmodel.php @@ -49,9 +49,7 @@ class CorporationMapModel extends BasicModel { * see parent */ public function clearCacheData(){ - parent::clearCacheData(); - - // clear map cache as well + // clear map cache $this->mapId->clearCacheData(); } diff --git a/app/main/model/corporationmodel.php b/app/main/model/corporationmodel.php index e9148021..240f8158 100644 --- a/app/main/model/corporationmodel.php +++ b/app/main/model/corporationmodel.php @@ -46,7 +46,7 @@ class CorporationModel extends BasicModel { /** * get all cooperation data - * @return array + * @return \stdClass */ public function getData(){ $cooperationData = (object) []; diff --git a/app/main/model/mapmodel.php b/app/main/model/mapmodel.php index 0293444f..159a9413 100644 --- a/app/main/model/mapmodel.php +++ b/app/main/model/mapmodel.php @@ -55,6 +55,11 @@ class MapModel extends BasicModel { 'nullable' => false, 'default' => '' ], + 'deleteExpiredConnections' => [ + 'type' => Schema::DT_BOOL, + 'nullable' => false, + 'default' => 1 + ], 'systems' => [ 'has-many' => ['Model\SystemModel', 'mapId'] ], @@ -134,6 +139,7 @@ class MapModel extends BasicModel { $mapData->id = $this->id; $mapData->name = $this->name; $mapData->icon = $this->icon; + $mapData->deleteExpiredConnections = $this->deleteExpiredConnections; $mapData->created = strtotime($this->created); $mapData->updated = strtotime($this->updated); @@ -194,12 +200,39 @@ class MapModel extends BasicModel { // max caching time for a map // the cached date has to be cleared manually on any change // this includes system, connection,... changes (all dependencies) - $this->updateCacheData($mapDataAll, '', 300); + $this->updateCacheData($mapDataAll); } return $mapDataAll; } + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterInsertEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterUpdateEvent($self, $pkeys){ + $self->clearCacheData(); + } + + /** + * Event "Hook" function + * @param self $self + * @param $pkeys + */ + public function afterEraseEvent($self, $pkeys){ + $self->clearCacheData(); + } + /** * get blank system model pre-filled with default SDE data * -> check for "inactive" systems on this map first! @@ -401,7 +434,7 @@ class MapModel extends BasicModel { } } elseif($obj instanceof AllianceModel){ - // check whether the corporation already has map access + // check whether the alliance already has map access $this->has('mapAlliances', ['active = 1 AND allianceId = :allianceId', ':allianceId' => $obj->id]); $result = $this->findone(['id = :id', ':id' => $this->id]); @@ -531,7 +564,7 @@ class MapModel extends BasicModel { /** * get data for all characters that are currently online "viewing" this map - * -> the result of this function is cached! + * -> The result of this function is cached! * @return \stdClass[] */ private function getCharactersData(){ @@ -639,13 +672,7 @@ class MapModel extends BasicModel { * @return bool */ public function isPrivate(){ - $isPrivate = false; - - if($this->typeId->id == 2){ - $isPrivate = true; - } - - return $isPrivate; + return ($this->typeId->id === 2); } /** @@ -653,13 +680,7 @@ class MapModel extends BasicModel { * @return bool */ public function isCorporation(){ - $isCorporation = false; - - if($this->typeId->id == 3){ - $isCorporation = true; - } - - return $isCorporation; + return ($this->typeId->id === 3); } /** @@ -667,13 +688,7 @@ class MapModel extends BasicModel { * @return bool */ public function isAlliance(){ - $isAlliance = false; - - if($this->typeId->id == 4){ - $isAlliance = true; - } - - return $isAlliance; + return ($this->typeId->id === 4); } /** diff --git a/app/main/model/systemmodel.php b/app/main/model/systemmodel.php index a5708fc6..c6213cb6 100644 --- a/app/main/model/systemmodel.php +++ b/app/main/model/systemmodel.php @@ -277,7 +277,7 @@ class SystemModel extends BasicModel { // max caching time for a system // the cached date has to be cleared manually on any change // this includes system, connection,... changes (all dependencies) - $this->updateCacheData($systemData, '', 300); + $this->updateCacheData($systemData); } return $systemData; @@ -358,19 +358,16 @@ class SystemModel extends BasicModel { /** * Event "Hook" function - * return false will stop any further action * @param self $self * @param $pkeys */ public function afterInsertEvent($self, $pkeys){ - parent::afterInsertEvent($self, $pkeys); - + $self->clearCacheData(); $self->logActivity('systemCreate'); } /** * Event "Hook" function - * can be overwritten * return false will stop any further action * @param self $self * @param $pkeys @@ -397,12 +394,11 @@ class SystemModel extends BasicModel { /** * Event "Hook" function - * return false will stop any further action * @param self $self * @param $pkeys */ public function afterUpdateEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); + $self->clearCacheData(); // check if rally point mail should be send if( @@ -418,13 +414,11 @@ class SystemModel extends BasicModel { /** * Event "Hook" function - * can be overwritten * @param self $self * @param $pkeys */ public function afterEraseEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); - + $self->clearCacheData(); $self->logActivity('systemDelete'); } diff --git a/app/main/model/systemsignaturemodel.php b/app/main/model/systemsignaturemodel.php index be5baa0e..44385146 100644 --- a/app/main/model/systemsignaturemodel.php +++ b/app/main/model/systemsignaturemodel.php @@ -183,8 +183,6 @@ class SystemSignatureModel extends BasicModel { * @param $pkeys */ public function afterInsertEvent($self, $pkeys){ - parent::afterInsertEvent($self, $pkeys); - $self->logActivity('signatureCreate'); } @@ -195,8 +193,6 @@ class SystemSignatureModel extends BasicModel { * @param $pkeys */ public function afterUpdateEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); - $self->logActivity('signatureUpdate'); } @@ -207,8 +203,6 @@ class SystemSignatureModel extends BasicModel { * @param $pkeys */ public function afterEraseEvent($self, $pkeys){ - parent::afterUpdateEvent($self, $pkeys); - $self->logActivity('signatureDelete'); } diff --git a/app/pathfinder.ini b/app/pathfinder.ini index aaa9ec7b..00799a46 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -3,7 +3,7 @@ [PATHFINDER] NAME = Pathfinder ; installed version (used for CSS/JS cache busting) -VERSION = v1.1.6 +VERSION = v1.1.7 ; contact information [optional] CONTACT = https://github.com/exodus4d ; public contact email [optional] @@ -77,6 +77,12 @@ ACTIVITY_LOGGING = 0 ; max recursive search depth for routes (default: 7000) ; decrease it on performance problems SEARCH_DEPTH = 7000 +; default count of routes that will be checked (initial) when a system is selected (default: 2) +SEARCH_DEFAULT_COUNT = 2 +; max count of routes that can be selected in "route settings" dialog (default: 4) +MAX_Default_COUNT = 4 +; max count of routes that will be checked (MAX_COUNT + custom routes ) (default: 6) +LIMIT = 6 ; Email notifications ============================================================================= ; Requires SMTP configuration (see environment.ini) @@ -119,6 +125,8 @@ CHARACTER_LOG = 300 CONSTELLATION_SYSTEMS = 1728000 ; max expire time. Expired cache files will be deleted by cronjob (seconds) (default: 10d) EXPIRE_MAX = 864000 +; expire time for EOL (end of life) connections (seconds) (default: 4h + 15min) +EXPIRE_CONNECTIONS_EOL = 15300 ; expire time for signatures (inactive systems) (seconds) (default 3d) EXPIRE_SIGNATURES = 259200 diff --git a/export/csv/system_wormhole.csv b/export/csv/system_wormhole.csv index 2a3a263c..7ab7caaa 100644 --- a/export/csv/system_wormhole.csv +++ b/export/csv/system_wormhole.csv @@ -81,7 +81,7 @@ "80";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002550";"68"; "81";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002516";"6"; "82";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002516";"21"; -"83";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002534";"18"; +"83";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002534";"30"; "84";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002534";"59"; "85";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002508";"39"; "86";"2016-07-16 13:53:20";"2016-07-16 13:53:20";"31002508";"28"; diff --git a/export/sql/pathfinder.sql b/export/sql/pathfinder.sql index a5149a9a..ddeb01d3 100644 --- a/export/sql/pathfinder.sql +++ b/export/sql/pathfinder.sql @@ -204,7 +204,7 @@ INSERT INTO `system_wormhole` (`id`, `created`, `updated`, `systemId`, `wormhole (80, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002550, 68), (81, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002516, 6), (82, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002516, 21), - (83, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002534, 18), + (83, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002534, 30), (84, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002534, 59), (85, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002508, 39), (86, '2016-07-16 13:53:20', '2016-07-16 13:53:20', 31002508, 28), diff --git a/js/app/config/signature_type.js b/js/app/config/signature_type.js index 04547e23..97f2b056 100644 --- a/js/app/config/signature_type.js +++ b/js/app/config/signature_type.js @@ -320,7 +320,7 @@ define(['jquery'], function($) { 5: { // Wormhole 1: 'D792 - HS', 2: 'C391 - LS', - 3: 'Z142 - 0.0', + 3: 'C248 - 0.0', 4: 'F135 - Thera' }, 6: { // ORE @@ -418,4 +418,4 @@ define(['jquery'], function($) { }; return signatureTypes; -}); \ No newline at end of file +}); diff --git a/js/app/logging.js b/js/app/logging.js index 64280fde..252f668f 100644 --- a/js/app/logging.js +++ b/js/app/logging.js @@ -58,7 +58,7 @@ define([ var tableHeadline = $('