- 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....
139 lines
3.9 KiB
PHP
139 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodu
|
|
* Date: 25.08.2017
|
|
* Time: 18:45
|
|
*/
|
|
|
|
namespace Model;
|
|
|
|
use DB\SQL\Schema;
|
|
|
|
abstract class AbstractMapTrackingModel extends BasicModel implements LogModelInterface {
|
|
|
|
private $trackingFieldConf = [
|
|
'createdCharacterId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\CharacterModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'character',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
],
|
|
'validate' => 'validate_notDry'
|
|
],
|
|
'updatedCharacterId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\CharacterModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'character',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
],
|
|
'validate' => 'validate_notDry'
|
|
]
|
|
];
|
|
|
|
/**
|
|
* get static character fields for this model instance
|
|
* @return array
|
|
*/
|
|
protected function getStaticFieldConf(): array{
|
|
return array_merge(parent::getStaticFieldConf(), $this->trackingFieldConf);
|
|
}
|
|
|
|
/**
|
|
* validates a model field to be a valid relational model
|
|
* @param $key
|
|
* @param $val
|
|
* @return bool
|
|
*/
|
|
protected function validate_notDry($key, $val): bool {
|
|
$valid = true;
|
|
if($colConf = $this->fieldConf[$key]){
|
|
if(isset($colConf['belongs-to-one'])){
|
|
if( (is_int($val) || ctype_digit($val)) && (int)$val > 0){
|
|
$valid = true;
|
|
}elseif( is_a($val, $colConf['belongs-to-one']) && !$val->dry() ){
|
|
$valid = true;
|
|
}else{
|
|
$valid = false;
|
|
$msg = 'Validation failed: "' . get_class($this) . '->' . $key . '" must be a valid instance of ' . $colConf['belongs-to-one'];
|
|
$this->throwValidationException($key, $msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $valid;
|
|
}
|
|
|
|
/**
|
|
* log character activity create/update/delete events
|
|
* @param string $action
|
|
*/
|
|
protected function logActivity($action){
|
|
// check if activity logging is enabled for this object
|
|
if($this->enableActivityLogging){
|
|
// check for field changes
|
|
if(
|
|
mb_stripos(mb_strtolower($action), 'delete') !== false ||
|
|
!empty($this->fieldChanges)
|
|
){
|
|
$this->newLog($action)->setCharacter($this->updatedCharacterId)->setData($this->fieldChanges)->buffer();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* validates all required columns of this class
|
|
* @return bool
|
|
* @throws \Exception\ValidationException
|
|
*/
|
|
public function isValid(): bool {
|
|
if($valid = parent::isValid()){
|
|
foreach($this->trackingFieldConf as $key => $colConf){
|
|
if($this->exists($key)){
|
|
$valid = $this->validateField($key, $this->$key);
|
|
if(!$valid){
|
|
break;
|
|
}
|
|
}else{
|
|
$valid = false;
|
|
$this->throwDbException('Missing table column "' . $this->getTable(). '.' . $key . '"');
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $valid;
|
|
}
|
|
|
|
/**
|
|
* get log file data
|
|
* @return array
|
|
*/
|
|
public function getLogData(): array {
|
|
return [];
|
|
}
|
|
|
|
|
|
/**
|
|
* save connection
|
|
* @param CharacterModel $characterModel
|
|
* @return ConnectionModel|false
|
|
*/
|
|
public function save(CharacterModel $characterModel = null){
|
|
if($this->dry()){
|
|
$this->createdCharacterId = $characterModel;
|
|
}
|
|
$this->updatedCharacterId = $characterModel;
|
|
|
|
return parent::save();
|
|
}
|
|
|
|
} |