@@ -186,17 +186,50 @@ public static function getGitCommit($hashOnly = false) {
186186 return $ gitcommit ;
187187 }
188188
189+ /**
190+ * function to check agent version for older update scripts, that still has
191+ * the 'type' field in AgentBinary instead of 'binaryType'
192+ */
193+ public static function checkAgentVersionLegacy ($ type , $ version , $ silent = false ) {
194+ $ agentBinaryFactory = Factory::getAgentBinaryFactory ();
195+ $ dict = $ agentBinaryFactory ->getNullObject ()->getKeyValueDict ();
196+ unset($ dict ["binaryType " ]);
197+ $ dict ["type " ] = null ;
198+ $ keys = array_keys ($ dict );
199+
200+ $ query = "SELECT " . implode (", " , $ keys ) . " FROM " . $ agentBinaryFactory ->getModelTable ();
201+ $ query .= " WHERE type=? " ;
202+ $ dbh = $ agentBinaryFactory ->getDB ();
203+ $ stmt = $ dbh ->prepare ($ query );
204+ $ vals = [$ type ];
205+ $ stmt ->execute ($ vals );
206+
207+ $ row = $ stmt ->fetch (PDO ::FETCH_ASSOC );
208+ if ($ row != null ) {
209+ $ pkName = $ agentBinaryFactory ->getNullObject ()->getPrimaryKey ();
210+ $ pk = $ row [$ pkName ];
211+ $ row ["binaryType " ] = $ row ["type " ];
212+ $ binary = $ agentBinaryFactory ->createObjectFromDict ($ pk , $ row );
213+
214+ if (Comparator::lessThan ($ binary ->getVersion (), $ version )) {
215+ if (!$ silent ) {
216+ echo "update $ type version... " ;
217+ }
218+ Factory::getAgentBinaryFactory ()->set ($ binary , AgentBinary::VERSION , $ version );
219+ if (!$ silent ) {
220+ echo "OK " ;
221+ }
222+ }
223+ }
224+ }
225+
189226 /**
190227 * @param string $type
191228 * @param string $version
192229 * @param bool $silent
193230 */
194231 public static function checkAgentVersion ($ type , $ version , $ silent = false ) {
195232 $ qF = new QueryFilter (AgentBinary::BINARY_TYPE , $ type , "= " );
196- if (Util::databaseColumnExists ("AgentBinary " , "type " )) {
197- // This check is needed for older updates when agentbinary column still got old 'type' name
198- Factory::getAgentFactory ()->getDB ()->query ("ALTER TABLE `AgentBinary` RENAME COLUMN `type` to `binaryType`; " );
199- }
200233 $ binary = Factory::getAgentBinaryFactory ()->filter ([Factory::FILTER => $ qF ], true );
201234 if ($ binary != null ) {
202235 if (Comparator::lessThan ($ binary ->getVersion (), $ version )) {
0 commit comments