- 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....
364 lines
9.5 KiB
PHP
364 lines
9.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodus4d
|
|
* Date: 26.02.15
|
|
* Time: 21:12
|
|
*/
|
|
|
|
namespace Model;
|
|
|
|
use DB\SQL\Schema;
|
|
use Controller\Api\Route;
|
|
use Lib\Logging;
|
|
|
|
class ConnectionModel extends AbstractMapTrackingModel {
|
|
|
|
protected $table = 'connection';
|
|
|
|
protected $fieldConf = [
|
|
'active' => [
|
|
'type' => Schema::DT_BOOL,
|
|
'nullable' => false,
|
|
'default' => 1,
|
|
'index' => true
|
|
],
|
|
'mapId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\MapModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'map',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'source' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\SystemModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'system',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
],
|
|
'activity-log' => true
|
|
],
|
|
'target' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\SystemModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'system',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
],
|
|
'activity-log' => true
|
|
],
|
|
'scope' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => '',
|
|
'activity-log' => true
|
|
],
|
|
'type' => [
|
|
'type' => self::DT_JSON,
|
|
'activity-log' => true
|
|
],
|
|
'eolUpdated' => [
|
|
'type' => Schema::DT_TIMESTAMP,
|
|
'default' => null
|
|
],
|
|
'signatures' => [
|
|
'has-many' => ['Model\SystemSignatureModel', 'connectionId']
|
|
]
|
|
];
|
|
|
|
/**
|
|
* set an array with all data for a system
|
|
* @param array $data
|
|
*/
|
|
public function setData($data){
|
|
unset($data['id']);
|
|
unset($data['created']);
|
|
unset($data['updated']);
|
|
unset($data['createdCharacterId']);
|
|
unset($data['updatedCharacterId']);
|
|
|
|
foreach((array)$data as $key => $value){
|
|
if( !is_array($value) ){
|
|
if( $this->exists($key) ){
|
|
$this->$key = $value;
|
|
}
|
|
}elseif($key == 'type'){
|
|
// json field
|
|
$this->$key = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get connection data as array
|
|
* @param bool $addSignatureData
|
|
* @return \stdClass
|
|
*/
|
|
public function getData($addSignatureData = false){
|
|
$connectionData = (object) [];
|
|
$connectionData->id = $this->id;
|
|
$connectionData->source = $this->source->id;
|
|
$connectionData->target = $this->target->id;
|
|
$connectionData->scope = $this->scope;
|
|
$connectionData->type = $this->type;
|
|
$connectionData->updated = strtotime($this->updated);
|
|
$connectionData->created = strtotime($this->created);
|
|
$connectionData->eolUpdated = strtotime($this->eolUpdated);
|
|
|
|
if($addSignatureData){
|
|
if( !empty($signaturesData = $this->getSignaturesData()) ){
|
|
$connectionData->signatures = $signaturesData;
|
|
}
|
|
}
|
|
|
|
return $connectionData;
|
|
}
|
|
|
|
/**
|
|
* setter for connection type
|
|
* @param $type
|
|
* @return int|number
|
|
*/
|
|
public function set_type($type){
|
|
$newTypes = (array)json_decode($type);
|
|
|
|
// set EOL timestamp
|
|
if( !in_array('wh_eol', $newTypes) ){
|
|
$this->eolUpdated = null;
|
|
}elseif(
|
|
in_array('wh_eol', $newTypes) &&
|
|
!in_array('wh_eol', (array)$this->type) // $this->type == null for new connection! (e.g. map import)
|
|
){
|
|
// connection EOL status change
|
|
$this->touch('eolUpdated');
|
|
}
|
|
|
|
return $type;
|
|
}
|
|
|
|
/**
|
|
* check object for model access
|
|
* @param CharacterModel $characterModel
|
|
* @return mixed
|
|
*/
|
|
public function hasAccess(CharacterModel $characterModel){
|
|
$access = false;
|
|
if( !$this->dry() ){
|
|
$access = $this->mapId->hasAccess($characterModel);
|
|
}
|
|
return $access;
|
|
}
|
|
|
|
/**
|
|
* set default connection type by search route between endpoints
|
|
*/
|
|
public function setDefaultTypeData(){
|
|
if(
|
|
is_object($this->source) &&
|
|
is_object($this->target)
|
|
){
|
|
$routeController = new Route();
|
|
$routeController->initJumpData();
|
|
$route = $routeController->findRoute($this->source->name, $this->target->name, 1);
|
|
|
|
if($route['routePossible']){
|
|
$this->scope = 'stargate';
|
|
$this->type = ['stargate'];
|
|
}else{
|
|
$this->scope = 'wh';
|
|
$this->type = ['wh_fresh'];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* check whether this connection is a wormhole or not
|
|
* @return bool
|
|
*/
|
|
public function isWormhole(){
|
|
return ($this->scope === 'wh');
|
|
}
|
|
|
|
/**
|
|
* check whether this model is valid or not
|
|
* @return bool
|
|
*/
|
|
public function isValid(): bool {
|
|
if($valid = parent::isValid()){
|
|
// check if source/target system are not equal
|
|
// check if source/target belong to same map
|
|
if(
|
|
is_object($this->source) &&
|
|
is_object($this->target) &&
|
|
$this->get('source', true) === $this->get('target', true) ||
|
|
$this->source->get('mapId', true) !== $this->target->get('mapId', true)
|
|
){
|
|
$valid = false;
|
|
}
|
|
}
|
|
|
|
return $valid;
|
|
}
|
|
|
|
/**
|
|
* Event "Hook" function
|
|
* can be overwritten
|
|
* return false will stop any further action
|
|
* @param ConnectionModel $self
|
|
* @param $pkeys
|
|
* @return bool
|
|
*/
|
|
public function beforeInsertEvent($self, $pkeys){
|
|
// check for "default" connection type and add them if missing
|
|
// -> get() with "true" returns RAW data! important for JSON table column check!
|
|
$types = (array)json_decode( $this->get('type', true) );
|
|
if(
|
|
!$this->scope ||
|
|
empty($types)
|
|
){
|
|
$this->setDefaultTypeData();
|
|
}
|
|
|
|
return $this->isValid() ? parent::beforeInsertEvent($self, $pkeys) : false;
|
|
}
|
|
|
|
/**
|
|
* Event "Hook" function
|
|
* return false will stop any further action
|
|
* @param self $self
|
|
* @param $pkeys
|
|
*/
|
|
public function afterInsertEvent($self, $pkeys){
|
|
$self->clearCacheData();
|
|
$self->logActivity('connectionCreate');
|
|
}
|
|
|
|
/**
|
|
* Event "Hook" function
|
|
* return false will stop any further action
|
|
* @param self $self
|
|
* @param $pkeys
|
|
*/
|
|
public function afterUpdateEvent($self, $pkeys){
|
|
$self->clearCacheData();
|
|
$self->logActivity('connectionUpdate');
|
|
}
|
|
|
|
/**
|
|
* Event "Hook" function
|
|
* can be overwritten
|
|
* @param self $self
|
|
* @param $pkeys
|
|
*/
|
|
public function afterEraseEvent($self, $pkeys){
|
|
$self->clearCacheData();
|
|
$self->logActivity('connectionDelete');
|
|
}
|
|
|
|
/**
|
|
* @param string $action
|
|
* @return Logging\LogInterface
|
|
*/
|
|
public function newLog($action = ''): Logging\LogInterface{
|
|
return $this->getMap()->newLog($action)->setTempData($this->getLogObjectData());
|
|
}
|
|
|
|
/**
|
|
* @return MapModel
|
|
*/
|
|
public function getMap(): MapModel{
|
|
return $this->get('mapId');
|
|
}
|
|
|
|
/**
|
|
* delete a connection
|
|
* @param CharacterModel $characterModel
|
|
*/
|
|
public function delete(CharacterModel $characterModel){
|
|
if( !$this->dry() ){
|
|
// check if character has access
|
|
if($this->hasAccess($characterModel)){
|
|
$this->erase();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get object relevant data for model log
|
|
* @return array
|
|
*/
|
|
public function getLogObjectData() : array{
|
|
return [
|
|
'objId' => $this->_id,
|
|
'objName' => $this->scope
|
|
];
|
|
}
|
|
|
|
/**
|
|
* see parent
|
|
*/
|
|
public function clearCacheData(){
|
|
$this->mapId->clearCacheData();
|
|
}
|
|
|
|
/**
|
|
* get all signatures that are connected with this connection
|
|
* @return array|mixed
|
|
*/
|
|
public function getSignatures(){
|
|
$signatures = [];
|
|
$this->filter('signatures', [
|
|
'active = :active',
|
|
':active' => 1
|
|
]);
|
|
|
|
if($this->signatures){
|
|
$signatures = $this->signatures;
|
|
}
|
|
|
|
return $signatures;
|
|
}
|
|
|
|
/**
|
|
* get all signature data linked to this connection
|
|
* @return array
|
|
*/
|
|
public function getSignaturesData(){
|
|
$signaturesData = [];
|
|
$signatures = $this->getSignatures();
|
|
|
|
foreach($signatures as $signature){
|
|
$signaturesData[] = $signature->getData();
|
|
}
|
|
|
|
return $signaturesData;
|
|
}
|
|
|
|
/**
|
|
* overwrites parent
|
|
* @param null $db
|
|
* @param null $table
|
|
* @param null $fields
|
|
* @return bool
|
|
*/
|
|
public static function setup($db=null, $table=null, $fields=null){
|
|
$status = parent::setup($db,$table,$fields);
|
|
|
|
if($status === true){
|
|
$status = parent::setMultiColumnIndex(['source', 'target', 'scope']);
|
|
}
|
|
|
|
return $status;
|
|
}
|
|
}
|