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

deployment gui - valuestore - delete method

parent 9cf69207
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,17 @@
* $oVersion->setProject("", $$sPackage, $sPhase, $sPlace);
* $oVersion->updateVar($sVarname, $sValue)
*
* delete
* $oVersion = new valuestore();
*
* to delete values for a single place:
* $oVersion->setProject("", $this->_aPrjConfig["fileprefix"]$sPhase, $sPlace);
* $aVersions=$oVersion->deleteValues();
*
* to delete all version items for a whole whole project (packages) in all phases
* $oVersion->setProject("", $this->_aPrjConfig["fileprefix"]);
* $aVersions=$oVersion->deleteValues("version");
*
* @author hahn
*/
class valuestore {
......@@ -326,21 +337,6 @@ class valuestore {
// PUBLIC SETTER
// ----------------------------------------------------------------------
/**
* cleanup value store
* @return boolean
*/
public function cleanup(){
if (!$this->_iTTL){
return false;
}
$sTtlDate=date("Y-m-d H:i:s", date("U") - $this->_iTTL );
$sSql="DELETE FROM `values` WHERE `time` < '$sTtlDate'";
$this->_makeQuery($sSql);
$this->_makeQuery("vaccum;");
return true;
}
/**
* init before setting or getting
* @param string $sProject project id
......@@ -367,7 +363,7 @@ class valuestore {
$this->_quit(__FUNCTION__ , "ERROR: you need to set a project. Use the setProject() method to do so.");
return false;
}
if (array_search($sPhase, $this->_allowedPhases)===false){
if ($sPhase && array_search($sPhase, $this->_allowedPhases)===false){
$this->_quit(__FUNCTION__ , "ERROR: you set a wrong phase [$sPhase]");
}
$this->sPhase=$sPhase;
......@@ -376,11 +372,14 @@ class valuestore {
}
public function setPlace($sPlace, $sHost=false){
if ((!$this->sProject && !$this->sPackage) || !$this->sPhase){
if ((!$this->sProject && !$this->sPackage)){
$this->_quit(__FUNCTION__ , "ERROR: you need to set a project and phase. Use the setProject() method to do so.");
return false;
}
if (array_search($sPlace, $this->_allowedPlaces)===false){
if ($sPlace && !$this->sPhase){
$this->_quit(__FUNCTION__ , "ERROR: you cannot set place [$sPlace] with leaving phase empty.");
}
if ($sPlace && array_search($sPlace, $this->_allowedPlaces)===false){
$this->_quit(__FUNCTION__ , "ERROR: you set a wrong place [$sPlace]");
}
$this->sPlace=$sPlace;
......@@ -389,7 +388,7 @@ class valuestore {
}
public function setHost($sHost=false){
if ((!$this->sProject && !$this->sPackage) || !$this->sPhase || !$this->sPlace){
if ((!$this->sProject && !$this->sPackage)){
$this->_quit(__FUNCTION__ , "ERROR: you need to set a project, phase and place. Use the setProject() method to do so.");
return false;
}
......@@ -405,6 +404,55 @@ class valuestore {
return $this->sHost;
}
// ----------------------------------------------------------------------
// DATABASE FUNCTIONS
// ----------------------------------------------------------------------
/**
* cleanup value store
* @return boolean
*/
public function cleanup(){
if (!$this->_iTTL){
return false;
}
$sTtlDate=date("Y-m-d H:i:s", date("U") - $this->_iTTL );
$sSql="DELETE FROM `values` WHERE `time` < '$sTtlDate'";
$this->_makeQuery($sSql);
$this->_makeQuery("vaccum;");
return true;
}
/**
* delete values
* @return boolean
*/
/**
* delete values from value store. You need to call setProject() to set
* project or package and optional phase, place, host. Then call this delete
* method.
* @param string $sVariable optional: limit deletion to a given variable
* @return boolean
*/
public function deleteValues($sVariable){
if ((!$this->sProject && !$this->sPackage) ){
$this->_quit(__FUNCTION__ , "ERROR: you need to set a project, phase and place. use the setProject() method to do so.");
}
$sWhere='1=1 '
. ($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 . "' " : "")
;
$sSql="DELETE FROM `values` WHERE $sWhere";
echo $sSql;
// return true;
return $this->_makeQuery($sSql);
}
/**
* update a version
* @return boolean
......@@ -437,7 +485,8 @@ class valuestore {
);
}
/**
* update a version
* update a version value
* @param type $sVersioninfos
* @return boolean
*/
public function updateVersion($sVersioninfos){
......
......@@ -88,7 +88,7 @@ foreach (array("action") as $sKey) {
$sAction = getParam('action', '/[^a-z]/');
if ($sAction !== "get" && $sAction !== "update") {
if ($sAction !== "delete" && $sAction !== "get" && $sAction !== "update") {
quit("action is unknown or not implemented yet.");
}
......@@ -116,6 +116,16 @@ $oVersion = new valuestore();
$oVersion->setProject($sProject, $sPackage, $sPhase, $sPlace, $sHost);
switch ($sAction) {
case 'delete':
if ($oVersion->deleteValues($sVarname)){
echo "OK: ".print_r($oVersion->whereiam())." ($sVarname) was deleted.";
} else {
echo "ERROR: update for $sVarname failed.";
}
break;
break;
case 'get':
header('Content-Type: application/json');
echo json_encode($oVersion->getVersion());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment