@@ -61,17 +61,19 @@ function updateScope(scope) {
61
61
/**
62
62
* Fix all projectTemplates.
63
63
*
64
- * @returns {undefined }
64
+ * @param {Object } logger logger
65
+ *
66
+ * @returns {Promise } resolved when dene
65
67
*/
66
- async function fixProjectTemplates ( ) {
68
+ async function fixProjectTemplates ( logger ) {
67
69
const projectTemplates = await models . ProjectTemplate . findAll ( ) ;
68
70
for ( const projectTemplate of projectTemplates ) {
69
71
if ( projectTemplate . scope ) {
70
72
const updatedScope = updateScope ( JSON . parse ( JSON . stringify ( projectTemplate . scope ) ) ) ;
71
73
if ( ! _ . isEqual ( updatedScope , projectTemplate . scope ) ) {
72
74
projectTemplate . scope = updatedScope ;
73
75
await projectTemplate . save ( ) ;
74
- console . log ( `updated record of ProjectTemplate with id ${ projectTemplate . id } ` ) ;
76
+ logger . info ( `updated record of ProjectTemplate with id ${ projectTemplate . id } ` ) ;
75
77
}
76
78
}
77
79
}
@@ -81,6 +83,7 @@ async function fixProjectTemplates() {
81
83
* Update the required property of an object.
82
84
*
83
85
* @param {Object } data any object
86
+ *
84
87
* @returns {undefined }
85
88
*/
86
89
function updateRequiredProperty ( data ) {
@@ -125,9 +128,11 @@ function updateTemplate(template) {
125
128
/**
126
129
* Fix all productTemplates.
127
130
*
128
- * @returns {undefined }
131
+ * @param {Object } logger logger
132
+ *
133
+ * @returns {Promise } resolved when dene
129
134
*/
130
- async function fixProductTemplates ( ) {
135
+ async function fixProductTemplates ( logger ) {
131
136
const productTemplates = await models . ProductTemplate . findAll ( ) ;
132
137
133
138
for ( const productTemplate of productTemplates ) {
@@ -136,7 +141,7 @@ async function fixProductTemplates() {
136
141
if ( ! _ . isEqual ( updatedTemplate , productTemplate . template ) ) {
137
142
productTemplate . template = updatedTemplate ;
138
143
await productTemplate . save ( ) ;
139
- console . log ( `updated record of ProductTemplate with id ${ productTemplate . id } ` ) ;
144
+ logger . info ( `updated record of ProductTemplate with id ${ productTemplate . id } ` ) ;
140
145
}
141
146
}
142
147
}
@@ -145,18 +150,26 @@ async function fixProductTemplates() {
145
150
/**
146
151
* Fix all metadata models.
147
152
*
153
+ * @param {Object } logger logger
154
+ *
148
155
* @returns {undefined }
149
156
*/
150
- async function fixMetadataForES ( ) {
151
- await fixProjectTemplates ( ) ;
152
- await fixProductTemplates ( ) ;
157
+ async function fixMetadataForES ( logger ) {
158
+ await fixProjectTemplates ( logger ) ;
159
+ await fixProductTemplates ( logger ) ;
160
+ }
161
+
162
+ if ( ! module . parent ) {
163
+ fixMetadataForES ( console )
164
+ . then ( ( ) => {
165
+ console . log ( 'done!' ) ;
166
+ process . exit ( ) ;
167
+ } ) . catch ( ( err ) => {
168
+ console . error ( 'Error syncing database' , err ) ;
169
+ process . exit ( 1 ) ;
170
+ } ) ;
153
171
}
154
172
155
- fixMetadataForES ( )
156
- . then ( ( ) => {
157
- console . log ( 'done!' ) ;
158
- process . exit ( ) ;
159
- } ) . catch ( ( err ) => {
160
- console . error ( 'Error syncing database' , err ) ;
161
- process . exit ( 1 ) ;
162
- } ) ;
173
+ module . exports = {
174
+ fixMetadataForES,
175
+ } ;
0 commit comments