Changed forums icons to use browse bean's small icon resolver and required patch

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2513 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-03-02 22:33:32 +00:00
parent af536825b8
commit e667abaac6
4 changed files with 116 additions and 1 deletions

View File

@@ -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

View File

@@ -280,5 +280,21 @@
</list>
</property>
</bean>
<bean id="patch.updateForumsIcons" class="org.alfresco.repo.admin.patch.impl.ForumsIconsPatch" parent="basePatch" >
<property name="id"><value>patch.forumsIcons</value></property>
<property name="description"><value>patch.forumsIcons.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>7</value></property>
<property name="targetSchema"><value>8</value></property>
<property name="importerBootstrap">
<ref bean="spacesBootstrap" />
</property>
<property name="nodeService">
<ref bean="nodeService"/>
</property>
<property name="searchService">
<ref bean="searchService" />
</property>
</bean>
</beans>

View File

@@ -15,4 +15,4 @@ version.edition=Community Network
# Schema number
version.schema=7
version.schema=8

View File

@@ -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;
}
}