Skip to content

Commit 556a810

Browse files
authored
Merge pull request #1722 from hashtopolis/fix-update-script
Forced to upgrade agentbinary to new binaryType in order to make sure…
2 parents 18db8bc + c705452 commit 556a810

12 files changed

+56
-22
lines changed

src/inc/Util.class.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
$qF = new QueryFilter("type", $type, "=");
199-
}
200233
$binary = Factory::getAgentBinaryFactory()->filter([Factory::FILTER => $qF], true);
201234
if ($binary != null) {
202235
if (Comparator::lessThan($binary->getVersion(), $version)) {

src/install/updates/update_v0.10.x_v0.11.0.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
if (!isset($PRESENT["v0.10.x_agentBinaries"])) {
33-
Util::checkAgentVersion("python", "0.5.0", true);
33+
Util::checkAgentVersionLegacy("python", "0.5.0", true);
3434
$EXECUTED["v0.10.x_agentBinaries"] = true;
3535
}
3636

src/install/updates/update_v0.11.x_v0.12.0.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
}
2525

2626
if (!isset($PRESENT["v0.11.x_agentBinaries"])) {
27-
Util::checkAgentVersion("python", "0.6.0", true);
27+
Util::checkAgentVersionLegacy("python", "0.6.0", true);
2828
$EXECUTED["v0.11.x_agentBinaries"] = true;
2929
}
3030

src/install/updates/update_v0.12.x_v0.13.0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@
252252
}
253253

254254
if (!isset($PRESENT["v0.12.x_agentBinaries"])) {
255-
Util::checkAgentVersion("python", "0.6.0.10", true);
255+
Util::checkAgentVersionLegacy("python", "0.6.0.10", true);
256256
$EXECUTED["v0.12.x_agentBinaries"] = true;
257257
}
258258

259259
if (!isset($PRESENT["v0.12.x_agentBinaries_1"])) {
260-
Util::checkAgentVersion("python", "0.7.0", true);
260+
Util::checkAgentVersionLegacy("python", "0.7.0", true);
261261
$EXECUTED["v0.12.x_agentBinaries_1"] = true;
262262
}
263263

src/install/updates/update_v0.13.x_v0.13.1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040

4141
if (!isset($PRESENT["v0.13.x_agentBinaries"])) {
42-
Util::checkAgentVersion("python", "0.7.1", true);
42+
Util::checkAgentVersionLegacy("python", "0.7.1", true);
4343
$EXECUTED["v0.13.x_agentBinaries"] = true;
4444
}
4545
if (!isset($PRESENT["v0.13.x_hash_length"])) {

src/install/updates/update_v0.14.3_v0.14.4.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
use DBA\QueryFilter;
66

77
if (!isset($PRESENT["v0.14.3_agentBinaries"])) {
8-
Util::checkAgentVersion("python", "0.7.3", true);
8+
Util::checkAgentVersionLegacy("python", "0.7.3", true);
99
$EXECUTED["v0.14.3_agentBinaries"] = true;
1010
}

src/install/updates/update_v0.14.4_v0.14.5.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
use DBA\HashType;
66
use DBA\QueryFilter;
77

8-
if (!isset($PRESENT["v0.14.4_agentBinaries"])) {
9-
Util::checkAgentVersion("python", "0.7.4", true);
10-
$EXECUTED["v0.14.4_agentBinaries"] = true;
11-
}
128

139
if (!isset($PRESENT["v0.14.4_update_agent_binary"])) {
1410
if (Util::databaseColumnExists("AgentBinary", "type")) {
@@ -17,6 +13,11 @@
1713
}
1814
}
1915

16+
if (!isset($PRESENT["v0.14.4_agentBinaries"])) {
17+
Util::checkAgentVersion("python", "0.7.4", true);
18+
$EXECUTED["v0.14.4_agentBinaries"] = true;
19+
}
20+
2021
if (!isset($PRESENT["v0.14.4_update_hashtypes"])){
2122
$hashTypes = [
2223
new HashType( 1310, 'sha224($pass.$salt)', 1, 0),

src/install/updates/update_v0.14.x_v0.14.2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
}
1111

1212
if (!isset($PRESENT["v0.14.x_agentBinaries"])) {
13-
Util::checkAgentVersion("python", "0.7.2", true);
13+
Util::checkAgentVersionLegacy("python", "0.7.2", true);
1414
$EXECUTED["v0.14.x_agentBinaries"] = true;
1515
}

src/install/updates/update_v0.5.x_v0.6.0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
echo "Apply updates...\n";
1515

1616
echo "Check agent binaries... ";
17-
Util::checkAgentVersion("python", "0.1.4");
18-
Util::checkAgentVersion("csharp", "0.52.2");
17+
Util::checkAgentVersionLegacy("python", "0.1.4");
18+
Util::checkAgentVersionLegacy("csharp", "0.52.2");
1919
echo "\n";
2020

2121
echo "Create new permissions... ";

src/install/updates/update_v0.6.0_v0.7.0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
echo "Apply updates...\n";
1313

1414
echo "Check agent binaries... ";
15-
Util::checkAgentVersion("python", "0.1.7");
16-
Util::checkAgentVersion("csharp", "0.52.4");
15+
Util::checkAgentVersionLegacy("python", "0.1.7");
16+
Util::checkAgentVersionLegacy("csharp", "0.52.4");
1717
echo "\n";
1818

1919
echo "Creating User API...";

0 commit comments

Comments
 (0)