001
014
015 package com.liferay.portal.upgrade.v7_0_0;
016
017 import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.util.PortletKeys;
021 import com.liferay.portlet.PortletPreferencesFactoryUtil;
022
023 import javax.portlet.PortletPreferences;
024 import javax.portlet.ReadOnlyException;
025
026
029 public class UpgradeWiki extends BaseUpgradePortletPreferences {
030
031 protected String getEmailSignatureSeparator(
032 PortletPreferences portletPreferences) {
033
034 return StringPool.NEW_LINE;
035 }
036
037 @Override
038 protected String[] getPortletIds() {
039 return new String[] {PortletKeys.WIKI};
040 }
041
042 protected void upgradeEmailSignature(
043 PortletPreferences portletPreferences,
044 String emailMessageBodyPortletPreferencesKey,
045 String emailMessageSignaturePortletPreferencesKey)
046 throws ReadOnlyException {
047
048 String emailMessageSignature = portletPreferences.getValue(
049 emailMessageSignaturePortletPreferencesKey, StringPool.BLANK);
050
051 if (Validator.isNotNull(emailMessageSignature)) {
052 String emailMessageBody = portletPreferences.getValue(
053 emailMessageBodyPortletPreferencesKey, StringPool.BLANK);
054
055 String signatureSeparator = getEmailSignatureSeparator(
056 portletPreferences);
057
058 emailMessageBody += signatureSeparator + emailMessageSignature;
059
060 portletPreferences.setValue(
061 emailMessageBodyPortletPreferencesKey, emailMessageBody);
062 }
063
064 portletPreferences.reset(emailMessageSignaturePortletPreferencesKey);
065 }
066
067 @Override
068 protected String upgradePreferences(
069 long companyId, long ownerId, int ownerType, long plid,
070 String portletId, String xml)
071 throws Exception {
072
073 PortletPreferences portletPreferences =
074 PortletPreferencesFactoryUtil.fromXML(
075 companyId, ownerId, ownerType, plid, portletId, xml);
076
077 upgradeEmailSignature(
078 portletPreferences, "emailPageAddedBody",
079 "emailPageAddedSignature");
080 upgradeEmailSignature(
081 portletPreferences, "emailPageUpdatedBody",
082 "emailPageUpdatedSignature");
083
084 return PortletPreferencesFactoryUtil.toXML(portletPreferences);
085 }
086
087 }