|
| 1 | +/* |
| 2 | + * Tencent is pleased to support the open source community by making 蓝鲸 available. |
| 3 | + * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | + * Licensed under the MIT License (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * http://opensource.org/licenses/MIT |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 9 | + * either express or implied. See the License for the specific language governing permissions and |
| 10 | + * limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +package x20_02_17_01 |
| 14 | + |
| 15 | +import ( |
| 16 | + "context" |
| 17 | + "fmt" |
| 18 | + "time" |
| 19 | + |
| 20 | + "configcenter/src/common" |
| 21 | + "configcenter/src/common/blog" |
| 22 | + "configcenter/src/common/metadata" |
| 23 | + "configcenter/src/scene_server/admin_server/upgrader" |
| 24 | + "configcenter/src/storage/dal" |
| 25 | +) |
| 26 | + |
| 27 | +type ProcessTemplate struct { |
| 28 | + Metadata metadata.Metadata `field:"metadata" json:"metadata" bson:"metadata"` |
| 29 | + |
| 30 | + ID int64 `field:"id" json:"id,omitempty" bson:"id"` |
| 31 | + ProcessName string `field:"bk_process_name" json:"bk_process_name" bson:"bk_process_name"` |
| 32 | + // the service template's, which this process template belongs to. |
| 33 | + ServiceTemplateID int64 `field:"service_template_id" json:"service_template_id" bson:"service_template_id"` |
| 34 | + |
| 35 | + // stores a process instance's data includes all the process's |
| 36 | + // properties's value. |
| 37 | + Property *metadata.ProcessProperty `field:"property" json:"property,omitempty" bson:"property"` |
| 38 | + |
| 39 | + Creator string `field:"creator" json:"creator,omitempty" bson:"creator"` |
| 40 | + Modifier string `field:"modifier" json:"modifier,omitempty" bson:"modifier"` |
| 41 | + CreateTime time.Time `field:"create_time" json:"create_time,omitempty" bson:"create_time"` |
| 42 | + LastTime time.Time `field:"last_time" json:"last_time,omitempty" bson:"last_time"` |
| 43 | + SupplierAccount string `field:"bk_supplier_account" json:"bk_supplier_account,omitempty" bson:"bk_supplier_account"` |
| 44 | +} |
| 45 | + |
| 46 | +func fixProcTemplateProcName(ctx context.Context, db dal.RDB, conf *upgrader.Config) error { |
| 47 | + |
| 48 | + conds := map[string]interface{}{ |
| 49 | + "$or": []interface{}{ |
| 50 | + map[string]string{"property.bk_func_name.value": ""}, |
| 51 | + map[string]interface{}{"property.bk_func_name.value": map[string]interface{}{"$exists": false}}, |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + rows := make([]ProcessTemplate, 0) |
| 56 | + if err := db.Table(common.BKTableNameProcessTemplate).Find(conds).All(ctx, &rows); err != nil { |
| 57 | + blog.ErrorJSON("find process template bk_process_name empty error. err:%s", err.Error()) |
| 58 | + return err |
| 59 | + } |
| 60 | + |
| 61 | + for _, row := range rows { |
| 62 | + updateCond := map[string]interface{}{ |
| 63 | + "id": row.ID, |
| 64 | + } |
| 65 | + if row.Property == nil { |
| 66 | + blog.ErrorJSON("fix process template id:%v, process template property empty, raw info:%s", row.ID, row) |
| 67 | + return fmt.Errorf("fix process template id:%v, process template property empty", row.ID) |
| 68 | + } |
| 69 | + if row.Property.ProcessName.Value == nil { |
| 70 | + blog.ErrorJSON("fix process template id:%v, bk_process_name empty, raw info:%s", row.ID, row) |
| 71 | + return fmt.Errorf("fix process template id:%v, bk_process_name empty", row.ID) |
| 72 | + } |
| 73 | + doc := map[string]interface{}{ |
| 74 | + "property.bk_func_name.value": *row.Property.ProcessName.Value, |
| 75 | + "property.bk_func_name.as_default_value": true, |
| 76 | + } |
| 77 | + if row.ProcessName == "" { |
| 78 | + doc["bk_process_name"] = *row.Property.ProcessName.Value |
| 79 | + } |
| 80 | + if err := db.Table(common.BKTableNameProcessTemplate).Update(ctx, updateCond, doc); err != nil { |
| 81 | + blog.ErrorJSON("fix process template id:%v, update db error. condition:%s, doc:%s, err:%s", updateCond, doc, err.Error()) |
| 82 | + return fmt.Errorf("fix process template id:%v, update db error. err:%s", row.ID, err.Error()) |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + return nil |
| 87 | +} |
0 commit comments