Explorar o código

Improved rename

Taichi Masuyama %!s(int64=4) %!d(string=hai) anos
pai
achega
6c117a2fcf
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      packages/app/src/server/service/page.ts

+ 7 - 2
packages/app/src/server/service/page.ts

@@ -317,6 +317,7 @@ class PageService {
   }
   }
 
 
   async renamePage(page, newPagePath, user, options) {
   async renamePage(page, newPagePath, user, options) {
+    const Page = mongoose.model('Page') as unknown as PageModel;
     /*
     /*
      * Common Operation
      * Common Operation
      */
      */
@@ -330,6 +331,10 @@ class PageService {
       return this.renamePageV4(page, newPagePath, user, options);
       return this.renamePageV4(page, newPagePath, user, options);
     }
     }
 
 
+    if (await Page.exists({ path: newPagePath })) {
+      throw Error(`Page already exists at ${newPagePath}`);
+    }
+
     /*
     /*
      * Resumable Operation
      * Resumable Operation
      */
      */
@@ -1399,7 +1404,7 @@ class PageService {
       ShareLink.deleteMany({ relatedPage: { $in: pageIds } }),
       ShareLink.deleteMany({ relatedPage: { $in: pageIds } }),
       Revision.deleteMany({ pageId: { $in: pageIds } }),
       Revision.deleteMany({ pageId: { $in: pageIds } }),
       Page.deleteMany({ $or: [{ path: { $in: pagePaths } }, { _id: { $in: pageIds } }] }),
       Page.deleteMany({ $or: [{ path: { $in: pagePaths } }, { _id: { $in: pageIds } }] }),
-      PageRedirect.deleteMany({ $or: [{ toPath: { $in: pagePaths } }] }),
+      PageRedirect.deleteMany({ $or: [{ fromPath: { $in: pagePaths }, toPath: { $in: pagePaths } }] }),
       attachmentService.removeAllAttachments(attachments),
       attachmentService.removeAllAttachments(attachments),
     ]);
     ]);
   }
   }
@@ -1569,7 +1574,7 @@ class PageService {
       .pipe(createBatchStream(BULK_REINDEX_SIZE))
       .pipe(createBatchStream(BULK_REINDEX_SIZE))
       .pipe(writeStream);
       .pipe(writeStream);
 
 
-    await streamToPromise(readStream);
+    await streamToPromise(writeStream);
 
 
     return nDeletedNonEmptyPages;
     return nDeletedNonEmptyPages;
   }
   }