001
014
015 package com.liferay.portal.upgrade.v6_2_0;
016
017 import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portlet.PortletPreferencesFactoryUtil;
022 import com.liferay.util.RSSUtil;
023
024 import javax.portlet.PortletPreferences;
025
026
030 public class UpgradeMessageBoards extends BaseUpgradePortletPreferences {
031
032 @Override
033 protected void doUpgrade() throws Exception {
034 super.doUpgrade();
035 }
036
037 @Override
038 protected String[] getPortletIds() {
039 return new String[] {"19"};
040 }
041
042 @Override
043 protected String upgradePreferences(
044 long companyId, long ownerId, int ownerType, long plid,
045 String portletId, String xml)
046 throws Exception {
047
048 PortletPreferences portletPreferences =
049 PortletPreferencesFactoryUtil.fromXML(
050 companyId, ownerId, ownerType, plid, portletId, xml);
051
052 String rssFormat = GetterUtil.getString(
053 portletPreferences.getValue("rssFormat", null));
054
055 if (Validator.isNotNull(rssFormat)) {
056 String rssFeedType = RSSUtil.getFeedType(
057 RSSUtil.getFormatType(rssFormat),
058 RSSUtil.getFormatVersion(rssFormat));
059
060 portletPreferences.setValue("rssFeedType", rssFeedType);
061 }
062
063 portletPreferences.reset("rssFormat");
064
065 portletPreferences = upgradeSubscriptionSubject(
066 "emailMessageAddedSubject", "emailMessageAddedSubjectPrefix",
067 portletPreferences);
068
069 portletPreferences = upgradeSubscriptionSubject(
070 "emailMessageUpdatedSubject", "emailMessageUpdatedSubjectPrefix",
071 portletPreferences);
072
073 return PortletPreferencesFactoryUtil.toXML(portletPreferences);
074 }
075
076 protected PortletPreferences upgradeSubscriptionSubject(
077 String subjectName, String subjectPrefixName,
078 PortletPreferences portletPreferences)
079 throws Exception {
080
081 String subjectPrefix = GetterUtil.getString(
082 portletPreferences.getValue(subjectPrefixName, StringPool.BLANK));
083
084 if (Validator.isNotNull(subjectPrefix)) {
085 String subject = subjectPrefix;
086
087 if (!subjectPrefix.contains("[$MESSAGE_SUBJECT$]")) {
088 subject = subject.concat(" [$MESSAGE_SUBJECT$]");
089 }
090
091 portletPreferences.setValue(subjectName, subject);
092 }
093
094 portletPreferences.reset(subjectPrefixName);
095
096 return portletPreferences;
097 }
098
099 }