1

Alfresco Share doesn't keep track of content modified outside it's interface which makes the recently modified RSS/Dashlet useless. I'm working on creating an RSS that I can use within sites to pull a list of recently modified items.

Right now I'm just working on getting the list of files and I'm stumbling a little bit as I'm not very familiar with Webscripts. I've got this piece of code that will retrieve the contents of a site then build an array of the files, the problem I'm running into is I could have many subfolders and I'm not sure how to properly traverse them.

var folder = companyhome.childByNamePath("/Sites/foo/documentLibrary");

var docs = new Array();

print(folder);
print("iterating...");
var children = folder.children;
for (i=0; i<children.length; i++)
{
  var c = children[i];
  if (c.isContainer)
  {
    print(c.name + " is a folder, traversing...");
    var subfolder = companyhome.childByNamePath("/Sites/foo/documentLibrary/" + c.name.toString());
    var subchildren = subfolder.children;
    for (j=0; j<subchildren.length; j++)
    {
      var d = subchildren[j];
      if (d.isDocument) docs.push(d);
    }
  }
  if (c.isDocument) docs.push(c);
}

print(docs);

In the end I'll sort by modified time then chop it for presentation, I'm operating under the assumption that getting the content is the hard part :)

Ashex
  • 523
  • 5
  • 11

2 Answers2

6

I would write a recursive function to traverse the folder hiarchy, something like this:

var documentLibrary = companyhome.childByNamePath("sites/foo/documentLibrary");

var children = documentLibrary.children;

traverse(children);

function traverse(nodes){
  for each(var node in nodes) {
    if (node.isContainer){
      logger.log(node.name + " is a folder, traversing down");
      traverse(node.children);
    }else {
      logger.log(node.name + "is a document, modified: " +     node.properties["cm:modified"]); 
    }
  }
}
billerby
  • 1,977
  • 12
  • 22
0

It's quite simple actually. If you look in the code of the docsummary dashlet/js file (Recently Modified Dashlet), you'll see that it's firing:

slingshot/doclib/doclist/documents/site/" + Alfresco.constants.SITE + "/documentLibrary?max=50

So you only need is a list of sites available and good for you that there is a service for it listSites(nameFilter, sitePresetFilter) .

You can just use listSites(null, null), which will return all sites. So just loop through the sites and fire the webscript.

Tahir Malik
  • 6,623
  • 15
  • 22
  • I'll test this out, the problem I'm seeing with the recently modified dashlet is it only tracks files that have been modified through Share (uploads/offline editing). Anything that's been modified through WebDAV or Online Editing (SharePoint add-on) will not show up. To me this indicates that the method it uses won't work. That being said, it's definitely worth looking into since it does the work for me. I was considering using that to get the full list of folders and retrieve documents from them. – Ashex Jun 05 '13 at 16:05
  • 1
    Yeah but still, if you retrieve the documents from every folder from every site without using a search, that's a heavy operation. And because it's in a Dashlet it will be fired a lot!. So either go that path and code a Cache in it, so it only refreshes every x minutes. This all just needs a lot of work to do and the solutions I'm suggesting is easier to implement and maintain – Tahir Malik Jun 05 '13 at 16:52
  • I sat down and figured out the Search query, turned on debugging and captured the one used for site search. I've got a webscript that returns the request via search.query sorted and filtered as desired so now I just need to craft the atom template and I should be set. – Ashex Jun 06 '13 at 00:49