Skip to content
Snippets Groups Projects
Commit 2a68fee7 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

rename methods for history data

parent e1d3aa51
No related branches found
No related tags found
1 merge request!18OP#7365 PHP-8.1 - Upgrade - cronlog Viewer (monitors.ascii)https://projects.iml.unibe.ch/work_packages/7365
......@@ -33,7 +33,7 @@ require_once 'cronlog.class.php';
* @license GNU GPL 3.0
* @author Axel Hahn <axel.hahn@iml.unibe.ch>
*
* 2024-09-20 <axel.hahn@unibe.ch> added type declarations; update php docs
* 2024-10-01 <axel.hahn@unibe.ch> added type declarations; update php docs
*/
class cronlogrenderer extends cronlog
{
......@@ -342,7 +342,7 @@ class cronlogrenderer extends cronlog
return '';
}
$sReturn = '';
$sServer = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : false;
$sServer = isset($_SERVER['SERVER_NAME']) ?? false;
$sReturn .= '<li class="nav-item"><a class="nav-link nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a></li>'
. '<li class="nav-item d-none d-sm-inline-block"><a href="#" class="nav-link">' . $this->t('instances') . ':</a></li>';
......@@ -360,7 +360,7 @@ class cronlogrenderer extends cronlog
* @param array $aData result of $oCL->getServerLogs()
* @return string
*/
public function renderJoblist(array $aData = []): string
public function renderHistoryTable(array $aData = []): string
{
$sTaskId = __FUNCTION__ . '-' . $this->_sActiveServer;
$sHtml = $this->_getCacheData($sTaskId);
......@@ -381,6 +381,7 @@ class cronlogrenderer extends cronlog
krsort($aTmp);
$aData = array_values($aTmp);
// render table
$sTblHead = '';
$iOK = 0;
$iErrors = 0;
......@@ -482,7 +483,7 @@ class cronlogrenderer extends cronlog
*
* @return string
*/
public function renderJoblistOfAllServers(): string
public function renderHistoryOfAllServers(): string
{
$aData = [];
foreach (array_keys($this->getServers()) as $sServer) {
......@@ -490,7 +491,7 @@ class cronlogrenderer extends cronlog
$aData = array_merge($aData, $this->getServerJobHistory());
}
$this->setServer('ALL');
return $this->renderJoblist($aData);
return $this->renderHistoryTable($aData);
}
/**
......
......@@ -32,7 +32,7 @@
* @license GNU GPL 3.0
* @author Axel Hahn <axel.hahn@iml.unibe.ch>
*
* 2024-09-20 <axel.hahn@unibe.ch> added type declarations; update php docs
* 2024-10-01 <axel.hahn@unibe.ch> added type declarations; update php docs
*/
class cronlog
......@@ -46,7 +46,7 @@ class cronlog
protected string $_sDataDir = "__APPDIR__/data";
/**
* TTL for cached data
* TTL for cached rendered html output of logs/ history/ timeline
* @var int
*/
protected int $_iTtlCache = 60; // in sec
......@@ -69,16 +69,52 @@ class cronlog
*/
protected array $_aSkipJoblogs = [];
/**
* Array of cronlog viewer instances to show a navigation to switch between them
* @var array
*/
protected array $_aInstances = [];
/**
* Array of all servers with cronjobs
* @var array
*/
protected array $_aServers = [];
/**
* Current server
* @var string
*/
protected string $_sActiveServer = '';
/**
* Filefilter for finished joblogs
* @var string
*/
protected string $_sFileFilter_serverjoblog = '*joblog*.done';
/**
* Filefilter for history logs
* @var string
*/
protected string $_sFileFilter_joblog = '*.log';
/**
* Filefilter for running jobs
* @var string
*/
protected string $_sFileFilter_jobrunning = '*.log.running*';
/**
* Current language
* @var string
*/
protected string $_sLang = ''; // language ... read from config file
/**
* Array of language texts
* @var array
*/
protected array $_aLang = []; // language data
// ----------------------------------------------------------------------
......@@ -125,7 +161,10 @@ class cronlog
*/
protected function _getCacheDir(): string
{
return $this->_sDataDir . '/__cache';
if(!is_dir("$this->_sDataDir/__cache")) {
mkdir("$this->_sDataDir/__cache", 0750, true);
}
return "$this->_sDataDir/__cache";
}
/**
......@@ -135,7 +174,7 @@ class cronlog
*/
protected function _getCacheFile(string $sTaskId): string
{
return $this->_getCacheDir() . '/' . $sTaskId;
return $this->_getCacheDir() . "/$sTaskId";
}
/**
......@@ -144,17 +183,20 @@ class cronlog
*/
protected function _getServerlogDir(): string
{
return $this->_sDataDir . '/' . $this->_sActiveServer;
return "$this->_sDataDir/$this->_sActiveServer";
}
/**
* Caching: get cached data if they exist and aren't expired
* Caching: get cached data for rendered html output
* if they exist and isn't expired
*
* @param string $sTaskId Name of the task
* @return mixed string|array
*/
protected function _getCacheData(string $sTaskId): string|array
{
// DISABLE CACHE return false;
// DISABLE CACHE
// return false;
$sFile = $this->_getCacheFile($sTaskId);
if (file_exists($sFile)) {
if (filemtime($sFile) > (date('U') - $this->_iTtlCache)) {
......@@ -288,7 +330,7 @@ class cronlog
}
/**
* Get logs from jobfilea of the current or given server
* Get logs from jobfiles of the current or given server
* @param boolean $bUseSkip hide jobs if their label matches the skip list; default: true
* @return array
*/
......
......@@ -48,9 +48,9 @@ if($sServer){
switch ($sItem){
case 'cronhistory':
if($sServer==='ALL'){
$sHtml.=$oCL->renderJoblistOfAllServers();
$sHtml.=$oCL->renderHistoryOfAllServers();
} else {
$sHtml.=$oCL->renderJoblist();
$sHtml.=$oCL->renderHistoryTable();
}
break;
case 'cronlogs':
......@@ -68,7 +68,7 @@ switch ($sItem){
}
break;
case 'instances':
$sHtml.=$oCL->renderInstances($sServer);
$sHtml.=$oCL->renderInstances();
break;
case 'selectserver':
$sHtml.=$oCL->renderServerlist($sServer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment