AnsweredAssumed Answered

node.remove() not working on batch

Question asked by michaelp on Sep 5, 2014
Latest reply on Sep 5, 2014 by kaynezhang
Hi guys,

I discovered something strange.


var query = "@cm\\:name:\"~*\"";
var nodes = search.luceneSearch(query);
var c = 0;
var d = 0;
var f = 0;
logger.log("Found " + nodes.length + " temporary files");

for (var node in nodes) {
   try {
      var doc = search.findNode("workspace://SpacesStore/" + nodes[node].properties["sys:node-uuid"]);
      var location = doc.displayPath + "/" + doc.name;
      if (doc.isContainer) {
         f++;
         continue;
      }
      if(doc.remove())
         logger.log(location + " - deleted");
         d++;
      } else {
         logger.log(location + " - not deleted");
      }
   } catch (e) {
      logger.log(e);
   }
   c++;
   
   if (c > 0) {
      break; //comment to delete ALL nodes from search result
   }
   
}

logger.log(d + "/" + c + " documents deleted");
logger.log(f + "/" + c + " were folders");


If I break the loop after the 1st node the 1st node will be deleted, if I want to delete all nodes (about ~500) NOTHING IS DELETED.

Why?

Alfresco 4.2.2


EDIT: all
doc.remove()
are returning
true
which means "success" at the documentation. No errors or exceptions, also nothing will get deleted

Outcomes