|
|
@@ -865,18 +865,6 @@ class PageService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _setIsV5IndexNormalizationInProgress(status) {
|
|
|
- try {
|
|
|
- await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
|
|
|
- 'app:isV5IndexNormalizationInProgress': status,
|
|
|
- });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.error(`Failed to update app:isV5IndexNormalizationInProgress to ${status} .`);
|
|
|
- throw err;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
async _isPagePathIndexUnique() {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
const now = (new Date()).toString();
|
|
|
@@ -897,6 +885,7 @@ class PageService {
|
|
|
}
|
|
|
else {
|
|
|
logger.error('Error occurred while checking index uniqueness.', err);
|
|
|
+ await Page.deleteMany({ path: { $regex: new RegExp('growi_check_is_path_index_unique', 'g') } });
|
|
|
throw err;
|
|
|
}
|
|
|
}
|
|
|
@@ -906,28 +895,20 @@ class PageService {
|
|
|
return isUnique;
|
|
|
}
|
|
|
|
|
|
+ // TODO: use socket to send status to the client
|
|
|
async v5InitialMigration(grant) {
|
|
|
// const socket = this.crowi.socketIoService.getAdminSocket();
|
|
|
- const isProcessing = this.crowi.configManager.getConfig('crowi', 'app:isV5IndexNormalizationInProgress');
|
|
|
-
|
|
|
- // avoid re-running many times
|
|
|
- if (isProcessing) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
const isUnique = await this._isPagePathIndexUnique();
|
|
|
|
|
|
// drop unique index first
|
|
|
if (isUnique) {
|
|
|
- await this._setIsV5IndexNormalizationInProgress(true);
|
|
|
try {
|
|
|
await this._v5NormalizeIndex();
|
|
|
- await this._setIsV5IndexNormalizationInProgress(false);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error('V5 index normalization failed.', err);
|
|
|
// socket.emit('v5IndexNormalizationFailed', { error: err.message });
|
|
|
- await this._setIsV5IndexNormalizationInProgress(false);
|
|
|
throw err;
|
|
|
}
|
|
|
}
|