mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 15:17:14 +00:00
fix(clients): preserve enable on portable import (#6481)
* fix(clients): preserve enable on portable import Stop BulkCreate and orphan ImportClients from forcing enable=true, and restate Enable=false after GORM Create (clients.enable default:true drops the zero value). Interactive Create still defaults new clients to enabled. Fixes #6478. * fix(clients): respect enable=false on node mirror; omit enable defaults true --------- Co-authored-by: mrchatam <287639636+mrchatam@users.noreply.github.com>
This commit is contained in:
@@ -169,11 +169,27 @@ func (s *ClientService) syncInboundClients(tx *gorm.DB, inboundId int, clients [
|
||||
}
|
||||
|
||||
if len(toCreate) > 0 {
|
||||
// Capture enable before Create: gorm default:true drops explicit false (#6478).
|
||||
// Restate disabled rows after CreateInBatches.
|
||||
wantEnable := make([]bool, len(toCreate))
|
||||
for i, rec := range toCreate {
|
||||
wantEnable[i] = rec.Enable
|
||||
}
|
||||
if err := tx.CreateInBatches(toCreate, 200).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rec := range toCreate {
|
||||
disabledIDs := make([]int, 0)
|
||||
for i, rec := range toCreate {
|
||||
idByEmail[rec.Email] = rec.Id
|
||||
if !wantEnable[i] {
|
||||
disabledIDs = append(disabledIDs, rec.Id)
|
||||
}
|
||||
}
|
||||
for _, batch := range chunkInts(disabledIDs, sqlInChunk) {
|
||||
if err := tx.Model(&model.ClientRecord{}).Where("id IN ?", batch).
|
||||
UpdateColumn("enable", false).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user