diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.desc.xml
new file mode 100644
index 0000000000..02322a9080
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.desc.xml
@@ -0,0 +1,15 @@
+
+ Thumbnail to Rendition Service optional patch.
+
+ /renditions/patchthumbnailsasrenditions
+ argument
+ admin
+ required
+ internal
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.json.ftl
new file mode 100644
index 0000000000..0b71a02abe
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/rendition/patchthumbnailsasrenditions.get.json.ftl
@@ -0,0 +1,7 @@
+<#escape x as jsonUtils.encodeJSONString(x)>
+{
+ "data" : {
+ "thumbnailNodesPatched" : ${patchedNodeCount?string}
+ }
+}
+#escape>
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index 27025592e1..2030549449 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -435,6 +435,14 @@
+
+
+
+
+
+
+
diff --git a/source/java/org/alfresco/repo/web/scripts/rendition/patch/PatchThumbnailsAsRenditionsGet.java b/source/java/org/alfresco/repo/web/scripts/rendition/patch/PatchThumbnailsAsRenditionsGet.java
new file mode 100644
index 0000000000..c2b7adc876
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/rendition/patch/PatchThumbnailsAsRenditionsGet.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2005-2010 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.repo.web.scripts.rendition.patch;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.model.RenditionModel;
+import org.alfresco.service.cmr.rendition.RenditionService;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.cmr.repository.StoreRef;
+import org.alfresco.service.cmr.search.ResultSet;
+import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.namespace.QName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.extensions.webscripts.Cache;
+import org.springframework.extensions.webscripts.DeclarativeWebScript;
+import org.springframework.extensions.webscripts.Status;
+import org.springframework.extensions.webscripts.WebScriptRequest;
+
+public class PatchThumbnailsAsRenditionsGet extends DeclarativeWebScript
+{
+ /** Logger */
+ private static Log logger = LogFactory.getLog(PatchThumbnailsAsRenditionsGet.class);
+
+ private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
+
+ private static final String QUERY = "TYPE:\"" + ContentModel.TYPE_THUMBNAIL +
+ "\" AND NOT ASPECT:\"" + RenditionModel.ASPECT_VISIBLE_RENDITION +
+ "\" AND NOT ASPECT:\"" + RenditionModel.ASPECT_HIDDEN_RENDITION + "\"";
+
+ /** Spring-injected services */
+ private NodeService nodeService;
+ private RenditionService renditionService;
+ private SearchService searchService;
+
+ /**
+ * Sets the nodeService.
+ *
+ * @param nodeService
+ */
+ public void setNodeService(NodeService nodeService)
+ {
+ this.nodeService = nodeService;
+ }
+
+ /**
+ * Sets the renditionService.
+ *
+ * @param renditionService
+ */
+ public void setRenditionService(RenditionService renditionService)
+ {
+ this.renditionService = renditionService;
+ }
+
+ /**
+ * Sets the searchService.
+ *
+ * @param searchService
+ */
+ public void setSearchService(SearchService searchService)
+ {
+ this.searchService = searchService;
+ }
+
+ @Override
+ public Map executeImpl(WebScriptRequest req, Status status, Cache cache)
+ {
+ if (logger.isInfoEnabled())
+ {
+ logger.debug("Patching legacy thumbnails by applying appropriate rendition aspect");
+ }
+
+ ResultSet types = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, QUERY);
+
+ final List resultNodeRefs = types.getNodeRefs();
+ types.close();
+
+ long patchedNodeRefs = 0;
+
+ for (NodeRef nodeRef : resultNodeRefs)
+ {
+ if (nodeService.exists(nodeRef) == false ||
+ renditionService.isRendition(nodeRef))
+ {
+ continue;
+ }
+
+ // Now add one of the two aspects depending on parent location.
+ ChildAssociationRef sourceNode = renditionService.getSourceNode(nodeRef);
+ ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
+ QName aspectToApply;
+ if (primaryParent.getParentRef().equals(sourceNode.getParentRef()))
+ {
+ aspectToApply = RenditionModel.ASPECT_HIDDEN_RENDITION;
+ }
+ else
+ {
+ aspectToApply = RenditionModel.ASPECT_VISIBLE_RENDITION;
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ StringBuilder msg = new StringBuilder();
+ msg.append("Applying aspect ")
+ .append(aspectToApply)
+ .append(" to node ")
+ .append(nodeRef);
+ logger.debug(msg.toString());
+ }
+ nodeService.addAspect(nodeRef, aspectToApply, null);
+ patchedNodeRefs++;
+ }
+
+ Map model = new HashMap();
+ model.put("patchedNodeCount", new Long(patchedNodeRefs));
+
+ return model;
+ }
+}
\ No newline at end of file