cancel
Showing results for 
Search instead for 
Did you mean: 

node.remove() not working on batch

michaelp
Confirmed Champ
Confirmed Champ
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
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
Javascript will be  automatically executed within an transaction,some code in the loop might cause an exception which cause it rollback.

Thanky for your reply.

Yes you are right, one exception is thrown at the ~400th node: Node is locked.

So this causes the rollback of the whole operation?

kaynezhang
World-Class Innovator
World-Class Innovator
Yes  I guess