@@ -1071,21 +1071,22 @@ func (ds *Datastore) CleanupUnusedSoftwareInstallers(ctx context.Context, softwa
1071
1071
func (ds * Datastore ) BatchSetSoftwareInstallers (ctx context.Context , tmID * uint , installers []* fleet.UploadSoftwareInstallerPayload ) error {
1072
1072
const upsertSoftwareTitles = `
1073
1073
INSERT INTO software_titles
1074
- (name, source, browser)
1074
+ (name, source, browser, bundle_identifier )
1075
1075
VALUES
1076
1076
%s
1077
1077
ON DUPLICATE KEY UPDATE
1078
1078
name = VALUES(name),
1079
1079
source = VALUES(source),
1080
- browser = VALUES(browser)
1080
+ browser = VALUES(browser),
1081
+ bundle_identifier = VALUES(bundle_identifier)
1081
1082
`
1082
1083
1083
1084
const loadSoftwareTitles = `
1084
1085
SELECT
1085
1086
id
1086
1087
FROM
1087
1088
software_titles
1088
- WHERE (name , source, browser) IN (%s)
1089
+ WHERE (unique_identifier , source, browser) IN (%s)
1089
1090
`
1090
1091
1091
1092
const unsetAllInstallersFromPolicies = `
@@ -1190,7 +1191,7 @@ COALESCE(post_install_script_content_id != ? OR
1190
1191
(post_install_script_content_id IS NULL AND ? IS NOT NULL) OR
1191
1192
(? IS NULL AND post_install_script_content_id IS NOT NULL)
1192
1193
, FALSE) is_metadata_modified FROM software_installers
1193
- WHERE global_or_team_id = ? AND title_id IN (SELECT id FROM software_titles WHERE name = ? AND source = ? AND browser = '')
1194
+ WHERE global_or_team_id = ? AND title_id IN (SELECT id FROM software_titles WHERE unique_identifier = ? AND source = ? AND browser = '')
1194
1195
`
1195
1196
1196
1197
const insertNewOrEditedInstaller = `
@@ -1216,7 +1217,7 @@ INSERT INTO software_installers (
1216
1217
install_during_setup
1217
1218
) VALUES (
1218
1219
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
1219
- (SELECT id FROM software_titles WHERE name = ? AND source = ? AND browser = ''),
1220
+ (SELECT id FROM software_titles WHERE unique_identifier = ? AND source = ? AND browser = ''),
1220
1221
?, (SELECT name FROM users WHERE id = ?), (SELECT email FROM users WHERE id = ?), ?, ?, COALESCE(?, false)
1221
1222
)
1222
1223
ON DUPLICATE KEY UPDATE
@@ -1245,7 +1246,7 @@ FROM
1245
1246
WHERE
1246
1247
global_or_team_id = ? AND
1247
1248
-- this is guaranteed to select a single title_id, due to unique index
1248
- title_id IN (SELECT id FROM software_titles WHERE name = ? AND source = ? AND browser = '')
1249
+ title_id IN (SELECT id FROM software_titles WHERE unique_identifier = ? AND source = ? AND browser = '')
1249
1250
`
1250
1251
1251
1252
const deleteInstallerLabelsNotInList = `
@@ -1330,18 +1331,43 @@ WHERE
1330
1331
1331
1332
var args []any
1332
1333
for _ , installer := range installers {
1333
- args = append (args , installer .Title , installer .Source , "" )
1334
+ args = append (
1335
+ args ,
1336
+ installer .Title ,
1337
+ installer .Source ,
1338
+ "" ,
1339
+ func () * string {
1340
+ if strings .TrimSpace (installer .BundleIdentifier ) != "" {
1341
+ return & installer .BundleIdentifier
1342
+ }
1343
+ return nil
1344
+ }(),
1345
+ )
1334
1346
}
1335
1347
1336
1348
values := strings .TrimSuffix (
1337
- strings .Repeat ("(?,?,?)," , len (installers )),
1349
+ strings .Repeat ("(?,?,?,? )," , len (installers )),
1338
1350
"," ,
1339
1351
)
1340
1352
if _ , err := tx .ExecContext (ctx , fmt .Sprintf (upsertSoftwareTitles , values ), args ... ); err != nil {
1341
1353
return ctxerr .Wrap (ctx , err , "insert new/edited software title" )
1342
1354
}
1343
1355
1344
1356
var titleIDs []uint
1357
+ args = []any {}
1358
+ for _ , installer := range installers {
1359
+ args = append (
1360
+ args ,
1361
+ BundleIdentifierOrName (installer .BundleIdentifier , installer .Title ),
1362
+ installer .Source ,
1363
+ "" ,
1364
+ )
1365
+ }
1366
+ values = strings .TrimSuffix (
1367
+ strings .Repeat ("(?,?,?)," , len (installers )),
1368
+ "," ,
1369
+ )
1370
+
1345
1371
if err := sqlx .SelectContext (ctx , tx , & titleIDs , fmt .Sprintf (loadSoftwareTitles , values ), args ... ); err != nil {
1346
1372
return ctxerr .Wrap (ctx , err , "load existing titles" )
1347
1373
}
@@ -1441,7 +1467,7 @@ WHERE
1441
1467
postInstallScriptID ,
1442
1468
// WHERE clause
1443
1469
globalOrTeamID ,
1444
- installer .Title ,
1470
+ BundleIdentifierOrName ( installer .BundleIdentifier , installer . Title ) ,
1445
1471
installer .Source ,
1446
1472
}
1447
1473
@@ -1472,7 +1498,7 @@ WHERE
1472
1498
postInstallScriptID ,
1473
1499
installer .Platform ,
1474
1500
installer .SelfService ,
1475
- installer .Title ,
1501
+ BundleIdentifierOrName ( installer .BundleIdentifier , installer . Title ) ,
1476
1502
installer .Source ,
1477
1503
installer .UserID ,
1478
1504
installer .UserID ,
@@ -1495,7 +1521,7 @@ WHERE
1495
1521
// ID (cannot use res.LastInsertID due to the upsert statement, won't
1496
1522
// give the id in case of update)
1497
1523
var installerID uint
1498
- if err := sqlx .GetContext (ctx , tx , & installerID , loadSoftwareInstallerID , globalOrTeamID , installer .Title , installer .Source ); err != nil {
1524
+ if err := sqlx .GetContext (ctx , tx , & installerID , loadSoftwareInstallerID , globalOrTeamID , BundleIdentifierOrName ( installer .BundleIdentifier , installer . Title ) , installer .Source ); err != nil {
1499
1525
return ctxerr .Wrapf (ctx , err , "load id of new/edited installer with name %q" , installer .Filename )
1500
1526
}
1501
1527
0 commit comments