diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 03b90dd00c..4904d81e29 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -41,3 +41,5 @@ patch.spacesRootPermission.result=Updated Spaces store root permission from 'Con patch.contentPermission.description=Update permission entries from 'cm:content' to 'sys:base'. patch.contentPermission.result=Created the following permission reference names: {0}. \nUpdated {1} permission entries. +patch.forumsIcons.description=Updates forums icon references +patch.forumsIcons.result=Updated {0} icon references \ No newline at end of file diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 5046000bc5..8587332e51 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -280,5 +280,21 @@ + + patch.forumsIcons + patch.forumsIcons.description + 0 + 7 + 8 + + + + + + + + + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 1b9f946e75..fff64d2a1a 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -15,4 +15,4 @@ version.edition=Community Network # Schema number -version.schema=7 +version.schema=8 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/ForumsIconsPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/ForumsIconsPatch.java new file mode 100644 index 0000000000..0c380bd789 --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/ForumsIconsPatch.java @@ -0,0 +1,97 @@ +package org.alfresco.repo.admin.patch.impl; + +import java.io.Serializable; + +import org.alfresco.i18n.I18NUtil; +import org.alfresco.model.ContentModel; +import org.alfresco.model.ForumModel; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.importer.ImporterBootstrap; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.namespace.QName; + +/** + * Patch to remove the '_large' from the icon property for all the forums + * based space types i.e. fm:forums, fm:forum and fm:topic. + * + * @author gavinc + */ +public class ForumsIconsPatch extends AbstractPatch +{ + private static final String MSG_SUCCESS = "patch.forumsIcons.result"; + + private ImporterBootstrap importerBootstrap; + private NodeService nodeService; + private SearchService searchService; + + public void setImporterBootstrap(ImporterBootstrap importerBootstrap) + { + this.importerBootstrap = importerBootstrap; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + + @Override + protected String applyInternal() throws Exception + { + int iconsChanged = 0; + + // change all the fm:forums nodes + iconsChanged += changeIcons(ForumModel.TYPE_FORUMS); + + // change all the fm:forum nodes + iconsChanged += changeIcons(ForumModel.TYPE_FORUM); + + // change all the topic nodes + iconsChanged += changeIcons(ForumModel.TYPE_TOPIC); + + // return success message + return I18NUtil.getMessage(MSG_SUCCESS, new Object[] {iconsChanged}); + } + + /** + * Removes the '_large' from the icon property for the nodes of the given type + * + * @param typeName The qname of the type to change the icon property for + * @return Returns the number of icons changed + */ + private int changeIcons(QName typeName) + { + int changed = 0; + String query = "TYPE:\"" + typeName.toString() + "\""; + ResultSet results = this.searchService.query(this.importerBootstrap.getStoreRef(), + SearchService.LANGUAGE_LUCENE, query); + + // if there are any results iterate through nodes and update icon property + if (results.length() > 0) + { + for (NodeRef node : results.getNodeRefs()) + { + String icon = (String)this.nodeService.getProperty(node, ContentModel.PROP_ICON); + if (icon != null && icon.length() > 0) + { + int idx = icon.indexOf("_large"); + if (idx != -1) + { + String newIcon = icon.substring(0, idx); + this.nodeService.setProperty(node, ContentModel.PROP_ICON, (Serializable)newIcon); + changed++; + } + } + } + } + + return changed; + } +}