瀏覽代碼

test with code in master

Shun Miyazawa 4 年之前
父節點
當前提交
8e160214a6
共有 1 個文件被更改,包括 45 次插入5 次删除
  1. 45 5
      packages/app/src/server/service/page.js

+ 45 - 5
packages/app/src/server/service/page.js

@@ -63,11 +63,6 @@ class PageService {
     // sanitize path
     newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
 
-    // create descendants first
-    if (isRecursively) {
-      await this.renameDescendantsWithStream(page, newPagePath, user, options);
-    }
-
     const update = {};
     // update Page
     update.path = newPagePath;
@@ -85,6 +80,10 @@ 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);
 
@@ -92,6 +91,47 @@ class PageService {
   }
 
 
+  // async renamePage(page, newPagePath, user, options, isRecursively = false) {
+
+  //   const Page = this.crowi.model('Page');
+  //   const Revision = this.crowi.model('Revision');
+  //   const path = page.path;
+  //   const createRedirectPage = options.createRedirectPage || false;
+  //   const updateMetadata = options.updateMetadata || false;
+  //   const socketClientId = options.socketClientId || null;
+
+  //   // sanitize path
+  //   newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
+
+  //   // create descendants first
+  //   if (isRecursively) {
+  //     await this.renameDescendantsWithStream(page, newPagePath, user, options);
+  //   }
+
+  //   const update = {};
+  //   // update Page
+  //   update.path = newPagePath;
+  //   if (updateMetadata) {
+  //     update.lastUpdateUser = user;
+  //     update.updatedAt = Date.now();
+  //   }
+  //   const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
+
+  //   // update Rivisions
+  //   await Revision.updateRevisionListByPath(path, { path: newPagePath }, {});
+
+  //   if (createRedirectPage) {
+  //     const body = `redirect ${newPagePath}`;
+  //     await Page.create(path, body, user, { redirectTo: newPagePath });
+  //   }
+
+  //   this.pageEvent.emit('delete', page, user, socketClientId);
+  //   this.pageEvent.emit('create', renamedPage, user, socketClientId);
+
+  //   return renamedPage;
+  // }
+
+
   async renameDescendants(pages, user, options, oldPagePathPrefix, newPagePathPrefix) {
     const Page = this.crowi.model('Page');