bug fixing minor improvements
This commit is contained in:
@@ -8,12 +8,21 @@
|
||||
|
||||
namespace Controller;
|
||||
use Model;
|
||||
use DB;
|
||||
|
||||
class Controller {
|
||||
|
||||
protected $f3;
|
||||
private $template;
|
||||
|
||||
function __construct(){
|
||||
|
||||
$this->f3 = \Base::instance();
|
||||
|
||||
// initiate DB connection
|
||||
DB\Database::instance('PF');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $template
|
||||
*/
|
||||
@@ -28,15 +37,6 @@ class Controller {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
function __construct(){
|
||||
|
||||
$f3 = \Base::instance();
|
||||
$this->f3 = $f3;
|
||||
|
||||
// init DB
|
||||
$this->setDB('PF');
|
||||
}
|
||||
|
||||
/**
|
||||
* event handler
|
||||
*/
|
||||
@@ -55,34 +55,11 @@ class Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* set/change DB connection
|
||||
* @param $type
|
||||
* set change the DB connection
|
||||
* @param string $database
|
||||
*/
|
||||
protected function setDB($type = ''){
|
||||
|
||||
if($type === 'CCP'){
|
||||
// CCP DB
|
||||
$db = new \DB\SQL(
|
||||
$this->f3->get('DB_CCP_DNS') . $this->f3->get('DB_CCP_NAME'),
|
||||
$this->f3->get('DB_CCP_USER'),
|
||||
$this->f3->get('DB_CCP_PASS')
|
||||
);
|
||||
}else{
|
||||
// Pathfinder DB
|
||||
$db = new \DB\SQL(
|
||||
$this->f3->get('DB_DNS') . $this->f3->get('DB_NAME'),
|
||||
$this->f3->get('DB_USER'),
|
||||
$this->f3->get('DB_PASS')
|
||||
);
|
||||
}
|
||||
$this->f3->set('DB', $db);
|
||||
|
||||
// set DB timezone to UTC +00:00 (eve server time)
|
||||
//$this->f3->get('DB')->exec('SET @@session.time_zone = "+00:00";');
|
||||
|
||||
// disable innoDB schema (relevant vor MySql 5.5)
|
||||
// not necessary for MySql 5.6
|
||||
//$this->f3->get('DB')->exec('SET GLOBAL innodb_stats_on_metadata = OFF;');
|
||||
protected function setDB($database = 'PF'){
|
||||
DB\Database::instance()->setDB($database);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,8 +168,9 @@ class Controller {
|
||||
return $validUser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* logout function
|
||||
* log the current user out
|
||||
*/
|
||||
public function logOut(){
|
||||
|
||||
|
||||
@@ -11,30 +11,22 @@ namespace controller;
|
||||
|
||||
class LogController extends Controller {
|
||||
|
||||
/**
|
||||
* log types. The Value represents the log file name
|
||||
* @var array
|
||||
*/
|
||||
protected static $logTypes = [
|
||||
'debug' => 'debug'
|
||||
];
|
||||
|
||||
/**
|
||||
* get an singleton instance for a logger instance
|
||||
* @param $loggerType
|
||||
* @param $logFileName
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getLogger($loggerType){
|
||||
public static function getLogger($logFileName){
|
||||
|
||||
$f3 = \Base::instance();
|
||||
|
||||
$hiveKey = 'LOGGER' . $loggerType;
|
||||
$hiveKey = 'LOGGER' . $logFileName;
|
||||
|
||||
// check if log controller already exists
|
||||
if( !$f3->exists($hiveKey) ){
|
||||
// create new logger instance
|
||||
|
||||
$logFile = self::$logTypes[$loggerType] . '.log';
|
||||
$logFile = $logFileName . '.log';
|
||||
|
||||
$f3->set($hiveKey, new \Log($logFile));
|
||||
}
|
||||
|
||||
@@ -108,7 +108,8 @@ class Map extends \Controller\AccessController {
|
||||
foreach((array)$rows as $rowData){
|
||||
$data = [
|
||||
'id' => $rowData->id,
|
||||
'label' => $rowData->label
|
||||
'label' => $rowData->label,
|
||||
'connectorDefinition' => $rowData->connectorDefinition
|
||||
];
|
||||
$connectionScopeData[$rowData->name] = $data;
|
||||
}
|
||||
@@ -319,16 +320,26 @@ class Map extends \Controller\AccessController {
|
||||
// cache time(s) per user should be equal or less than this function is called
|
||||
// prevent request flooding
|
||||
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
|
||||
$mapData = (array)$f3->get('POST.mapData');
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
if($user){
|
||||
$cacheKey = 'user_map_data_' . $user->id;
|
||||
// -> get active user object
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
$cacheKey = 'user_map_data_' . $activeCharacter->id;
|
||||
|
||||
// if there is any system/connection change data submitted -> clear cache
|
||||
if(!empty($mapData)){
|
||||
$f3->clear($cacheKey);
|
||||
}
|
||||
|
||||
if($f3->exists($cacheKey) === false ){
|
||||
|
||||
$mapData = (array)$f3->get('POST.mapData');
|
||||
// get current map data ========================================================
|
||||
$maps = $user->getMaps();
|
||||
|
||||
@@ -356,8 +367,7 @@ class Map extends \Controller\AccessController {
|
||||
){
|
||||
|
||||
// map changes expected =============================================
|
||||
// -> get active user object
|
||||
$activeCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
|
||||
// loop current user maps and check for changes
|
||||
foreach($maps as $map){
|
||||
@@ -379,6 +389,7 @@ class Map extends \Controller\AccessController {
|
||||
// system belongs to the current map
|
||||
if(is_object($filteredMap->systems)){
|
||||
// update
|
||||
unset($systemData['updated']);
|
||||
$system = $filteredMap->systems->current();
|
||||
$system->setData($systemData);
|
||||
$system->updatedCharacterId = $activeCharacter->characterId;
|
||||
@@ -407,6 +418,7 @@ class Map extends \Controller\AccessController {
|
||||
// connection belongs to the current map
|
||||
if(is_object($filteredMap->connections)){
|
||||
// update
|
||||
unset($connectionData['updated']);
|
||||
$connection = $filteredMap->connections->current();
|
||||
$connection->setData($connectionData);
|
||||
$connection->save($user);
|
||||
|
||||
@@ -238,7 +238,7 @@ class Route extends \Controller\AccessController {
|
||||
|
||||
if(count($rows) > 0){
|
||||
// switch DB back to pathfinder DB
|
||||
$this->setDB();
|
||||
$this->setDB('PF');
|
||||
|
||||
// clear cache table
|
||||
$query = "TRUNCATE system_neighbour";
|
||||
|
||||
@@ -149,11 +149,12 @@ class System extends \Controller\AccessController {
|
||||
public function search($f3, $params){
|
||||
|
||||
// switch DB
|
||||
\DB\Database::instance();
|
||||
$this->setDB('CCP');
|
||||
|
||||
$searchToken = '';
|
||||
// check for search parameter
|
||||
if( array_key_exists( 'arg1', $params) ){
|
||||
if( isset($params['arg1']) ){
|
||||
$searchToken = $params['arg1'];
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,15 @@ class User extends Controller\Controller{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* log the current user out + clear character system log data
|
||||
*/
|
||||
public function logOut(){
|
||||
$this->deleteLog();
|
||||
|
||||
return parent::logOut();
|
||||
}
|
||||
|
||||
/**
|
||||
* save/update "map sharing" configurations for all map types
|
||||
* the user has access to
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: exodus4d
|
||||
* Date: 09.03.15
|
||||
* Time: 21:31
|
||||
*/
|
||||
|
||||
namespace Controller\Cron;
|
||||
|
||||
class Update extends \Controller\Controller {
|
||||
|
||||
protected $apiRequestOptions = [
|
||||
'timeout' => 5
|
||||
];
|
||||
|
||||
/**
|
||||
* table names for all system log tables
|
||||
* @var array
|
||||
*/
|
||||
protected $logTables = [
|
||||
'jumps' => 'system_jumps',
|
||||
'shipKills' => 'system_kills_ships',
|
||||
'podKills' => 'system_kills_pods',
|
||||
'factionKills' => 'system_kills_factions'
|
||||
];
|
||||
|
||||
/**
|
||||
* event handler
|
||||
*/
|
||||
function beforeroute() {
|
||||
|
||||
// controller access allowed for CLI-mode (command line)
|
||||
if(php_sapi_name() != 'cli'){
|
||||
$this->f3->error(401, 'Cronjob: unauthorized access');
|
||||
}
|
||||
|
||||
// set linebreak for status output
|
||||
define('LNBR', PHP_EOL);
|
||||
|
||||
parent::beforeroute();
|
||||
}
|
||||
|
||||
/**
|
||||
* check all system log tables for the correct number of system entries that will be locked
|
||||
* @return array
|
||||
*/
|
||||
private function _prepareSystemLogTables(){
|
||||
|
||||
$systemController = new \Controller\Api\System();
|
||||
$systemsData = $systemController->getSystems();
|
||||
|
||||
// switch DB back to pathfinder
|
||||
$this->setDB('PF');
|
||||
|
||||
// insert systems into each log table if not exist
|
||||
$this->f3->get('DB')->begin();
|
||||
foreach($this->logTables as $tableName){
|
||||
|
||||
// insert systems into jump log table
|
||||
$sqlInsertSystem = "INSERT IGNORE INTO " . $tableName . " (systemId)
|
||||
VALUES(:systemId)";
|
||||
|
||||
foreach($systemsData as $systemData){
|
||||
// skip WH systems -> no jump data available
|
||||
if($systemData['type']['name'] == 'k-space'){
|
||||
$this->f3->get('DB')->exec($sqlInsertSystem, array(
|
||||
':systemId' => $systemData['systemId']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->f3->get('DB')->commit();
|
||||
|
||||
return $systemsData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* imports all relevant map stats from CCPs API
|
||||
* >> php index.php "/cron/update/importmapdata"
|
||||
* @param $f3
|
||||
*/
|
||||
public function importMapData($f3){
|
||||
|
||||
$time_start = microtime(true);
|
||||
// prepare system jump log table
|
||||
$systemsData = $this->_prepareSystemLogTables();
|
||||
$time_end = microtime(true);
|
||||
$execTimePrepareSystemLogTables = $time_end - $time_start;
|
||||
|
||||
|
||||
// get current jump Data -------------------------------------------------------
|
||||
$time_start = microtime(true);
|
||||
$apiPath = $this->f3->get('api_path.CCP_XML') . '/map/Jumps.xml.aspx';
|
||||
|
||||
$apiResponse = \Web::instance()->request($apiPath, $this->apiRequestOptions );
|
||||
|
||||
$jumpData = [];
|
||||
$updateJumps = false;
|
||||
if($apiResponse['body']){
|
||||
$xml = simplexml_load_string($apiResponse['body']);
|
||||
$rowApiData = $xml->result->rowset;
|
||||
|
||||
foreach($rowApiData->children() as $systemApiData){
|
||||
$attributeApiData = $systemApiData->attributes();
|
||||
$systemId = $attributeApiData->solarSystemID->__toString();
|
||||
$shipJumps =$attributeApiData->shipJumps->__toString();
|
||||
|
||||
$jumpData[$systemId] = $shipJumps;
|
||||
}
|
||||
|
||||
$updateJumps = true;
|
||||
}
|
||||
$time_end = microtime(true);
|
||||
$execTimeGetJumpData = $time_end - $time_start;
|
||||
|
||||
// get current kill Data -------------------------------------------------------
|
||||
$time_start = microtime(true);
|
||||
$apiPath = $this->f3->get('api_path.CCP_XML') . '/map/Kills.xml.aspx';
|
||||
|
||||
$apiResponse = \Web::instance()->request($apiPath, $this->apiRequestOptions );
|
||||
$killData = [];
|
||||
$updateKills = false;
|
||||
if($apiResponse['body']){
|
||||
$xml = simplexml_load_string($apiResponse['body']);
|
||||
$rowApiData = $xml->result->rowset;
|
||||
foreach($rowApiData->children() as $systemApiData){
|
||||
$attributeApiData = $systemApiData->attributes();
|
||||
$systemId = $attributeApiData->solarSystemID->__toString();
|
||||
$shipKills =$attributeApiData->shipKills->__toString();
|
||||
$podKills =$attributeApiData->podKills->__toString();
|
||||
$factionKills =$attributeApiData->factionKills->__toString();
|
||||
|
||||
$killData[$systemId] = [
|
||||
'shipKills' => $shipKills,
|
||||
'podKills' => $podKills,
|
||||
'factionKills' => $factionKills,
|
||||
];
|
||||
}
|
||||
|
||||
$updateKills = true;
|
||||
|
||||
}
|
||||
$time_end = microtime(true);
|
||||
$execTimeGetKillData = $time_end - $time_start;
|
||||
|
||||
// update system log tables -----------------------------------------------------
|
||||
$time_start = microtime(true);
|
||||
// make sure last update is (at least) 1h ago
|
||||
$f3->get('DB')->begin();
|
||||
foreach($this->logTables as $key => $tableName){
|
||||
$sql = "UPDATE
|
||||
" . $tableName . "
|
||||
SET
|
||||
value24 = value23,
|
||||
value23 = value22,
|
||||
value22 = value21,
|
||||
value21 = value20,
|
||||
value20 = value19,
|
||||
value19 = value18,
|
||||
value18 = value17,
|
||||
value17 = value16,
|
||||
value16 = value15,
|
||||
value15 = value14,
|
||||
value14 = value13,
|
||||
value13 = value12,
|
||||
value12 = value11,
|
||||
value11 = value10,
|
||||
value10 = value9,
|
||||
value9 = value8,
|
||||
value8 = value7,
|
||||
value7 = value6,
|
||||
value6 = value5,
|
||||
value5 = value4,
|
||||
value4 = value3,
|
||||
value3 = value2,
|
||||
value2 = value1,
|
||||
value1 = :value
|
||||
WHERE
|
||||
systemId = :systemId AND
|
||||
HOUR(TIMEDIFF(NOW(), updated)) > 0
|
||||
";
|
||||
|
||||
foreach($systemsData as $systemData){
|
||||
|
||||
if(
|
||||
$key == 'jumps' &&
|
||||
$updateJumps
|
||||
){
|
||||
// update jump data (if available)
|
||||
$currentJumps = 0;
|
||||
if(array_key_exists($systemData['systemId'], $jumpData)){
|
||||
$currentJumps = $jumpData[$systemData['systemId']];
|
||||
}
|
||||
|
||||
$f3->get('DB')->exec($sql, array(
|
||||
':systemId' => $systemData['systemId'],
|
||||
':value' => $currentJumps
|
||||
));
|
||||
}else if($updateKills){
|
||||
|
||||
// update kill data (if available)
|
||||
$currentKills = 0;
|
||||
if(array_key_exists($systemData['systemId'], $killData)){
|
||||
$currentKillData = $killData[$systemData['systemId']];
|
||||
|
||||
$currentKills = $currentKillData[$key];
|
||||
}
|
||||
|
||||
$f3->get('DB')->exec($sql, array(
|
||||
':systemId' => $systemData['systemId'],
|
||||
':value' => $currentKills
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
$f3->get('DB')->commit();
|
||||
|
||||
$time_end = microtime(true);
|
||||
$execTimeUpdateTables = $time_end - $time_start;
|
||||
|
||||
// ------------------------
|
||||
echo 'prepare system log tables: ' . round($execTimePrepareSystemLogTables, 2) . 's' . LNBR;
|
||||
echo 'get jump data: ' . round($execTimeGetJumpData, 2) . 's' . LNBR;
|
||||
echo 'get kill data: ' . round($execTimeGetKillData, 2) . 's' . LNBR;
|
||||
echo 'update log tables: ' . round($execTimeUpdateTables, 2) . 's' . LNBR;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user