|
|
@@ -73,20 +73,43 @@ class PageService {
|
|
|
}
|
|
|
|
|
|
async duplicateRecursively(page, newPagePath, user) {
|
|
|
+ const pageCollection = mongoose.connection.collection('pages');
|
|
|
+ const revisionCollection = mongoose.connection.collection('revisions');
|
|
|
+
|
|
|
const Page = this.crowi.model('Page');
|
|
|
const newPagePathPrefix = newPagePath;
|
|
|
const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
|
|
|
-
|
|
|
const pages = await Page.findManageableListWithDescendants(page, user);
|
|
|
|
|
|
- const promise = pages.map(async(page) => {
|
|
|
+ const duplicatePageBulkOp = pageCollection.initializeUnorderedBulkOp();
|
|
|
+ const revisionPrepareBulkOp = revisionCollection.initializeUnorderedBulkOp();
|
|
|
+
|
|
|
+ pages.forEach(async(page) => {
|
|
|
const newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
|
- return this.duplicate(page, newPagePath, user);
|
|
|
+ // await page.populate({ path: 'revision', model: 'Revision', select: 'body' }).execPopulate();
|
|
|
+
|
|
|
+ duplicatePageBulkOp.insert({
|
|
|
+ path: newPagePath, body: 'new', creator: user._id, lastUpdateUser: user._id,
|
|
|
+ });
|
|
|
+
|
|
|
+ revisionPrepareBulkOp.insert({
|
|
|
+ path: newPagePath, body: 'new', author: user._id, format: 'markdown',
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
+ const { result } = await revisionPrepareBulkOp.execute();
|
|
|
+ console.log(result);
|
|
|
+
|
|
|
+
|
|
|
+ // const promise = pages.map(async(page) => {
|
|
|
+ // const newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
|
+ // return this.duplicate(page, newPagePath, user);
|
|
|
+ // });
|
|
|
+
|
|
|
const newPath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
|
|
|
|
- await Promise.allSettled(promise);
|
|
|
+ // await Promise.allSettled(promise);
|
|
|
|
|
|
const newParentpage = await Page.findByPath(newPath);
|
|
|
|