|
@@ -12,7 +12,8 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
const ObjectId = mongoose.Schema.Types.ObjectId;
|
|
const ObjectId = mongoose.Schema.Types.ObjectId;
|
|
|
const revisionSchema = new mongoose.Schema({
|
|
const revisionSchema = new mongoose.Schema({
|
|
|
- path: { type: String, required: true, index: true },
|
|
|
|
|
|
|
+ // OBSOLETE path: { type: String, required: true, index: true }
|
|
|
|
|
+ pageId: { type: ObjectId, required: true, index: true },
|
|
|
body: {
|
|
body: {
|
|
|
type: String,
|
|
type: String,
|
|
|
required: true,
|
|
required: true,
|
|
@@ -36,18 +37,10 @@ module.exports = function(crowi) {
|
|
|
.exec();
|
|
.exec();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- revisionSchema.statics.updateRevisionListByPath = function(path, updateData, options) {
|
|
|
|
|
|
|
+ revisionSchema.statics.updateRevisionListByPath = async function(path, updateData) {
|
|
|
const Revision = this;
|
|
const Revision = this;
|
|
|
|
|
|
|
|
- return new Promise(((resolve, reject) => {
|
|
|
|
|
- Revision.update({ path }, { $set: updateData }, { multi: true }, (err, data) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return resolve(data);
|
|
|
|
|
- });
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ return Revision.updateMany({ path }, { $set: updateData });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
revisionSchema.statics.prepareRevision = function(pageData, body, previousBody, user, options) {
|
|
revisionSchema.statics.prepareRevision = function(pageData, body, previousBody, user, options) {
|
|
@@ -64,7 +57,7 @@ module.exports = function(crowi) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const newRevision = new Revision();
|
|
const newRevision = new Revision();
|
|
|
- newRevision.path = pageData.path;
|
|
|
|
|
|
|
+ newRevision.pageId = pageData._id;
|
|
|
newRevision.body = body;
|
|
newRevision.body = body;
|
|
|
newRevision.format = format;
|
|
newRevision.format = format;
|
|
|
newRevision.author = user._id;
|
|
newRevision.author = user._id;
|
|
@@ -76,24 +69,5 @@ module.exports = function(crowi) {
|
|
|
return newRevision;
|
|
return newRevision;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- revisionSchema.statics.removeRevisionsByPath = function(path) {
|
|
|
|
|
- const Revision = this;
|
|
|
|
|
-
|
|
|
|
|
- return new Promise(((resolve, reject) => {
|
|
|
|
|
- Revision.remove({ path }, (err, data) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return resolve(data);
|
|
|
|
|
- });
|
|
|
|
|
- }));
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- revisionSchema.statics.findAuthorsByPage = async function(page) {
|
|
|
|
|
- const result = await this.distinct('author', { path: page.path }).exec();
|
|
|
|
|
- return result;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
return mongoose.model('Revision', revisionSchema);
|
|
return mongoose.model('Revision', revisionSchema);
|
|
|
};
|
|
};
|