Przeglądaj źródła

success to create new page paths in duplicateRecursively without using Promiss.allSettled but need to change the syntax of the duplicate method to fix an error.

kaori 5 lat temu
rodzic
commit
d1ed33535e
1 zmienionych plików z 15 dodań i 7 usunięć
  1. 15 7
      src/server/service/page.js

+ 15 - 7
src/server/service/page.js

@@ -78,19 +78,27 @@ class PageService {
 
 
   async duplicateRecursively(page, newPagePath, user) {
   async duplicateRecursively(page, newPagePath, user) {
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
-    // const newPagePathPrefix = newPagePath;
     const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
     const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
-
+    // ここで配下のページを含むpagesを取得
     const pages = await Page.findManageableListWithDescendants(page, user);
     const pages = await Page.findManageableListWithDescendants(page, user);
 
 
-    const promise = pages.map(async(page) => {
-      const newPagePath1 = page.path.replace(pathRegExp, newPagePath);
-      return this.duplicate(page, newPagePath1, user);
-    });
+
+    // const promise = pages.map(async(page) => {
+    //   const newPagePath1 = page.path.replace(pathRegExp, newPagePath);
+    //   return this.duplicate(page, newPagePath1, user);
+    // });
+
+    const newPagePaths = pages.map(page => page.path.replace(pathRegExp, newPagePath));
+    await this.duplicate(pages, newPagePaths, user);
+
+    // const promise = async() => {
+    // const newPagePaths = pages[path].replace(pathRegExp, newPagePath);
+    // await this.duplicate(pages, newPagePaths, user);
+    // };
 
 
     const newPath = page.path.replace(pathRegExp, newPagePath);
     const newPath = page.path.replace(pathRegExp, newPagePath);
 
 
-    await Promise.allSettled(promise);
+    // await Promise.allSettled(promise);
 
 
     const newParentpage = await Page.findByPath(newPath);
     const newParentpage = await Page.findByPath(newPath);