Taichi Masuyama 4 lat temu
rodzic
commit
93f15a014a

+ 4 - 1
packages/app/src/server/models/page.ts

@@ -852,8 +852,11 @@ schema.statics.takeOffFromTree = async function(pageId: ObjectIdLike) {
   return this.findByIdAndUpdate(pageId, { $set: { parent: null } });
 };
 
-schema.statics.removeEmptyPagesByPaths = async function(paths: string[]): Promise<void> {
+schema.statics.removeEmptyPages = async function(pageIdsToNotRemove: ObjectIdLike[], paths: string[]): Promise<void> {
   await this.deleteMany({
+    _id: {
+      $nin: pageIdsToNotRemove,
+    },
     path: {
       $in: paths,
     },

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

@@ -2482,7 +2482,6 @@ class PageService {
    */
   async normalizeParentRecursively(paths: string[], user: any | null): Promise<void> {
     const Page = mongoose.model('Page') as unknown as PageModel;
-    const { PageQueryBuilder } = Page;
 
     const ancestorPaths = paths.flatMap(p => collectAncestorPaths(p, [p]));
     const regexps = paths.map(p => new RegExp(`^${escapeStringRegexp(addTrailingSlash(p))}`, 'i'));
@@ -2626,7 +2625,7 @@ class PageService {
         }
 
         // Remove unnecessary empty pages
-        await Page.removeEmptyPagesByPaths(pages.map(p => p.path));
+        await Page.removeEmptyPages(pages.map(p => p._id), pages.map(p => p.path));
 
         callback();
       },

+ 1 - 6
packages/app/test/integration/service/v5.migration.test.js

@@ -28,7 +28,7 @@ describe('V5 page migration', () => {
       jest.restoreAllMocks();
 
       // initialize pages for test
-      let pages = await Page.insertMany([
+      await Page.insertMany([
         {
           path: '/private1',
           grant: Page.GRANT_OWNER,
@@ -59,11 +59,6 @@ describe('V5 page migration', () => {
         },
       ]);
 
-      if (!await Page.exists({ path: '/' })) {
-        const additionalPages = await Page.insertMany([{ path: '/', grant: Page.GRANT_PUBLIC }]);
-        pages = [...additionalPages, ...pages];
-      }
-
       const pagesToRun = await Page.find({ path: { $in: ['/private1', '/dummyParent/private1'] } });
 
       // migrate