@jsreport/jsreport-core 3.12.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/lib/main/optionsSchema.js +263 -271
- package/lib/main/reporter.js +8 -16
- package/lib/main/settings.js +14 -8
- package/lib/worker/render/executeEngine.js +23 -1
- package/lib/worker/reporter.js +45 -0
- package/lib/worker/sandbox/createSandbox.js +56 -98
- package/lib/worker/sandbox/isolatedRequire.js +1 -21
- package/lib/worker/sandbox/runInSandbox.js +20 -7
- package/package.json +6 -6
- package/test/extensions/validExtensions/listeners/main.js +62 -51
- package/test/extensions/validExtensions/listeners/worker.js +81 -74
- package/lib/main/migration/resourcesToAssets.js +0 -230
- package/lib/main/migration/xlsxTemplatesToAssets.js +0 -128
|
@@ -1,74 +1,81 @@
|
|
|
1
|
-
const extend = require('node.extend.without.arrays')
|
|
2
|
-
const vm = require('vm')
|
|
3
|
-
const Module = require('module')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const process = require('process')
|
|
6
|
-
|
|
7
|
-
module.exports = (reporter, definition) => {
|
|
8
|
-
reporter.initializeListeners.add('test-listeners', () => {
|
|
9
|
-
reporter.beforeRenderListeners.add('listeners', async (req, res) => {
|
|
10
|
-
const result = await reporter.executeMainAction('test-beforeRender-listeners', { req, res }, req)
|
|
11
|
-
extend(true, req, result.req)
|
|
12
|
-
extend(true, res, result.res)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
reporter.afterRenderListeners.add('listeners', async (req, res) => {
|
|
16
|
-
const result = await reporter.executeMainAction('test-afterRender-listeners', { req, res }, req)
|
|
17
|
-
extend(true, req, result.req)
|
|
18
|
-
extend(true, res, result.res)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
reporter.validateRenderListeners.add('listeners', async (req, res) => {
|
|
22
|
-
const result = await reporter.executeMainAction('test-validateRender-listeners', { req, res }, req)
|
|
23
|
-
extend(true, req, result.req)
|
|
24
|
-
extend(true, res, result.res)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
reporter.afterTemplatingEnginesExecutedListeners.add('listeners', async (req, res) => {
|
|
28
|
-
const result = await reporter.executeMainAction('test-afterTemplatingEnginesExecuted-listeners', { req, res }, req)
|
|
29
|
-
extend(true, req, result.req)
|
|
30
|
-
extend(true, res, result.res)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const evalInWorker = (code, req, res) => {
|
|
34
|
-
const script = new vm.Script(`
|
|
35
|
-
;(function () {
|
|
36
|
-
return ${code}
|
|
37
|
-
})()
|
|
38
|
-
`)
|
|
39
|
-
|
|
40
|
-
return script.runInThisContext({
|
|
41
|
-
displayErrors: true
|
|
42
|
-
})(req, res, {
|
|
43
|
-
mainModuleFilename: require.main.filename,
|
|
44
|
-
require: (m) => {
|
|
45
|
-
if (Module.builtinModules.includes(m)) {
|
|
46
|
-
return require(m)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
return require(path.join(process.cwd(), 'node_modules', m))
|
|
51
|
-
} catch (e) {
|
|
52
|
-
// hack, make it working in monorepo as well as normal extension
|
|
53
|
-
return require(path.join(process.cwd(), '../../node_modules', m))
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
reporter
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
reporter.afterRenderListeners.add('eval-listeners', async (req, res) => {
|
|
61
|
-
const code = await reporter.executeMainAction('test-afterRenderEval', {}, req)
|
|
62
|
-
if (code) {
|
|
63
|
-
return evalInWorker(code, req, res)
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
reporter.beforeRenderListeners.insert(0, 'eval-listeners', async (req, res) => {
|
|
68
|
-
const code = await reporter.executeMainAction('test-beforeRenderEval', {}, req)
|
|
69
|
-
if (code) {
|
|
70
|
-
return evalInWorker(code, req, res)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
const extend = require('node.extend.without.arrays')
|
|
2
|
+
const vm = require('vm')
|
|
3
|
+
const Module = require('module')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const process = require('process')
|
|
6
|
+
|
|
7
|
+
module.exports = (reporter, definition) => {
|
|
8
|
+
reporter.initializeListeners.add('test-listeners', () => {
|
|
9
|
+
reporter.beforeRenderListeners.add('listeners', async (req, res) => {
|
|
10
|
+
const result = await reporter.executeMainAction('test-beforeRender-listeners', { req, res }, req)
|
|
11
|
+
extend(true, req, result.req)
|
|
12
|
+
extend(true, res, result.res)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
reporter.afterRenderListeners.add('listeners', async (req, res) => {
|
|
16
|
+
const result = await reporter.executeMainAction('test-afterRender-listeners', { req, res }, req)
|
|
17
|
+
extend(true, req, result.req)
|
|
18
|
+
extend(true, res, result.res)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
reporter.validateRenderListeners.add('listeners', async (req, res) => {
|
|
22
|
+
const result = await reporter.executeMainAction('test-validateRender-listeners', { req, res }, req)
|
|
23
|
+
extend(true, req, result.req)
|
|
24
|
+
extend(true, res, result.res)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
reporter.afterTemplatingEnginesExecutedListeners.add('listeners', async (req, res) => {
|
|
28
|
+
const result = await reporter.executeMainAction('test-afterTemplatingEnginesExecuted-listeners', { req, res }, req)
|
|
29
|
+
extend(true, req, result.req)
|
|
30
|
+
extend(true, res, result.res)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const evalInWorker = (code, req, res) => {
|
|
34
|
+
const script = new vm.Script(`
|
|
35
|
+
;(function () {
|
|
36
|
+
return ${code}
|
|
37
|
+
})()
|
|
38
|
+
`)
|
|
39
|
+
|
|
40
|
+
return script.runInThisContext({
|
|
41
|
+
displayErrors: true
|
|
42
|
+
})(req, res, {
|
|
43
|
+
mainModuleFilename: require.main.filename,
|
|
44
|
+
require: (m) => {
|
|
45
|
+
if (Module.builtinModules.includes(m)) {
|
|
46
|
+
return require(m)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
return require(path.join(process.cwd(), 'node_modules', m))
|
|
51
|
+
} catch (e) {
|
|
52
|
+
// hack, make it working in monorepo as well as normal extension
|
|
53
|
+
return require(path.join(process.cwd(), '../../node_modules', m))
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
reporter
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
reporter.afterRenderListeners.add('eval-listeners', async (req, res) => {
|
|
61
|
+
const code = await reporter.executeMainAction('test-afterRenderEval', {}, req)
|
|
62
|
+
if (code) {
|
|
63
|
+
return evalInWorker(code, req, res)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
reporter.beforeRenderListeners.insert(0, 'eval-listeners', async (req, res) => {
|
|
68
|
+
const code = await reporter.executeMainAction('test-beforeRenderEval', {}, req)
|
|
69
|
+
if (code) {
|
|
70
|
+
return evalInWorker(code, req, res)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
reporter.afterTemplatingEnginesExecutedListeners.add('eval-listeners', async (req, res) => {
|
|
75
|
+
const code = await reporter.executeMainAction('test-afterTemplatingEnginesExecutedEval', {}, req)
|
|
76
|
+
if (code) {
|
|
77
|
+
return evalInWorker(code, req, res)
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
const Request = require('../../shared/request')
|
|
2
|
-
|
|
3
|
-
module.exports = async (reporter) => {
|
|
4
|
-
if (
|
|
5
|
-
reporter.options.migrateResourcesToAssets === false ||
|
|
6
|
-
reporter.documentStore.collection('scripts') == null ||
|
|
7
|
-
reporter.documentStore.collection('data') == null
|
|
8
|
-
) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const migrated = await reporter.settings.findValue('core-migrated-resources')
|
|
13
|
-
|
|
14
|
-
if (migrated) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const req = Request({})
|
|
19
|
-
await reporter.documentStore.beginTransaction(req)
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const templateIds = await reporter.documentStore.collection('templates').find({}, { _id: 1 }, req)
|
|
23
|
-
|
|
24
|
-
if (templateIds.length !== 0) {
|
|
25
|
-
reporter.logger.debug('Running migration "resourcesToAssets"')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const templateToAssetResourcesMap = new Map()
|
|
29
|
-
const dataToAssetMap = new Map()
|
|
30
|
-
const dataEntitiesToRemove = []
|
|
31
|
-
|
|
32
|
-
for (const templateId of templateIds) {
|
|
33
|
-
const template = await reporter.documentStore.collection('templates').findOne({ _id: templateId._id }, req)
|
|
34
|
-
|
|
35
|
-
if (template.resources == null) {
|
|
36
|
-
continue
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (Array.isArray(template.resources.items)) {
|
|
40
|
-
for (const dataItem of template.resources.items) {
|
|
41
|
-
const dataEntity = await reporter.documentStore.collection('data').findOne({ shortid: dataItem.shortid }, req)
|
|
42
|
-
|
|
43
|
-
if (dataEntity) {
|
|
44
|
-
let newAsset
|
|
45
|
-
|
|
46
|
-
if (dataToAssetMap.has(dataEntity._id)) {
|
|
47
|
-
newAsset = dataToAssetMap.get(dataEntity._id)
|
|
48
|
-
} else {
|
|
49
|
-
const assetProps = {
|
|
50
|
-
content: Buffer.from(dataEntity.dataJson || ''),
|
|
51
|
-
folder: dataEntity.folder || null
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (dataEntity.readPermissions != null) {
|
|
55
|
-
assetProps.readPermissions = dataEntity.readPermissions
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (dataEntity.editPermissions != null) {
|
|
59
|
-
assetProps.editPermissions = dataEntity.editPermissions
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
newAsset = await insertUnique(reporter, 'assets', `${dataEntity.name}.json`, assetProps, req)
|
|
63
|
-
|
|
64
|
-
dataToAssetMap.set(dataEntity._id, newAsset)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const assetResources = templateToAssetResourcesMap.get(template._id) || []
|
|
68
|
-
|
|
69
|
-
assetResources.push({
|
|
70
|
-
...newAsset,
|
|
71
|
-
originalName: dataEntity.name
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
templateToAssetResourcesMap.set(template._id, assetResources)
|
|
75
|
-
dataEntitiesToRemove.push(dataEntity._id)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const templateAssetResources = templateToAssetResourcesMap.get(template._id) || []
|
|
81
|
-
|
|
82
|
-
if (templateAssetResources.length > 0) {
|
|
83
|
-
const scriptProps = {
|
|
84
|
-
content: (
|
|
85
|
-
`
|
|
86
|
-
// THIS SCRIPT WAS GENERATED BY MIGRATION IN V3, IT PROVIDES BACKWARD COMPATIBILITY
|
|
87
|
-
// WITH THE DEPRECATED jsreport-resources https://jsreport.net/learn/resources
|
|
88
|
-
// THE RECOMMENDATION NOW IS TO USE jsreport-localization https://jsreport.net/learn/localization
|
|
89
|
-
// SO WHEN YOU DECIDE TO USE jsreport-localization TO FULLY REPLACE THE jsreport-resources
|
|
90
|
-
// JUST REMOVE THIS SCRIPT FROM YOUR TEMPLATE AND DELETE IT
|
|
91
|
-
const jsreport = require('jsreport-proxy')
|
|
92
|
-
|
|
93
|
-
async function beforeRender (req, res) {
|
|
94
|
-
req.options.language = req.options.language || req.template.localization?.language
|
|
95
|
-
const defaultLanguage = ${template.resources.defaultLanguage != null ? '\'' + template.resources.defaultLanguage + '\'' : 'undefined'}
|
|
96
|
-
const assetsResources = [${templateAssetResources.map(a => `{ name: '${a.originalName}', shortid: '${a.shortid}' }`).join(', ')}]
|
|
97
|
-
|
|
98
|
-
const resources = await Promise.all(assetsResources.map(async (r) => {
|
|
99
|
-
const asset = await jsreport.documentStore.collection('assets').findOne({ shortid: r.shortid })
|
|
100
|
-
|
|
101
|
-
if (asset == null) {
|
|
102
|
-
throw new Error(\`Asset resources with shortid \${r.shortid} was not found (resource lookup)\`)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
asset.resourceName = r.name
|
|
106
|
-
asset.content = asset.content.toString()
|
|
107
|
-
|
|
108
|
-
return asset
|
|
109
|
-
}))
|
|
110
|
-
|
|
111
|
-
resources.forEach((r) => {
|
|
112
|
-
r.dataJson = r.content
|
|
113
|
-
r.data = JSON.parse(r.content)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
req.options.resources = resources
|
|
117
|
-
req.data.$resources = resources
|
|
118
|
-
|
|
119
|
-
const resourcesByName = {}
|
|
120
|
-
|
|
121
|
-
resources.forEach((r) => {
|
|
122
|
-
resourcesByName[r.resourceName] = r.data
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
req.options.resource = resourcesByName
|
|
126
|
-
req.data.$resource = resourcesByName
|
|
127
|
-
|
|
128
|
-
const isLocalizedRequest = req.options.language != null || defaultLanguage != null
|
|
129
|
-
|
|
130
|
-
if (isLocalizedRequest) {
|
|
131
|
-
let languageUsed
|
|
132
|
-
let applicableResources = []
|
|
133
|
-
|
|
134
|
-
if (req.options.language) {
|
|
135
|
-
languageUsed = req.options.language
|
|
136
|
-
applicableResources = resources.filter((r) => r.resourceName.startsWith(\`\${languageUsed}-\`))
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!applicableResources.length && defaultLanguage) {
|
|
140
|
-
languageUsed = defaultLanguage
|
|
141
|
-
applicableResources = resources.filter((r) => r.resourceName.startsWith(\`\${languageUsed}-\`))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
console.log(\`Found \${applicableResources.length} resources for language "\${languageUsed}"\`)
|
|
145
|
-
|
|
146
|
-
req.options.localizedResources = applicableResources
|
|
147
|
-
req.data.$localizedResources = applicableResources
|
|
148
|
-
|
|
149
|
-
const localizedResourceByName = {}
|
|
150
|
-
|
|
151
|
-
applicableResources.forEach((r) => {
|
|
152
|
-
localizedResourceByName[r.resourceName.substring(\`\${languageUsed}-\`.length)] = r.data
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
req.options.localizedResource = applicableResources.length === 1 ? applicableResources[0].data : localizedResourceByName
|
|
156
|
-
req.data.$localizedResource = req.options.localizedResource
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
`
|
|
160
|
-
),
|
|
161
|
-
folder: template.folder || null
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (template.readPermissions != null) {
|
|
165
|
-
scriptProps.readPermissions = template.readPermissions
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (template.editPermissions != null) {
|
|
169
|
-
scriptProps.editPermissions = template.editPermissions
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const newScript = await insertUnique(reporter, 'scripts', `${template.name}_resources`, scriptProps, req)
|
|
173
|
-
|
|
174
|
-
template.scripts = template.scripts || []
|
|
175
|
-
|
|
176
|
-
template.scripts.unshift({
|
|
177
|
-
shortid: newScript.shortid
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
template.resources = null
|
|
182
|
-
|
|
183
|
-
await reporter.documentStore.collection('templates').update({ _id: template._id }, { $set: template }, req)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
for (const dataEntityId of dataEntitiesToRemove) {
|
|
187
|
-
await reporter.documentStore.collection('data').remove({ _id: dataEntityId }, req)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (templateIds.length !== 0) {
|
|
191
|
-
reporter.logger.debug('Migration "resourcesToAssets" finished')
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
await reporter.documentStore.commitTransaction(req)
|
|
195
|
-
|
|
196
|
-
await reporter.settings.addOrSet('core-migrated-resources', true)
|
|
197
|
-
} catch (migrationErr) {
|
|
198
|
-
await reporter.documentStore.rollbackTransaction(req)
|
|
199
|
-
|
|
200
|
-
migrationErr.message = `Migration "resourcesToAssets" failed: ${migrationErr.message}`
|
|
201
|
-
|
|
202
|
-
throw migrationErr
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async function insertUnique (reporter, collectionName, baseName, entity, req) {
|
|
207
|
-
let newEntity
|
|
208
|
-
let tryCount = 0
|
|
209
|
-
|
|
210
|
-
while (newEntity == null) {
|
|
211
|
-
try {
|
|
212
|
-
const entityName = '_'.repeat(tryCount) + baseName
|
|
213
|
-
|
|
214
|
-
newEntity = await reporter.documentStore.collection(collectionName).insert({
|
|
215
|
-
...entity,
|
|
216
|
-
name: entityName
|
|
217
|
-
}, req)
|
|
218
|
-
|
|
219
|
-
return newEntity
|
|
220
|
-
} catch (insertError) {
|
|
221
|
-
tryCount++
|
|
222
|
-
|
|
223
|
-
if (insertError.code === 'DUPLICATED_ENTITY') {
|
|
224
|
-
continue
|
|
225
|
-
} else {
|
|
226
|
-
throw insertError
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
const Request = require('../../shared/request')
|
|
2
|
-
|
|
3
|
-
module.exports = async (reporter) => {
|
|
4
|
-
if (
|
|
5
|
-
reporter.options.migrateXlsxTemplatesToAssets === false ||
|
|
6
|
-
reporter.documentStore.collection('xlsxTemplates') == null ||
|
|
7
|
-
reporter.documentStore.collection('assets') == null
|
|
8
|
-
) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const migrated = await reporter.settings.findValue('core-migrated-xlsxTemplates')
|
|
13
|
-
|
|
14
|
-
if (migrated) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const req = Request({})
|
|
19
|
-
await reporter.documentStore.beginTransaction(req)
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const xlsxTemplateIds = await reporter.documentStore.collection('xlsxTemplates').find({}, { _id: 1 }, req)
|
|
23
|
-
|
|
24
|
-
if (xlsxTemplateIds.length !== 0) {
|
|
25
|
-
reporter.logger.debug('Running migration "xlsxTemplatesToAssets"')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const xlsxTemplateToAssetMap = new Map()
|
|
29
|
-
|
|
30
|
-
for (const xlsxTemplateId of xlsxTemplateIds) {
|
|
31
|
-
const xlsxTemplate = await reporter.documentStore.collection('xlsxTemplates').findOne({ _id: xlsxTemplateId._id }, req)
|
|
32
|
-
|
|
33
|
-
if (!xlsxTemplateToAssetMap.has(xlsxTemplate.shortid)) {
|
|
34
|
-
let newAsset
|
|
35
|
-
let tryCount = 0
|
|
36
|
-
|
|
37
|
-
while (newAsset == null) {
|
|
38
|
-
try {
|
|
39
|
-
const assetName = `${'_'.repeat(tryCount) + xlsxTemplate.name}.xlsx`
|
|
40
|
-
|
|
41
|
-
const assetProps = {
|
|
42
|
-
name: assetName,
|
|
43
|
-
content: xlsxTemplate.contentRaw,
|
|
44
|
-
folder: xlsxTemplate.folder || null
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (xlsxTemplate.readPermissions != null) {
|
|
48
|
-
assetProps.readPermissions = xlsxTemplate.readPermissions
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (xlsxTemplate.editPermissions != null) {
|
|
52
|
-
assetProps.editPermissions = xlsxTemplate.editPermissions
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
newAsset = await reporter.documentStore.collection('assets').insert(assetProps, req)
|
|
56
|
-
} catch (insertError) {
|
|
57
|
-
tryCount++
|
|
58
|
-
|
|
59
|
-
if (insertError.code === 'DUPLICATED_ENTITY') {
|
|
60
|
-
continue
|
|
61
|
-
} else {
|
|
62
|
-
throw insertError
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
xlsxTemplateToAssetMap.set(xlsxTemplate.shortid, newAsset)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const templateIds = await reporter.documentStore.collection('templates').find({}, { _id: 1 }, req)
|
|
72
|
-
|
|
73
|
-
for (const templateId of templateIds) {
|
|
74
|
-
const template = await reporter.documentStore.collection('templates').findOne({ _id: templateId._id }, req)
|
|
75
|
-
let continueUpdate = false
|
|
76
|
-
|
|
77
|
-
// handle jsreport-xlsx migration
|
|
78
|
-
if (template.xlsxTemplate != null) {
|
|
79
|
-
continueUpdate = true
|
|
80
|
-
|
|
81
|
-
const xlsxTemplateRef = template.xlsxTemplate
|
|
82
|
-
|
|
83
|
-
template.xlsxTemplate = null
|
|
84
|
-
|
|
85
|
-
if (xlsxTemplateRef.shortid != null && xlsxTemplateToAssetMap.has(xlsxTemplateRef.shortid)) {
|
|
86
|
-
template.xlsx = template.xlsx || {}
|
|
87
|
-
template.xlsx.templateAssetShortid = xlsxTemplateToAssetMap.get(xlsxTemplateRef.shortid).shortid
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// handle jsreport-html-to-xlsx migration
|
|
92
|
-
if (template.baseXlsxTemplate != null) {
|
|
93
|
-
continueUpdate = true
|
|
94
|
-
|
|
95
|
-
const baseXlsxTemplateRef = template.baseXlsxTemplate
|
|
96
|
-
|
|
97
|
-
template.baseXlsxTemplate = null
|
|
98
|
-
|
|
99
|
-
if (baseXlsxTemplateRef.shortid != null && xlsxTemplateToAssetMap.has(baseXlsxTemplateRef.shortid)) {
|
|
100
|
-
template.htmlToXlsx = template.htmlToXlsx || {}
|
|
101
|
-
template.htmlToXlsx.templateAssetShortid = xlsxTemplateToAssetMap.get(baseXlsxTemplateRef.shortid).shortid
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (continueUpdate) {
|
|
106
|
-
await reporter.documentStore.collection('templates').update({ _id: template._id }, { $set: template }, req)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (const xlsxTemplateId of xlsxTemplateIds) {
|
|
111
|
-
await reporter.documentStore.collection('xlsxTemplates').remove({ _id: xlsxTemplateId._id }, req)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (xlsxTemplateIds.length !== 0) {
|
|
115
|
-
reporter.logger.debug('Migration "xlsxTemplatesToAssets" finished')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await reporter.documentStore.commitTransaction(req)
|
|
119
|
-
|
|
120
|
-
await reporter.settings.addOrSet('core-migrated-xlsxTemplates', true)
|
|
121
|
-
} catch (migrationErr) {
|
|
122
|
-
await reporter.documentStore.rollbackTransaction(req)
|
|
123
|
-
|
|
124
|
-
migrationErr.message = `Migration "xlsxTemplatesToAssets" failed: ${migrationErr.message}`
|
|
125
|
-
|
|
126
|
-
throw migrationErr
|
|
127
|
-
}
|
|
128
|
-
}
|