|
@@ -174,21 +174,49 @@ class ImportService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * import collections from json
|
|
|
|
|
|
|
+ * Calculate whether page normalization is required
|
|
|
*
|
|
*
|
|
|
* @param {string} collections MongoDB collection name
|
|
* @param {string} collections MongoDB collection name
|
|
|
- * @param {array} importSettingsMap key: collection name, value: ImportSettings instance
|
|
|
|
|
*/
|
|
*/
|
|
|
- async import(collections, importSettingsMap) {
|
|
|
|
|
- // init status object
|
|
|
|
|
- this.currentProgressingStatus = new CollectionProgressingStatus(collections);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ async getShouldNormalizePages(collections) {
|
|
|
const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
|
|
const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
|
|
|
const isImportPagesCollection = collections.includes('pages');
|
|
const isImportPagesCollection = collections.includes('pages');
|
|
|
const shouldNormalizePages = isV5Compatible && isImportPagesCollection;
|
|
const shouldNormalizePages = isV5Compatible && isImportPagesCollection;
|
|
|
|
|
|
|
|
- // set isV5Compatible to false
|
|
|
|
|
|
|
+ return shouldNormalizePages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Update the config app:isV5Compatible to false when page normalization is required
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {string} collections MongoDB collection name
|
|
|
|
|
+ */
|
|
|
|
|
+ async updateIsV5CompatibleBeforeImport(collections) {
|
|
|
|
|
+ const shouldNormalizePages = this.getShouldNormalizePages(collections);
|
|
|
|
|
+
|
|
|
if (shouldNormalizePages) await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', { 'app:isV5Compatible': false });
|
|
if (shouldNormalizePages) await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', { 'app:isV5Compatible': false });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Run pageService.normalizeAllPublicPages when page normalization is required
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {string} collections MongoDB collection name
|
|
|
|
|
+ */
|
|
|
|
|
+ async normalizeAllPublicPagesAfterImport(collections) {
|
|
|
|
|
+ const shouldNormalizePages = this.getShouldNormalizePages(collections);
|
|
|
|
|
+
|
|
|
|
|
+ if (shouldNormalizePages) await this.crowi.pageService.normalizeAllPublicPages();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * import collections from json
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {string} collections MongoDB collection name
|
|
|
|
|
+ * @param {array} importSettingsMap key: collection name, value: ImportSettings instance
|
|
|
|
|
+ */
|
|
|
|
|
+ async import(collections, importSettingsMap) {
|
|
|
|
|
+ // init status object
|
|
|
|
|
+ this.currentProgressingStatus = new CollectionProgressingStatus(collections);
|
|
|
|
|
|
|
|
// process serially so as not to waste memory
|
|
// process serially so as not to waste memory
|
|
|
const promises = collections.map((collectionName) => {
|
|
const promises = collections.map((collectionName) => {
|
|
@@ -207,9 +235,6 @@ class ImportService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // run normalizeAllPublicPages
|
|
|
|
|
- if (shouldNormalizePages) await this.crowi.pageService.normalizeAllPublicPages();
|
|
|
|
|
-
|
|
|
|
|
this.currentProgressingStatus = null;
|
|
this.currentProgressingStatus = null;
|
|
|
this.emitTerminateEvent();
|
|
this.emitTerminateEvent();
|
|
|
|
|
|