Remove un-rectify-able changes
This commit is contained in:
parent
2de33d4da5
commit
52eb72d94f
|
@ -172,15 +172,19 @@ Change.prototype.rectify = function(cb) {
|
|||
|
||||
async.parallel(tasks, function(err) {
|
||||
if(err) return cb(err);
|
||||
change.save(cb);
|
||||
if(change.prev === Change.UNKNOWN) {
|
||||
// this occurs when a record of a change doesn't exist
|
||||
// and its current revision is null (not found)
|
||||
change.remove(cb);
|
||||
} else {
|
||||
change.save(cb);
|
||||
}
|
||||
});
|
||||
|
||||
function updateRevision(cb) {
|
||||
// get the current revision
|
||||
change.currentRevision(function(err, rev) {
|
||||
if(err) return Change.handleError(err, cb);
|
||||
change.debug('updating revision ('+ rev +')');
|
||||
// deleted
|
||||
if(rev) {
|
||||
// avoid setting rev and prev to the same value
|
||||
if(currentRev !== rev) {
|
||||
|
@ -196,10 +200,9 @@ Change.prototype.rectify = function(cb) {
|
|||
} else if(!change.prev) {
|
||||
change.debug('ERROR - could not determing prev');
|
||||
change.prev = Change.UNKNOWN;
|
||||
return cb(new Error('could not determine the previous rev for '
|
||||
+ change.modelId));
|
||||
}
|
||||
}
|
||||
change.debug('updated revision (was ' + currentRev + ')');
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
@ -493,8 +496,9 @@ Change.prototype.getModel = function(callback) {
|
|||
*
|
||||
* **Note: call `conflict.fetch()` to get the `target` and `source` models.
|
||||
*
|
||||
* @param {*} sourceModelId
|
||||
* @param {*} targetModelId
|
||||
* @param {*} modelId
|
||||
* @param {DataModel} SourceModel
|
||||
* @param {DataModel} TargetModel
|
||||
* @property {ModelClass} source The source model instance
|
||||
* @property {ModelClass} target The target model instance
|
||||
*/
|
||||
|
@ -570,9 +574,9 @@ Conflict.prototype.changes = function(cb) {
|
|||
], done);
|
||||
|
||||
function getSourceChange(cb) {
|
||||
conflict.SourceChange.findOne({
|
||||
modelId: conflict.sourceModelId
|
||||
}, function(err, change) {
|
||||
conflict.SourceChange.findOne({where: {
|
||||
modelId: conflict.modelId
|
||||
}}, function(err, change) {
|
||||
if(err) return cb(err);
|
||||
sourceChange = change;
|
||||
cb();
|
||||
|
@ -580,9 +584,9 @@ Conflict.prototype.changes = function(cb) {
|
|||
}
|
||||
|
||||
function getTargetChange(cb) {
|
||||
conflict.TargetChange.findOne({
|
||||
modelId: conflict.targetModelId
|
||||
}, function(err, change) {
|
||||
conflict.TargetChange.findOne({where: {
|
||||
modelId: conflict.modelId
|
||||
}}, function(err, change) {
|
||||
if(err) return cb(err);
|
||||
targetChange = change;
|
||||
cb();
|
||||
|
|
|
@ -767,7 +767,8 @@ DataModel.createUpdates = function(deltas, cb) {
|
|||
if(err) return cb(err);
|
||||
if(!inst) {
|
||||
console.error('missing data for change:', change);
|
||||
return callback();
|
||||
return cb && cb(new Error('missing data for change: '
|
||||
+ change.modelId));
|
||||
}
|
||||
if(inst.toObject) {
|
||||
update.data = inst.toObject();
|
||||
|
|
Loading…
Reference in New Issue