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