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

versions class: queries can use PDO prepare method; update names of places (like in project.class)

parent 5fb0676c
No related branches found
No related tags found
No related merge requests found
......@@ -77,13 +77,19 @@ class versions {
/**
* execute a sql statement
* @param string $sSql sql statement
* @param array $aVars array with values (uses PDO::prepare(); $sSql must contain placeholders :key)
* @return database object
*/
private function _makeQuery($sSql) {
private function _makeQuery($sSql, $aVars=false) {
// $this->_log(__FUNCTION__."($sSql)");
// echo "DEBUG: executing SQL<pre>$sSql</pre>";
$oDb = new PDO("sqlite:" . $this->_dbfile);
if ($aVars && is_array($aVars)){
$sth = $oDb->prepare($sSql);
$result = $sth->execute($aVars);
} else {
$result = $oDb->query($sSql);
}
return $result;
}
......@@ -168,7 +174,7 @@ class versions {
WHERE
project='" . $this->sProject . "'
AND phase='" . $this->sPhase . "'
AND place='installed'
AND place='deployed'
";
return $this->_makeSelectQuery($sSql, 'host');
}
......@@ -241,7 +247,7 @@ class versions {
die("ERROR: you need to set a project and phase. Use the setProject() method to do so.");
return false;
}
if($sPlace!=='queue' && $sPlace!=='puppet' && $sPlace!=='installed'){
if($sPlace!=='onhold' && $sPlace!=='ready2install' && $sPlace!=='deployed'){
die("ERROR: you set a wrong place [$sPlace]");
}
$this->sPlace=$sPlace;
......@@ -254,11 +260,11 @@ class versions {
die("ERROR: you need to set a project, phase and place. Use the setProject() method to do so.");
return false;
}
if($sHost && $this->sPlace!=='installed'){
die("ERROR: a host can be set on place [installed] only.");
if($sHost && $this->sPlace!=='deployed'){
die("ERROR: a host can be set on place [deployed] only.");
}
if(!$sHost && $this->sPlace==='installed'){
die("ERROR: on place [installed] a host MUST be set.");
if(!$sHost && $this->sPlace==='deployed'){
die("ERROR: on place [deployed] a host MUST be set.");
}
$this->sHost=$sHost;
return $this->sHost;
......@@ -282,11 +288,17 @@ class versions {
'" . $this->sPhase . "',
'" . $this->sPlace . "',
'" . $this->sHost . "',
'" . $sVarname . "',
'" . $sValue . "'
:variable,
:value
);
";
return $this->_makeQuery($sSql);
return $this->_makeQuery(
$sSql,
array(
'variable'=>$sVarname,
'value'=>$sValue,
)
);
}
/**
* update a version
......
......@@ -92,7 +92,7 @@ $sPlace = getParam('place', '/[^a-z]/');
$sHost = getParam('host', '/[^a-z\.\-0-9]/');
if ($sHost && !$sPlace) {
$sPlace = 'installed';
$sPlace = 'deployed';
}
$sVarname = getParam('variable', '/[^a-z]/');
......@@ -112,7 +112,6 @@ switch ($sAction) {
case 'get':
print_r($oVersion->getVersion());
break;
case 'update':
if (!$sVarname) {
......@@ -121,8 +120,11 @@ switch ($sAction) {
switch ($sVarname) {
// case 'other-varname':
case 'version':
$oVersion->updateVar($sVarname, $sValue);
if ($oVersion->updateVar($sVarname, $sValue)){
echo "OK: $sVarname was updated.";
} else {
echo "ERROR: update for $sVarname failed.";
}
break;
default:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment