Просмотр исходного кода

Merge pull request #3566 from weseek/fix/5474-5475-streamToPromise

Fix/5474 5475 stream to promise
Yuki Takei 5 лет назад
Родитель
Сommit
a49ac06d6e
2 измененных файлов с 14 добавлено и 8 удалено
  1. 2 0
      CHANGES.md
  2. 12 8
      src/server/service/page.js

+ 2 - 0
CHANGES.md

@@ -9,6 +9,8 @@
     * Introduced by v4.2.8
 * Fix: Group page is excluded by recurrence operation
     * Introduced by v4.2.8
+* Fix: New path to rename and duplicate is considered as a child page
+    * Introduced by v4.2.8
 
 ## v4.2.13
 

+ 12 - 8
src/server/service/page.js

@@ -5,6 +5,7 @@ const debug = require('debug')('growi:models:page');
 const { Writable } = require('stream');
 const { createBatchStream } = require('@server/util/batch-stream');
 const { isTrashPage } = require('@commons/util/path-utils');
+const streamToPromise = require('stream-to-promise');
 const { serializePageSecurely } = require('../models/serializers/page-serializer');
 
 const BULK_REINDEX_SIZE = 100;
@@ -57,6 +58,10 @@ class PageService {
     // sanitize path
     newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
 
+    if (isRecursively) {
+      await this.renameDescendantsWithStream(page, newPagePath, user, options);
+    }
+
     const update = {};
     // update Page
     update.path = newPagePath;
@@ -74,10 +79,6 @@ class PageService {
       await Page.create(path, body, user, { redirectTo: newPagePath });
     }
 
-    if (isRecursively) {
-      this.renameDescendantsWithStream(page, newPagePath, user, options);
-    }
-
     this.pageEvent.emit('delete', page, user, socketClientId);
     this.pageEvent.emit('create', renamedPage, user, socketClientId);
 
@@ -185,6 +186,8 @@ class PageService {
     readStream
       .pipe(createBatchStream(BULK_REINDEX_SIZE))
       .pipe(writeStream);
+
+    return streamToPromise(writeStream);
   }
 
 
@@ -237,14 +240,14 @@ class PageService {
 
     newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
 
+    if (isRecursively) {
+      await this.duplicateDescendantsWithStream(page, newPagePath, user);
+    }
+
     const createdPage = await Page.create(
       newPagePath, page.revision.body, user, options,
     );
 
-    if (isRecursively) {
-      this.duplicateDescendantsWithStream(page, newPagePath, user);
-    }
-
     // take over tags
     const originTags = await page.findRelatedTagsById();
     let savedTags = [];
@@ -391,6 +394,7 @@ class PageService {
       .pipe(createBatchStream(BULK_REINDEX_SIZE))
       .pipe(writeStream);
 
+    return streamToPromise(writeStream);
   }