diff --git a/public_html/versions/classes/versions.class.php b/public_html/versions/classes/versions.class.php index 4468a5f5b0b27c6f4f0b35ef7a20c4c0cd64af08..c3da08da4423a581cffa778cdd080d00c1f85587 100644 --- a/public_html/versions/classes/versions.class.php +++ b/public_html/versions/classes/versions.class.php @@ -76,14 +76,20 @@ class versions { /** * 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 */ - 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); - $result = $oDb->query($sSql); + 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 diff --git a/public_html/versions/index.php b/public_html/versions/index.php index 7d79ff6ca90869b8dcb0e6999a791349f17f91ae..8fbb34621e34ff0726834e92b03f430b06a15d54 100644 --- a/public_html/versions/index.php +++ b/public_html/versions/index.php @@ -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); - echo "OK: $sVarname was updated."; + if ($oVersion->updateVar($sVarname, $sValue)){ + echo "OK: $sVarname was updated."; + } else { + echo "ERROR: update for $sVarname failed."; + } break; default: