|
|
@@ -881,6 +881,27 @@ module.exports = function(crowi) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.deletePageRecursively = function (pageData, user, options) {
|
|
|
+ var Page = this
|
|
|
+ , path = pageData.path
|
|
|
+ , options = options || {}
|
|
|
+ ;
|
|
|
+
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ Page
|
|
|
+ .generateQueryToListByStartWith(path, user, options)
|
|
|
+ .then(function (pages) {
|
|
|
+ Promise.all(pages.map(function (page) {
|
|
|
+ return Page.deletePage(page, user, options);
|
|
|
+ }))
|
|
|
+ .then(function (data) {
|
|
|
+ return resolve(pageData);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.revertDeletedPage = function(pageData, user, options) {
|
|
|
var Page = this
|
|
|
, newPath = Page.getRevertDeletedPageName(pageData.path)
|
|
|
@@ -911,6 +932,26 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.revertDeletedPageRecursively = function (pageData, user, options) {
|
|
|
+ var Page = this
|
|
|
+ , path = pageData.path
|
|
|
+ , options = options || { includeDeletedPage: true}
|
|
|
+ ;
|
|
|
+
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ Page
|
|
|
+ .generateQueryToListByStartWith(path, user, options)
|
|
|
+ .then(function (pages) {
|
|
|
+ Promise.all(pages.map(function (page) {
|
|
|
+ return Page.revertDeletedPage(page, user, options);
|
|
|
+ }))
|
|
|
+ .then(function (data) {
|
|
|
+ return resolve(data[0]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* This is danger.
|
|
|
*/
|
|
|
@@ -946,6 +987,27 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.completelyDeletePageRecursively = function (pageData, user, options) {
|
|
|
+ // Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
+ var Page = this
|
|
|
+ , path = pageData.path
|
|
|
+ , options = options || { includeDeletedPage: true }
|
|
|
+ ;
|
|
|
+
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ Page
|
|
|
+ .generateQueryToListByStartWith(path, user, options)
|
|
|
+ .then(function (pages) {
|
|
|
+ Promise.all(pages.map(function (page) {
|
|
|
+ return Page.completelyDeletePage(page, user, options);
|
|
|
+ }))
|
|
|
+ .then(function (data) {
|
|
|
+ return resolve(data[0]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.removePageById = function(pageId) {
|
|
|
var Page = this;
|
|
|
|
|
|
@@ -1025,6 +1087,27 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.renameRecursively = function(pageData, newPagePathPrefix, user, options) {
|
|
|
+ var Page = this
|
|
|
+ , path = pageData.path
|
|
|
+ , pathRegExp = new RegExp('^' + path, 'i');
|
|
|
+
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ Page
|
|
|
+ .generateQueryToListByStartWith(path, user, options)
|
|
|
+ .then(function(pages) {
|
|
|
+ Promise.all(pages.map(function(page) {
|
|
|
+ newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
|
+ return Page.rename(page, newPagePath, user, options);
|
|
|
+ }))
|
|
|
+ .then(function() {
|
|
|
+ pageData.path = newPagePathPrefix;
|
|
|
+ return resolve();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.getHistories = function() {
|
|
|
// TODO
|
|
|
return;
|