|
|
@@ -12,27 +12,6 @@ class PageService {
|
|
|
this.crowi = crowi;
|
|
|
}
|
|
|
|
|
|
- async deleteCompletely(pageId, pagePath) {
|
|
|
- // Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
- const Bookmark = this.crowi.model('Bookmark');
|
|
|
- const Comment = this.crowi.model('Comment');
|
|
|
- const Page = this.crowi.model('Page');
|
|
|
- const PageTagRelation = this.crowi.model('PageTagRelation');
|
|
|
- const ShareLink = this.crowi.model('ShareLink');
|
|
|
- const Revision = this.crowi.model('Revision');
|
|
|
-
|
|
|
- return Promise.all([
|
|
|
- Bookmark.removeBookmarksByPageId(pageId),
|
|
|
- Comment.removeCommentsByPageId(pageId),
|
|
|
- PageTagRelation.remove({ relatedPage: pageId }),
|
|
|
- ShareLink.remove({ relatedPage: pageId }),
|
|
|
- Revision.removeRevisionsByPath(pagePath),
|
|
|
- Page.findByIdAndRemove(pageId),
|
|
|
- Page.removeRedirectOriginPageByPath(pagePath),
|
|
|
- this.removeAllAttachments(pageId),
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
async removeAllAttachments(pageId) {
|
|
|
const Attachment = this.crowi.model('Attachment');
|
|
|
const { attachmentService } = this.crowi;
|
|
|
@@ -98,9 +77,28 @@ class PageService {
|
|
|
return newParentpage;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
+ */
|
|
|
+ async completelyDeletePageRecursively(targetPage, user, options = {}) {
|
|
|
+ const findOpts = { includeTrashed: true };
|
|
|
+ const Page = this.crowi.model('Page');
|
|
|
+
|
|
|
+ // find manageable descendants (this array does not include GRANT_RESTRICTED)
|
|
|
+ const pages = await Page.findManageableListWithDescendants(targetPage, user, findOpts);
|
|
|
+
|
|
|
+ // ここをストリーム化したい
|
|
|
+ // page ではなく pages として渡したい
|
|
|
+ // await Promise.all(pages.map((page) => {
|
|
|
+ // return this.completelyDeletePage(page, user, options);
|
|
|
+ // }));
|
|
|
+ return this.completelyDeletePage(pages, user, options);
|
|
|
|
|
|
- async completelyDeletePage(pageData, user, options = {}) {
|
|
|
- this.validateCrowi();
|
|
|
+ }
|
|
|
+
|
|
|
+ // pages をうけとれるように改修したい
|
|
|
+ async completelyDeletePage(pages, user, options = {}) {
|
|
|
+ // this.validateCrowi();
|
|
|
let pageEvent;
|
|
|
// init event
|
|
|
if (this.crowi != null) {
|
|
|
@@ -109,32 +107,47 @@ class PageService {
|
|
|
pageEvent.on('update', pageEvent.onUpdate);
|
|
|
}
|
|
|
|
|
|
- const { _id, path } = pageData;
|
|
|
+ const ids = pages.map(page => (page._id));
|
|
|
+ // ids.join('');
|
|
|
+ const paths = pages.map(page => (page.path));
|
|
|
+
|
|
|
+ // const { _ids, path } = pageData;
|
|
|
const socketClientId = options.socketClientId || null;
|
|
|
|
|
|
- logger.debug('Deleting completely', path);
|
|
|
+ logger.debug('Deleting completely', paths);
|
|
|
|
|
|
- await this.deleteCompletely(_id, path);
|
|
|
+ await this.deleteCompletely(ids, paths);
|
|
|
|
|
|
if (socketClientId != null) {
|
|
|
- pageEvent.emit('delete', pageData, user, socketClientId); // update as renamed page
|
|
|
+ pageEvent.emit('delete', pages, user, socketClientId); // update as renamed page
|
|
|
}
|
|
|
- return pageData;
|
|
|
+ return pages;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
- */
|
|
|
- async completelyDeletePageRecursively(targetPage, user, options = {}) {
|
|
|
- const findOpts = { includeTrashed: true };
|
|
|
- const Page = this.crowi.model('Page');
|
|
|
-
|
|
|
- // find manageable descendants (this array does not include GRANT_RESTRICTED)
|
|
|
- const pages = await Page.findManageableListWithDescendants(targetPage, user, findOpts);
|
|
|
+ // pageIds を受け取れるように改修したい
|
|
|
+ async deleteCompletely(pageIds, pagePaths) {
|
|
|
+ // Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
+ // const Bookmark = this.crowi.model('Bookmark');
|
|
|
+ // const Comment = this.crowi.model('Comment');
|
|
|
+ // const Page = this.crowi.model('Page');
|
|
|
+ const PageTagRelation = this.crowi.model('PageTagRelation');
|
|
|
+ // const ShareLink = this.crowi.model('ShareLink');
|
|
|
+ // const Revision = this.crowi.model('Revision');
|
|
|
+
|
|
|
+ console.log(pageIds);
|
|
|
+ // console.log(PageTagRelation.find({ pageIds }));
|
|
|
+ return await PageTagRelation.find({ relatedPage: { $in: pageIds } }).remove({});
|
|
|
+ // return Promise.all([
|
|
|
+ // Bookmark.removeBookmarksByPageId(pageIds),
|
|
|
+ // Comment.removeCommentsByPageId(pageIds),
|
|
|
+ // PageTagRelation.remove({ relatedPage: pageIds }),
|
|
|
+ // ShareLink.remove({ relatedPage: pageIds }),
|
|
|
+ // Revision.removeRevisionsByPath(pagePaths),
|
|
|
+ // Page.findByIdAndRemove(pageIds),
|
|
|
+ // Page.removeRedirectOriginPageByPath(pagePaths),
|
|
|
+ // this.removeAllAttachments(pageIds),
|
|
|
+ // ]);
|
|
|
|
|
|
- await Promise.all(pages.map((page) => {
|
|
|
- return this.completelyDeletePage(page, user, options);
|
|
|
- }));
|
|
|
}
|
|
|
|
|
|
|