Files
pathfinder/app/main/model/characterlogmodel.php
Exodus4D a8edf39697 - new "logging" system for map/system/signature/connection changes, closed #271
- new map change log to Slack channel
- new "rally point" logging to Slack channel
- new "rally point" poke options (e.g. custom message), closed #295
- new log options for WebSocket installations
- added ship "mass" logging (backend only), #313
- added map logging to Slack, #326
- added "ESI error rate" limit detection
- added "Monolog" as new logging library (Composer dependency)
- added "Swiftmailer" as new eMail library (Composer dependency)
- added Support for Redis session hander (performance boost)
- improved character select panels (visible "online" status)
- improved "activity logging" (more DB columns added to check)
- improved eMail logging (HTML template support)
- improved "delete map" now become "inactive" for some days before delete
- improved character logout handling
- improved /setup page for DB bootstrap (new button for DB create if not exists)
- fixed broken ship tracking (ship name re-added)
- fixed broken ship tracking for multiple chars on different browser tabs
- fixed broken cursor coordinates, closed #518
- fixed null pointer "charactermodel.php->isActive():925" closed #529
- fixed broken "scroll offset", closed #533 closed #534
- Updated "validation" library JS v0.10.1 -> v0.11.9
- Updated ORM Mapper _Cortex_ v1.5.0-dev -> v1.5.0
- and many more....
2017-10-22 17:58:34 +02:00

225 lines
6.2 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 30.03.15
* Time: 00:04
*/
namespace Model;
use Controller\Api\User as User;
use Controller\Controller as Controller;
use DB\SQL\Schema;
class CharacterLogModel extends BasicModel {
protected $table = 'character_log';
protected $fieldConf = [
'active' => [
'type' => Schema::DT_BOOL,
'nullable' => false,
'default' => 1,
'index' => true
],
'characterId' => [
'type' => Schema::DT_INT,
'index' => true,
'unique' => true,
'belongs-to-one' => 'Model\CharacterModel',
'constraint' => [
[
'table' => 'character',
'on-delete' => 'CASCADE'
]
]
],
'systemId' => [
'type' => Schema::DT_INT,
'index' => true
],
'systemName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
],
'shipTypeId' => [
'type' => Schema::DT_INT,
'index' => true
],
'shipTypeName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
],
'shipId' => [
'type' => Schema::DT_BIGINT,
'index' => true
],
'shipMass' => [
'type' => Schema::DT_FLOAT,
'nullable' => false,
'default' => 0
],
'shipName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
],
'stationId' => [
'type' => Schema::DT_INT,
'index' => true
],
'stationName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
]
];
/**
* set log data from array
* @param array $logData
*/
public function setData($logData){
if( isset($logData['system']) ){
$this->systemId = (int)$logData['system']['id'];
$this->systemName = $logData['system']['name'];
}else{
$this->systemId = null;
$this->systemName = '';
}
if( isset($logData['ship']) ){
$this->shipTypeId = (int)$logData['ship']['typeId'];
$this->shipTypeName = $logData['ship']['typeName'];
$this->shipId = (int)$logData['ship']['id'];
$this->shipName = $logData['ship']['name'];
$this->shipMass = (float)$logData['ship']['mass'];
}else{
$this->shipTypeId = null;
$this->shipTypeName = '';
$this->shipId = null;
$this->shipName = '';
$this->shipMass = 0;
}
if( isset($logData['station']) ){
$this->stationId = (int)$logData['station']['id'];
$this->stationName = $logData['station']['name'];
}else{
$this->stationId = null;
$this->stationName = '';
}
}
/**
* get all character log data
* @return object
*/
public function getData(){
$logData = (object) [];
$logData->system = (object) [];
$logData->system->id = (int)$this->systemId;
$logData->system->name = $this->systemName;
$logData->ship = (object) [];
$logData->ship->typeId = (int)$this->shipTypeId;
$logData->ship->typeName = $this->shipTypeName;
$logData->ship->id = $this->shipId;
$logData->ship->name = $this->shipName;
$logData->ship->mass = $this->shipMass;
$logData->station = (object) [];
$logData->station->id = (int)$this->stationId;
$logData->station->name = $this->stationName;
return $logData;
}
/**
* setter for systemId
* @param int $systemId
* @return int
*/
public function set_systemId($systemId){
if($systemId > 0){
$this->updateCharacterSessionLocation($systemId);
}
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!
if($this->characterId){
// characterId relation could be deleted by cron therefore check again first...
$this->characterId->clearCacheDataWithPrefix(CharacterModel::DATA_CACHE_KEY_LOG);
}
}
/**
* update session data for active character
* @param int $systemId
*/
protected function updateCharacterSessionLocation(int $systemId){
$controller = new Controller();
if(
!empty($sessionCharacter = $controller->getSessionCharacterData()) &&
$sessionCharacter['ID'] === $this->get('characterId', true)
){
$systemChanged = false;
if((int)$sessionCharacter['PREV_SYSTEM_ID'] === 0){
$sessionCharacter['PREV_SYSTEM_ID'] = (int)$systemId;
$systemChanged = true;
}elseif((int)$sessionCharacter['PREV_SYSTEM_ID'] !== $this->systemId){
$sessionCharacter['PREV_SYSTEM_ID'] = $this->systemId;
$systemChanged = true;
}
if($systemChanged){
$sessionCharacters = CharacterModel::mergeSessionCharacterData([$sessionCharacter]);
$this->getF3()->set(User::SESSION_KEY_CHARACTERS, $sessionCharacters);
}
}
}
}