diff --git a/app/cron.ini b/app/cron.ini index 9eb31085..b37b9aaf 100644 --- a/app/cron.ini +++ b/app/cron.ini @@ -23,8 +23,11 @@ downtime = 0 11 * * * ; delete expired connections (e.g. EOL) deleteConnections = Cron\MapUpdate->deleteConnections, @fiveMinutes +; disable character log data +deactivateLogData = Cron\CharacterUpdate->deactivateLogData, @instant + ; delete character log data -deleteLogData = Cron\CharacterUpdate->deleteLogData, @tenMinutes +deleteLogData = Cron\CharacterUpdate->deleteLogData, @instant ; delete expired signatures deleteSignatures = Cron\MapUpdate->deleteSignatures, @halfHour diff --git a/app/main/cron/characterupdate.php b/app/main/cron/characterupdate.php index 042d9242..ea4bbafb 100644 --- a/app/main/cron/characterupdate.php +++ b/app/main/cron/characterupdate.php @@ -13,32 +13,90 @@ use Model; class CharacterUpdate { + const CHARACTER_LOG_ACTIVE = 300; + const CHARACTER_LOG_INACTIVE = 300; + /** - * delete all character log data + * get "active" time for character log data in seconds + * -> get default value in case of nothing found in *.ini file + * @param \Base $f3 + * @return int + */ + protected function getCharacterLogActiveTime($f3){ + $logActiveTime = (int)$f3->get('PATHFINDER.CACHE.CHARACTER_LOG_ACTIVE'); + return ($logActiveTime >= 0) ? $logActiveTime : self::CHARACTER_LOG_ACTIVE; + } + + /** + * get "incactive" time for character log data in seconeds + * @param \Base $f3 + * @return int + */ + protected function getCharacterLogInactiveTime($f3){ + $logInactiveTime = (int)$f3->get('PATHFINDER.CACHE.CHARACTER_LOG_INACTIVE'); + return ($logInactiveTime >= 0) ? $logInactiveTime : self::CHARACTER_LOG_INACTIVE; + } + + /** + * set character log data as inactive in case of not changed within X seconds + * >> php index.php "/cron/deactivateLogData" + * @param \Base $f3 + */ + function deactivateLogData($f3){ + DB\Database::instance()->getDB('PF'); + $logActiveTime = $this->getCharacterLogActiveTime($f3); + + /** + * @var $characterLogModel Model\CharacterLogModel + */ + $characterLogModel = Model\BasicModel::getNew('CharacterLogModel', 0); + + // find expired character logs + $characterLogs = $characterLogModel->find([ + 'active = :active AND TIMESTAMPDIFF(SECOND, updated, NOW() ) > :lifetime', + ':active' => 1, + ':lifetime' => $logActiveTime + ]); + + if(is_object($characterLogs)){ + foreach($characterLogs as $characterLog){ + /** + * @var $characterLog Model\CharacterLogModel + */ + $characterLog->setActive(false); + $characterLog->save(); + } + } + } + + /** + * delete all character log data that were set to "active = 0" after X seconds of no changes + * -> see deactivateLogData() * >> php index.php "/cron/deleteLogData" * @param \Base $f3 */ function deleteLogData($f3){ - $logExpire = (int)$f3->get('PATHFINDER.CACHE.CHARACTER_LOG'); + DB\Database::instance()->getDB('PF'); + $logInactiveTime = $this->getCharacterLogInactiveTime($f3); - if($logExpire > 0){ - DB\Database::instance()->getDB('PF'); + /** + * @var $characterLogModel Model\CharacterLogModel + */ + $characterLogModel = Model\BasicModel::getNew('CharacterLogModel', 0); - /** - * @var $characterLogModel Model\CharacterLogModel - */ - $characterLogModel = Model\BasicModel::getNew('CharacterLogModel', 0); + // find expired character logs + $characterLogs = $characterLogModel->find([ + 'active = :active AND TIMESTAMPDIFF(SECOND, updated, NOW() ) > :lifetime', + ':active' => 0, + ':lifetime' => $logInactiveTime + ]); - // find expired character logs - $characterLogs = $characterLogModel->find([ - 'TIMESTAMPDIFF(SECOND, updated, NOW() ) > :lifetime', - ':lifetime' => $logExpire - ]); - - if(is_object($characterLogs)){ - foreach($characterLogs as $characterLog){ - $characterLog->erase(); - } + if(is_object($characterLogs)){ + foreach($characterLogs as $characterLog){ + /** + * @var $characterLog Model\CharacterLogModel + */ + $characterLog->erase(); } } } diff --git a/app/main/model/basicmodel.php b/app/main/model/basicmodel.php index be7277c7..8b547500 100644 --- a/app/main/model/basicmodel.php +++ b/app/main/model/basicmodel.php @@ -48,14 +48,6 @@ abstract class BasicModel extends \DB\Cortex { */ protected $validate = []; - /** - * enables change for "active" column - * -> see setActive(); - * -> $this->active = false; will NOT work (prevent abuse)! - * @var bool - */ - protected $allowActiveChange = false; - /** * enables check for $fieldChanges on update/insert * -> fields that should be checked need an "activity-log" flag @@ -64,6 +56,14 @@ abstract class BasicModel extends \DB\Cortex { */ protected $enableActivityLogging = true; + /** + * enables change for "active" column + * -> see setActive(); + * -> $this->active = false; will NOT work (prevent abuse)! + * @var bool + */ + private $allowActiveChange = false; + /** * getData() cache key prefix * -> do not change, otherwise cached data is lost diff --git a/app/main/model/characterlogmodel.php b/app/main/model/characterlogmodel.php index 65714a39..ff2fa427 100644 --- a/app/main/model/characterlogmodel.php +++ b/app/main/model/characterlogmodel.php @@ -116,6 +116,7 @@ class CharacterLogModel extends BasicModel { public function getData(){ $logData = (object) []; + $logData->active = $this->active; $logData->system = (object) []; $logData->system->id = (int)$this->systemId; $logData->system->name = $this->systemName; @@ -134,16 +135,60 @@ class CharacterLogModel extends BasicModel { } /** + * setter for systemId * @param int $systemId * @return int */ public function set_systemId($systemId){ + if($this->systemId != $systemId){ + $this->setActive(true); + } + if($systemId > 0){ $this->updateCharacterSessionLocation($systemId); } return $systemId; } + /** + * setter for $shipTypeId + * @param int $shipTypeId + * @return int + */ + public function set_shipTypeId($shipTypeId){ + if($this->shipTypeId != $shipTypeId){ + $this->setActive(true); + } + + return $shipTypeId; + } + + /** + * setter for $shipId + * @param int $shipId + * @return int + */ + public function set_shipId($shipId){ + if($this->shipId != $shipId){ + $this->setActive(true); + } + + return $shipId; + } + + /** + * setter for $stationId + * @param int $stationId + * @return int + */ + public function set_stationId($stationId){ + if($this->stationId != $stationId){ + $this->setActive(true); + } + + return $stationId; + } + /** * Event "Hook" function * return false will stop any further action diff --git a/app/main/model/mapmodel.php b/app/main/model/mapmodel.php index 47b74660..2640418b 100644 --- a/app/main/model/mapmodel.php +++ b/app/main/model/mapmodel.php @@ -266,8 +266,14 @@ class MapModel extends BasicModel { // get blank system $systemController = new System(); $systems = $systemController->getSystemModelByIds([$systemId]); - $system = reset($systems); - $system->mapId = $this->_id; + if( count($systems) ){ + $system = reset($systems); + $system->mapId = $this->_id; + }else{ + // should NEVER happen -> systemId does NOT exist in New Eden!! + $this->getF3()->error(500, 'SystemId "' . $systemId . '"" does not exist in EVE!' ); + } + } $system->setActive(true); @@ -834,6 +840,15 @@ class MapModel extends BasicModel { // get data of characters which have with map access $activeUserCharactersData = $this->getCharactersData(); + // sort characters by "active" status + $sortByActiveLog = function($a, $b){ + if($a->log->active == $b->log->active){ + return 0; + }else{ + return ($a->log->active && !$b->log->active) ? 0 : 1; + } + }; + $mapUserData = (object)[]; $mapUserData->config = (object)[]; $mapUserData->config->id = $this->id; @@ -857,14 +872,15 @@ class MapModel extends BasicModel { unset($activeUserCharactersData[$key]); } }else{ - // user has NO log data. If its an corp/ally map not each member is active - // user is not relevant for this function! + // character has NO log data. If its an corp/ally map not each member is active + // -> character is not relevant for this function! unset($activeUserCharactersData[$key]); } } // add system if active users were found if(count($systemUserData->user) > 0){ + usort($systemUserData->user, $sortByActiveLog); $mapUserData->data->systems[] = $systemUserData; } } diff --git a/app/pathfinder.ini b/app/pathfinder.ini index 14e84a2f..0bc0b92a 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -127,8 +127,10 @@ EXECUTION_LIMIT = 50 ; CACHE =========================================================================================== [PATHFINDER.CACHE] -; expire time for character log data (seconds) (default: 5min) -CHARACTER_LOG = 300 +; mark characters inactive if nothing (ship/system/...) changed within X seconds (default: 5min) +CHARACTER_LOG_ACTIVE = 300 +; delete character log data if "inactive" for X seconds (seconds) (default: 10min) +CHARACTER_LOG_INACTIVE = 300 ; expire time for static system data (seconds) (default: 20d) CONSTELLATION_SYSTEMS = 1728000 ; max expire time. Expired cache files will be deleted by cronjob (seconds) (default: 10d) diff --git a/js/app/map/local.js b/js/app/map/local.js index 3cb6f093..e8f761f4 100644 --- a/js/app/map/local.js +++ b/js/app/map/local.js @@ -34,7 +34,12 @@ define([ tableCellEllipsisClass: 'pf-table-cell-ellipsis', tableCellEllipsis80Class: 'pf-table-cell-80', - tableCellEllipsis90Class: 'pf-table-cell-90' + tableCellEllipsis90Class: 'pf-table-cell-90', + + // toolbar + toolbarClass: 'pf-map-overlay-toolbar', // class for toolbar - content + toolbarIconClass: 'pf-map-overlay-toolbar-icon', // class for toolbar icon + toolbarCheckboxClass: 'pf-map-overlay-toolbar-checkbox' // class for toolbar checkbox }; /** @@ -322,7 +327,6 @@ define([ text: MapUtil.config.defaultLocalJumpRadius }).attr('title', 'jumps') ) - ); let headline = $('
', { @@ -342,6 +346,8 @@ define([ content.append(headline); content.append(table); + // toolbar not used for now + // content.append(initToolbar()); overlay.append(overlayMain); overlay.append(content); @@ -509,6 +515,44 @@ define([ }); }; + let initToolbar = () => { + + let getCheckbox = (options) => { + return $('
', { + class: [config.toolbarCheckboxClass, 'checkbox'].join(' ') + }).append( + $('', { + type: 'checkbox', + id: options.id, + name: options.name, + value: options.value, + checked: 'checked' + }), + $('