Commit 7fd9fd70 authored by Caleb Weeks's avatar Caleb Weeks

ensuring that the jcr:content node of the page being updated is safe to write to

parent cd4fb7bc
......@@ -387,17 +387,58 @@ module.exports = function restubFromBlQuery(params, cb){
});
//keep retring saving to the path until success, or until 30 seconds has passed
let touch = (path, touchCb, attempt) => {
attempt = attempt || 0;
if(attempt < 60){
sc.post(path, {'bl:touch': (new Date()).getTime() + ""}, (err)=>{
if(!err){
touchCb();
}else{
log.warning(`Failed to successfully touch ${path} on attempt ${attempt}`);
setTimeout(()=>{touch(path, touchCb, attempt + 1)}, 500);
}
});
}else{
let touchErr = `Failed to successfully touch ${path} after 60 attempts`;
log.error(touchErr)
touchCb(touchErr);
}
}
let next = function(err){
if(!err){
if(throttledRequests.length){
var formParams = throttledRequests.shift();
sc.post(targetPath, formParams, (err)=>{
if(err){
console.log('Error processing stub POST', {targetPath, formParams});
}
next(err);
});
let submitThrottledRequest = (touchErr)=>{
if(touchErr){
log.error('Not trying stub POST', {targetPath, formParams});
next(touchErr);
}else{
var formParams = throttledRequests.shift();
sc.post(targetPath, formParams, (err)=>{
if(err){
log.error('Error processing stub POST', {targetPath, formParams});
}
next(err);
});
}
};
//we only want to go with the touch approach when we're under a child page
if(_.includes(targetPath, "/jcr:content/")){
//do a 'touch' to ensure there are no current conflicts
let jcrPath = targetPath.split('/jcr:content')[0] + '/jcr:content';
touch(jcrPath, submitThrottledRequest);
}else{
submitThrottledRequest();
}
}else{
cb();
}
......
......@@ -90,6 +90,11 @@ module.exports.remapFlattened = function remapFlattened(flattenedInput, mappable
item.oldPath=item.value; item.value=newPath;
}
if(_.endsWith(item.name, 'bl:query')){
//add in the bl:processing node
flattenedResult.push({name: item.name.replace("bl:query", 'bl:processing'), value: "true"});
}
}
flattenedResult.push(item);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment