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

Merge branch 'task-1538-fgix-multiple-hosts' into 'master'

Task 1538 fgix multiple hosts

See merge request !48
parents cc3ad828 bf7ee1e3
No related branches found
No related tags found
No related merge requests found
......@@ -115,19 +115,33 @@ $sTableHead='';
if(is_array($aData) && count($aData)){
// echo '<pre>' . print_r($aData, 1);
foreach ($aData as $aRow){
$sUrl='index.php?action=get&project='.$aRow['project'].'&package='.$aRow['package'].'&phase='.$aRow['phase'].'&host='.$aRow['host'].'&variable='.$aRow['variable'].'';
$sTable.='<tr onclick="location.href=\''.$sUrl.'\'">';
$sItemUrl='index.php?project='.$aRow['project'].'&package='.$aRow['package'].'&phase='.$aRow['phase'].'&host='.$aRow['host'].'&variable='.$aRow['variable'].'';
// $sTable.='<tr onclick="location.href=\''.$sUrl.'\'">';
$sTable.='<tr>';
foreach ($aRow as $sKey=>$sValue){
// $sTable.='<td class="'.$sKey.'"><a href="'.$sUrl.'">'.$sValue.'</a></td>';
$sTable.='<td class="'.$sKey.'">'.htmlentities($sValue).'</td>';
}
$sTable.='</tr>';
$sTable.='<td>'
. '<button onclick="location.href=\''.$sItemUrl.'&action=get\'">View</button>'
. '<form method="POST" action="'.$sItemUrl.'">'
. '<input type="hidden" name="action" value="delete">'
. '<button>Delete</button>'
. '</form>'
. '</td>'
. '</tr>';
}
foreach (array_keys($aRow) as $sKey){
$sTableHead.='<th class="'.$sKey.'">'.$sKey.'</th>';
}
$sOut.='<table id="tbldata"><thead>'
$sOut.=''
. '<form method="POST" action="index.php">'
. '<input type="hidden" name="action" value="cleanup">'
. '<button>Cleanup</button>'
. '</form>'
. '<table id="tbldata"><thead>'
. '<tr>'.$sTableHead. '</tr>'
. '</thead>'
. '<tbody>'.$sTable.'</tbody></table>';
......
......@@ -92,10 +92,10 @@ class valuestore {
// cache dir is hardcoded to versions directory :-/
$this->_dbfile = __DIR__ . '/../data/versioncache.db';
if (!file_exists($this->_dbfile)) {
$this->_oDB = new PDO("sqlite:" . $this->_dbfile);
if (!file_exists($this->_dbfile) || !filesize($this->_dbfile)) {
$this->_createDb();
}
$this->_oDB = new PDO("sqlite:" . $this->_dbfile);
}
/**
* add a log messsage
......@@ -445,14 +445,23 @@ class valuestore {
/**
* cleanup value store
* @param integer $iTtl optional: max age in seconds of items to keep; 0 to delete all; default is 1 day
* @return boolean
*/
public function cleanup(){
if (!$this->_iTTL){
return false;
public function cleanup($iTtl=false){
if ($iTtl===false){
$iTtl=$this->_iTTL;
}
$sTtlDate=date("Y-m-d H:i:s", date("U") - $this->_iTTL );
$sSql="DELETE FROM `values` WHERE `time` < '$sTtlDate'";
$sTtlDate=date("Y-m-d H:i:s", date("U") - (int)$iTtl );
$sSql="DELETE FROM `values` WHERE `time` < '$sTtlDate' "
. ($this->sProject ? "AND project='" . $this->sProject . "' " : "")
. ($this->sPackage ? "AND package='" . $this->sPackage . "' " : "")
. ($this->sPhase ? "AND phase='" . $this->sPhase . "' " : "")
. ($this->sPlace ? "AND place='" . $this->sPlace . "' " : "")
. ($this->sHost ? "AND host='" . $this->sHost . "' " : "")
. ($sVariable ? "AND variable='" . $sVariable . "' " : "")
;
// die("$iTtl ... $sSql ... ABORT");
$this->_makeQuery($sSql);
$this->_makeQuery("vaccum;");
return true;
......@@ -478,7 +487,7 @@ class valuestore {
. ($sVariable ? "AND variable='" . $sVariable . "' " : "")
;
$sSql="DELETE FROM `values` WHERE $sWhere";
echo $sSql;
// echo $sSql;
// return true;
return $this->_makeQuery($sSql);
}
......
......@@ -24,8 +24,6 @@
*
* 2017-04-07 hahn first lines
*/
// ----------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------
......@@ -71,24 +69,19 @@ function getParam($sKey, $sRegex4Cleanup = false) {
// ----------------------------------------------------------------------
// check required params
// ----------------------------------------------------------------------
/*
if (!$_GET || !count($_GET)) {
quit("no parameter was found.");
}
*/
foreach (array("action") as $sKey) {
if (!array_key_exists($sKey, $_GET)) {
quit("value required: $sKey=");
}
}
// ----------------------------------------------------------------------
// get vars
// ----------------------------------------------------------------------
$sAction = getParam('action', '/[^a-z]/');
if ($sAction !== "delete" && $sAction !== "get" && $sAction !== "update") {
if ($sAction !== "delete" && $sAction !== "get" && $sAction !== "update" && $sAction !== "cleanup") {
quit("action is unknown or not implemented yet.");
}
......@@ -113,10 +106,14 @@ $sValue = getParam('value', '');
require './classes/valuestore.class.php';
$oVersion = new valuestore();
$oVersion->setProject($sProject, $sPackage, $sPhase, $sPlace, $sHost);
switch ($sAction) {
case 'cleanup':
$oVersion->cleanup();
echo "Cleanup was done.";
break;
case 'delete':
$oVersion->setProject($sProject, $sPackage, $sPhase, $sPlace, $sHost);
if ($oVersion->deleteValues($sVarname)) {
echo "OK: " . print_r($oVersion->whereiam()) . " ($sVarname) was deleted.";
......@@ -127,11 +124,13 @@ switch ($sAction) {
break;
case 'get':
$oVersion->setProject($sProject, $sPackage, $sPhase, $sPlace, $sHost);
header('Content-Type: application/json');
echo json_encode($oVersion->getVersion());
break;
case 'update':
$oVersion->setProject($sProject, $sPackage, $sPhase, $sPlace, $sHost);
if (!$sVarname) {
quit("ERROR: the update action requires a variable and a value.");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment