Skip to content

Commit

Permalink
Merge pull request #883 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.5.5
  • Loading branch information
exodus4d authored Dec 9, 2019
2 parents aef6d4e + 1d4a964 commit f443e80
Show file tree
Hide file tree
Showing 181 changed files with 5,030 additions and 2,152 deletions.
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// Define globals exposed by Node.js.
"node": true,

// Allow ES6.
"esversion": 7,
// Allow ES8.
"esversion": 9,

/*
* ENFORCING OPTIONS
Expand Down
11 changes: 6 additions & 5 deletions app/cron.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[CRON]
log = TRUE
cli = TRUE
web = FALSE
log = TRUE
cli = TRUE
web = FALSE
silent = TRUE

[CRON.presets]
; run every minute
Expand Down Expand Up @@ -51,13 +52,13 @@ deleteMapData = Cron\MapUpdate->deleteMapData, @downtime
deleteAuthenticationData = Cron\CharacterUpdate->deleteAuthenticationData, @downtime

; delete expired cache files
deleteExpiredCacheData = Cron\Cache->deleteExpiredData, @downtime
deleteExpiredCacheData = Cron\Cache->deleteExpiredCacheData, @downtime

; delete old statistics (activity log) data
deleteStatisticsData = Cron\StatisticsUpdate->deleteStatisticsData, @weekly

; truncate map history log files
truncateMapHistoryLogFiles = Cron\MapHistory->truncateFiles, @halfHour
truncateMapHistoryLogFiles = Cron\MapHistory->truncateMapHistoryLogFiles, @halfHour

; sync "sovereignty" and "faction warfare" data from CCP´s ESI API
updateSovereigntyData = Cron\Universe->updateSovereigntyData, @halfPastHour
Expand Down
83 changes: 83 additions & 0 deletions app/main/controller/api/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,93 @@

use Controller;
use lib\Config;
use lib\Cron;
use Model;

class Setup extends Controller\Controller {

/**
* get HTML table <tr>´s for all cronjobs
* @param \Base $f3
*/
public function cronTable(\Base $f3){
$return = (object) [];
$return->error = [];
$return->jobsData = Cron::instance()->getJobsConfig();
$return->html = $this->getCronHtml($return->jobsData);
echo json_encode($return);
}

/**
* toggle "isPaused" for a cronjob by its name
* @param \Base $f3
*/
public function cronPause(\Base $f3){
$postData = (array)$f3->get('POST');
$return = (object) [];
$return->error = [];

if($jobName = (string)$postData['job']){
$cron = Cron::instance();
if($job = $cron->getJob($jobName)){
if($job->valid()){
$job->isPaused = !$job->isPaused;
$job->save();

$return->jobsData = $cron->getJobsConfig([$jobName]);
$return->html = $this->getCronHtml($return->jobsData);
}
}
}

echo json_encode($return);
}

/**
* execute a cronjob by its name
* -> runs sync
* -> max execution time might be lower than CLI calls!
* @param \Base $f3
*/
public function cronExecute(\Base $f3){
$postData = (array)$f3->get('POST');
$return = (object) [];
$return->error = [];

if($jobName = (string)$postData['job']){
$cron = Cron::instance();
if($job = $cron->getJob($jobName)){
if($job->valid()){
$cron->execute($jobName, false);

$return->jobsData = $cron->getJobsConfig([$jobName]);
$return->html = $this->getCronHtml($return->jobsData);
}
}
}

echo json_encode($return);
}

/**
* get HTML for cronJobs
* @param array $jobsData
* @return string
*/
protected function getCronHtml(array $jobsData) : string {
$tplData = [
'cronConfig' => [
'jobs' => $jobsData,
'settings' => $this->getF3()->constants(Cron::instance(), 'DEFAULT_')
],
'tplCounter' => $this->counter(),
'tplConvertBytes' => function(){
return call_user_func_array([\lib\format\Number::instance(), 'bytesToString'], func_get_args());
}
];
return \Template::instance()->render('templates/ui/cron_table_row.html', null, $tplData, 0);
}

/**
* build search index from existing data (e.g. Systems)
* OR import data from ESI (e.g. Structures)
Expand Down
37 changes: 19 additions & 18 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Controller\Api;

use Controller;
use lib\Config;
use Model\Pathfinder;

class System extends Controller\AccessController {
Expand Down Expand Up @@ -39,7 +40,7 @@ public function graphData(\Base $f3){
$cacheResponse = false;

// number of log entries in each table per system (24 = 24h)
$logEntryCount = 24;
$logEntryCount = Pathfinder\AbstractSystemApiBasicModel::DATA_COLUMN_COUNT;

$ttl = 60 * 10;

Expand All @@ -51,47 +52,47 @@ public function graphData(\Base $f3){
'factionKills' => 'SystemFactionKillModel'
];

$exists = false;

foreach($systemIds as $systemId){
$cacheKey = $this->getSystemGraphCacheKey($systemId);
if( !$f3->exists($cacheKey, $graphData )){
if(!$exists = $f3->exists($cacheKey, $graphData)){
$graphData = [];
$cacheSystem = false;

foreach($logTables as $label => $ModelClass){
$systemLogModel = Pathfinder\AbstractPathfinderModel::getNew($ModelClass);
foreach($logTables as $label => $className){
$systemLogModel = Pathfinder\AbstractSystemApiBasicModel::getNew($className);
$systemLogExists = false;

// 10min cache (could be up to 1h cache time)
$systemLogModel->getByForeignKey('systemId', $systemId);
if( !$systemLogModel->dry() ){
if($systemLogModel->valid()){
$systemLogExists = true;
$cacheSystem = true;
$cacheResponse = true;
}

$systemLogData = $systemLogModel->getData();

// podKills share graph with shipKills -> skip
if($label != 'podKills'){
$graphData[$label]['logExists'] = $systemLogExists;
$graphData[$label]['updated'] = $systemLogData->updated;
}

$counter = 0;
for( $i = $logEntryCount; $i >= 1; $i--){
$column = 'value' . $i;
$value = $systemLogExists ? $systemLogModel->$column : 0;

// ship and pod kills should be merged into one table
$logValueCount = range(0, $logEntryCount - 1);
foreach($logValueCount as $i){
if($label == 'podKills'){
$graphData['shipKills']['data'][$counter]['z'] = $value;
$graphData['shipKills']['data'][$i]['z'] = $systemLogData->values[$i];
}else{
$dataSet = [
'x' => ($i - 1) . 'h',
'y' => $value
$graphData[$label]['data'][] = [
'x' => ($logEntryCount - $i - 1) . 'h',
'y' => $systemLogData->values[$i]
];
$graphData[$label]['data'][] = $dataSet;
}
$counter++;
}
}

if($cacheSystem){
$f3->set($cacheKey, $graphData, $ttl);
}
Expand All @@ -104,7 +105,7 @@ public function graphData(\Base $f3){

if($cacheResponse){
// send client cache header
$f3->expire($ttl);
$f3->expire(Config::ttlLeft($exists, $ttl));
}

echo json_encode($graphsData);
Expand Down
2 changes: 2 additions & 0 deletions app/main/controller/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use Controller;
use lib\Config;
use Model\Pathfinder;
use Exception;

Expand Down Expand Up @@ -119,6 +120,7 @@ public function getCookieCharacter(\Base $f3){
$cookieName = (string)$data['cookie'];

$return = (object) [];
$return->ccpImageServer = Config::getPathfinderData('api.ccp_image_server');
$return->error = [];

if( !empty($cookieData = $this->getCookieByName($cookieName) )){
Expand Down
2 changes: 1 addition & 1 deletion app/main/controller/appcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function afterroute(\Base $f3){
parent::afterroute($f3);

// clear all SSO related temp data
if( $f3->exists(Ccp\Sso::SESSION_KEY_SSO) ){
if($f3->exists(Ccp\Sso::SESSION_KEY_SSO)){
$f3->clear(Ccp\Sso::SESSION_KEY_SSO);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/main/controller/ccp/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public function getCharacterData(int $characterId) : \stdClass{
*/
$corporation = Pathfinder\AbstractPathfinderModel::getNew('CorporationModel');
$corporation->getById($corporationId, 0);
if( !$corporation->dry() ){
if($corporation->valid()){
$characterData->corporation = $corporation;
}
}
Expand All @@ -479,7 +479,7 @@ public function getCharacterData(int $characterId) : \stdClass{
*/
$alliance = Pathfinder\AbstractPathfinderModel::getNew('AllianceModel');
$alliance->getById($allianceId, 0);
if( !$alliance->dry() ){
if($alliance->valid()){
$characterData->alliance = $alliance;
}
}
Expand Down
31 changes: 29 additions & 2 deletions app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ function beforeroute(\Base $f3, $params) : bool {
}else{
$this->initResource($f3);

$this->setTemplate( Config::getPathfinderData('view.index') );
$this->setTemplate(Config::getPathfinderData('view.index'));


$f3->set('tplImage', \lib\format\Image::instance());
}

return true;
Expand Down Expand Up @@ -165,7 +168,7 @@ protected function initResource(\Base $f3){
'font' => $f3->get('BASE') . '/public/fonts',
'document' => $f3->get('BASE') . '/public/templates',
'image' => $f3->get('BASE') . '/public/img'
]);
], true);

$resource->register('style', 'pathfinder');

Expand All @@ -178,6 +181,10 @@ protected function initResource(\Base $f3){
$resource->register('font', 'fa-solid-900');
$resource->register('font', 'fa-brands-400');

$resource->register('url', self::getEnvironmentData('CCP_SSO_URL'), 'prerender');
$resource->register('url', Config::getPathfinderData('api.ccp_image_server'), 'dns-prefetch');
$resource->register('url', '//i.ytimg.com', 'dns-prefetch'); // YouTube tiny embed domain

$f3->set('tplResource', $resource);
}

Expand Down Expand Up @@ -805,6 +812,26 @@ protected function logActivities(){
Monolog::instance()->log();
}

/**
* simple counter with "static" store
* -> called within tpl render
* @return \Closure
*/
protected function counter() : \Closure {
$store = [];

return function(string $action = 'increment', string $type = 'default', $val = 0) use (&$store){
$return = null;
switch($action){
case 'increment': $store[$type]++; break;
case 'add': $store[$type] += (int)$val; break;
case 'get': $return = $store[$type] ? : null; break;
case 'reset': unset($store[$type]); break;
}
return $return;
};
}

/**
* get controller by class name
* -> controller class is searched within all controller directories
Expand Down
Loading

0 comments on commit f443e80

Please sign in to comment.