Shun Miyazawa 4 лет назад
Родитель
Сommit
e175ab31c5
1 измененных файлов с 5 добавлено и 46 удалено
  1. 5 46
      packages/app/src/server/service/page.js

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

@@ -50,7 +50,6 @@ class PageService {
     return this.prepareShoudDeletePagesByRedirectTo(pagePath, redirectToPagePathMapping, pagePaths);
     return this.prepareShoudDeletePagesByRedirectTo(pagePath, redirectToPagePathMapping, pagePaths);
   }
   }
 
 
-
   async renamePage(page, newPagePath, user, options, isRecursively = false) {
   async renamePage(page, newPagePath, user, options, isRecursively = false) {
 
 
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
@@ -63,6 +62,11 @@ class PageService {
     // sanitize path
     // sanitize path
     newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
     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 = {};
     const update = {};
     // update Page
     // update Page
     update.path = newPagePath;
     update.path = newPagePath;
@@ -80,10 +84,6 @@ class PageService {
       await Page.create(path, body, user, { redirectTo: newPagePath });
       await Page.create(path, body, user, { redirectTo: newPagePath });
     }
     }
 
 
-    if (isRecursively) {
-      await this.renameDescendantsWithStream(page, newPagePath, user, options);
-    }
-
     this.pageEvent.emit('delete', page, user, socketClientId);
     this.pageEvent.emit('delete', page, user, socketClientId);
     this.pageEvent.emit('create', renamedPage, user, socketClientId);
     this.pageEvent.emit('create', renamedPage, user, socketClientId);
 
 
@@ -91,47 +91,6 @@ 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) {
   async renameDescendants(pages, user, options, oldPagePathPrefix, newPagePathPrefix) {
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');