From 2a68fee7efb9ce7c61eabf4ae589fbda45294730 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Tue, 1 Oct 2024 10:46:43 +0200 Subject: [PATCH] rename methods for history data --- classes/cronlog-renderer.class.php | 11 +++--- classes/cronlog.class.php | 58 +++++++++++++++++++++++++----- get.php | 6 ++-- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/classes/cronlog-renderer.class.php b/classes/cronlog-renderer.class.php index 08c020c..8a6ddd6 100644 --- a/classes/cronlog-renderer.class.php +++ b/classes/cronlog-renderer.class.php @@ -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); } /** diff --git a/classes/cronlog.class.php b/classes/cronlog.class.php index bdfd415..0670aa7 100644 --- a/classes/cronlog.class.php +++ b/classes/cronlog.class.php @@ -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 */ diff --git a/get.php b/get.php index 6c44582..6a00219 100644 --- a/get.php +++ b/get.php @@ -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); -- GitLab