View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.setup;
35  
36  import info.magnolia.cms.beans.config.ContentRepository;
37  import info.magnolia.cms.core.ItemType;
38  import info.magnolia.module.AbstractModuleVersionHandler;
39  import info.magnolia.module.InstallContext;
40  import info.magnolia.module.delta.AddMimeMappingTask;
41  import info.magnolia.module.delta.ArrayDelegateTask;
42  import info.magnolia.module.delta.BootstrapConditionally;
43  import info.magnolia.module.delta.BootstrapSingleResource;
44  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
45  import info.magnolia.module.delta.Condition;
46  import info.magnolia.module.delta.CreateNodeTask;
47  import info.magnolia.module.delta.DeltaBuilder;
48  import info.magnolia.module.delta.FilterOrderingTask;
49  import info.magnolia.module.delta.MoveNodeTask;
50  import info.magnolia.module.delta.NewPropertyTask;
51  import info.magnolia.module.delta.NodeExistsDelegateTask;
52  import info.magnolia.module.delta.PropertyExistsDelegateTask;
53  import info.magnolia.module.delta.PropertyValueDelegateTask;
54  import info.magnolia.module.delta.Task;
55  import info.magnolia.module.delta.WarnTask;
56  import info.magnolia.module.delta.WebXmlConditionsUtil;
57  import info.magnolia.module.delta.WorkspaceXmlConditionsUtil;
58  import info.magnolia.setup.for3_5.GenericTasks;
59  import info.magnolia.setup.for3_6.CheckMagnoliaDevelopProperty;
60  import info.magnolia.setup.for3_6.CheckNodeTypesDefinition;
61  import info.magnolia.setup.for3_6.CheckNodesForMixVersionable;
62  import info.magnolia.setup.for3_6_2.UpdateGroups;
63  import info.magnolia.setup.for3_6_2.UpdateRoles;
64  import info.magnolia.setup.for3_6_2.UpdateUsers;
65  import info.magnolia.setup.for4_3.UpdateUserPermissions;
66  
67  import java.util.ArrayList;
68  import java.util.List;
69  
70  /**
71   * 3.5 being the first version of core as a module, it is always "installed",
72   * but we need it to behave differently if magnolia was installed previously
73   * (ie. updating from 3.0), which is why there are so many "conditional
74   * tasks". Once 3.5 is out the door, this will need to be revised
75   * completely.
76   *
77   * @author gjoseph
78   * @version $Revision: $ ($Author: $)
79   */
80  public class CoreModuleVersionHandler extends AbstractModuleVersionHandler {
81      public static final String BOOTSTRAP_AUTHOR_INSTANCE_PROPERTY = "magnolia.bootstrap.authorInstance";
82  
83      // TODO : why is this a BootstrapConditionally and not a BootstrapSingleResource ?
84      private final BootstrapConditionally auditTrailManagerTask = new BootstrapConditionally("New auditory log configuration", "Install new configuration for auditory log manager.", "/mgnl-bootstrap/core/config.server.auditLogging.xml");
85      private final BootstrapSingleResource bootstrapFreemarker = new BootstrapSingleResource("Freemarker configuration", "Freemarker template loaders can now be configured in Magnolia. Adds default configuration", "/mgnl-bootstrap/core/config.server.rendering.freemarker.xml");
86      private final CreateNodeTask addFreemarkerSharedVariables = new CreateNodeTask("Freemarker configuration", "Adds sharedVariables node to the Freemarker configuration",
87              ContentRepository.CONFIG, "/server/rendering/freemarker", "sharedVariables", ItemType.CONTENTNODE.getSystemName());
88  
89      public CoreModuleVersionHandler() {
90          super();
91  
92          register(DeltaBuilder.update("3.5", "")
93                  .addTasks(GenericTasks.genericTasksFor35())
94          );
95  
96          register(DeltaBuilder.update("3.6", "")
97                  .addCondition(new CheckNodeTypesDefinition())
98                  .addTask(new CheckMagnoliaDevelopProperty())
99                  .addTask(new CheckNodesForMixVersionable())
100         );
101 
102         final CheckAndModifyPropertyValueTask log4jServletMapping = new CheckAndModifyPropertyValueTask("Mapping for log4j configuration servlet", "Fixes the mapping for the log4j configuration servlet, making it specification compliant.",
103                 ContentRepository.CONFIG,
104                 "/server/filters/servlets/log4j/mappings/--magnolia-log4j-",
105                 "pattern", "/.magnolia/log4j*", "/.magnolia/log4j"
106         );
107 
108         register(DeltaBuilder.update("3.6.2", "")
109                 .addTask(new UpdateUsers())
110                 .addTask(new UpdateRoles())
111                 .addTask(new UpdateGroups())
112                 .addTask(log4jServletMapping)
113         );
114 
115         register(DeltaBuilder.update("3.6.4", "")
116                 .addTask(new AddMimeMappingTask("flv", "video/x-flv", "/.resources/file-icons/flv.png"))
117                 .addTask(new AddMimeMappingTask("svg", "image/svg+xml", "/.resources/file-icons/svg.png"))
118                 .addTask(new CheckAndModifyPropertyValueTask("PNG MIME mapping", "Checks and updates PNG MIME mapping if not correct.", ContentRepository.CONFIG, "/server/MIMEMapping/png", "mime-type", "application/octet-stream", "image/png"))
119                 .addTask(new CheckAndModifyPropertyValueTask("SWF MIME mapping", "Checks and updates SWF MIME mapping if not correct.", ContentRepository.CONFIG, "/server/MIMEMapping/swf", "mime-type", "application/octet-stream", "application/x-shockwave-flash"))
120         );
121 
122         register(DeltaBuilder.update("3.6.7", "")
123                 // since these mimetypes were correct with the 3.6.4 release, but with wrong values, and this
124                 // has only been recognized after 4.0.1 and 4.1 were released, we need to apply the same
125                 // fix tasks for 3.6.7, 4.0.2 and 4.1.1
126                 .addTask(fixMimetype("png", "image/png;", "image/png"))
127                 .addTask(fixMimetype("swf", "application/x-shockwave-flash;", "application/x-shockwave-flash"))
128         );
129 
130         final Task updateLinkResolverClass = new CheckAndModifyPropertyValueTask("Link rendering", "Updates the link rendering implementation class.", ContentRepository.CONFIG, "/server/rendering/linkResolver", "class", "info.magnolia.cms.link.LinkResolverImpl", "info.magnolia.link.LinkTransformerManager");
131         final Task renameLinkResolver = new MoveNodeTask("Link management configuration", "Updates the link management configuration.", ContentRepository.CONFIG, "/server/rendering/linkResolver", "/server/rendering/linkManagement", true);
132         register(DeltaBuilder.update("4.0", "")
133                 .addTask(auditTrailManagerTask)
134                 .addTask(bootstrapFreemarker)
135                 .addTask(updateLinkResolverClass)
136                 .addTask(renameLinkResolver)
137                 .addTask(new ChangeNodeTypesInUserWorkspace())
138         );
139 
140         register(DeltaBuilder.update("4.0.2", "")
141                 // the two tasks below - updateUsers and CAMPVT(Fix anonymous permissions) are also executed for 3.6.6 set on 3.6 branch. This is due to fact that tasks needed to be applied on 3.6 branch after 4.0 release already. Tasks are safe to be executed multiple times.
142                 .addTask(new UpdateUsers())
143                 .addTask(new CheckAndModifyPropertyValueTask("Fix for anonymous user permissions", "Fix previously incorrect path for anonymous user permissions.", ContentRepository.USERS, "/system/anonymous/acl_users/0", "path", "/anonymous/*", "/system/anonymous/*"))
144 
145                 // warning - if adding update tasks for the 4.0.2 release below this point,
146                 // make sure they'd also be applied correctly for the 4.1 branch in the various possible update scenarios
147                 // since 4.1 will be released before 4.0.2 (4.0.2 -> 4.1 -> 4.1.1; 4.0.1 -> 4.1 -> 4.1.1)
148         );
149 
150         register(DeltaBuilder.update("4.0.3", "")
151 
152                 // since these mimetypes were correct with the 3.6.4 release, but with wrong values, and this
153                 // has only been recognized after 4.0.1 and 4.1 were released, we need to apply the same
154                 // fix tasks for 3.6.7, 4.0.3 and 4.1.1
155                 .addTask(fixMimetype("png", "image/png;", "image/png"))
156                 .addTask(fixMimetype("swf", "application/x-shockwave-flash;", "application/x-shockwave-flash"))
157         );
158 
159         register(DeltaBuilder.update("4.1.1", "")
160                 // since these mimetypes were correct with the 3.6.4 release, but with wrong values, and this
161                 // has only been recognized after 4.0.1 and 4.1 were released, we need to apply the same
162                 // fix tasks for 3.6.7, 4.0.2 and 4.1.1
163                 .addTask(fixMimetype("png", "image/png;", "image/png"))
164                 .addTask(fixMimetype("swf", "application/x-shockwave-flash;", "application/x-shockwave-flash"))
165         );
166 
167         register(DeltaBuilder.update("4.3", "")
168                 .addTask(addFreemarkerSharedVariables)
169                 .addTask(
170                 new ArrayDelegateTask("New unicode normalization filter", "Add the new unicode normalization filter.",
171                         new BootstrapSingleResource("Unicode Normalization filter ", "Add new Unicode Normalization filter.", "/mgnl-bootstrap/core/config.server.filters.unicodeNormalization.xml"),
172                         new FilterOrderingTask("multipartRequest", "New filter ordering : context, contentType, multipart, unicodeNormalization, login.", new String[]{"contentType"}),
173                         new FilterOrderingTask("unicodeNormalization", "New filter ordering : context, contentType, multipart, unicodeNormalization, login.", new String[]{"multipartRequest"})
174                 ))
175                 .addTask(new UpdateUserPermissions())
176         );
177         
178         register(DeltaBuilder.update("4.3.6", "")
179                 .addTask(new NodeExistsDelegateTask("TemplateExceptionHandler", "Checks if templateExceptionHandler node exists", ContentRepository.CONFIG, "/server/rendering/freemarker/templateExceptionHandler", new WarnTask("TemplateExceptionHandler", "Unable to set node templateExceptionHandler because it already exists"), new CreateNodeTask("TemplateExceptionHandler", "Creates node templateExceptionHandler", ContentRepository.CONFIG, "/server/rendering/freemarker", "templateExceptionHandler", ItemType.CONTENTNODE.getSystemName())))
180                 .addTask(new PropertyExistsDelegateTask("Class", "Checks if class property exists", ContentRepository.CONFIG, "/server/rendering/freemarker/templateExceptionHandler", "class", new WarnTask("class","Unable to set property class because it already exists"),  new NewPropertyTask("Class", "Creates property class and sets it to class path", ContentRepository.CONFIG, "/server/rendering/freemarker/templateExceptionHandler", "class", "info.magnolia.freemarker.ModeDependentTemplateExceptionHandler"))));
181     }
182 
183     private PropertyValueDelegateTask fixMimetype(String mimeType, final String previouslyWrongValue, final String fixedValue) {
184         final String workspaceName = ContentRepository.CONFIG;
185         final String nodePath = "/server/MIMEMapping/" + mimeType;
186         final CheckAndModifyPropertyValueTask fixTask = new CheckAndModifyPropertyValueTask(null, null, workspaceName, nodePath,
187                 "mime-type", previouslyWrongValue, fixedValue);
188 
189         return new PropertyValueDelegateTask(mimeType.toUpperCase() + " MIME mapping",
190                 "Checks and updates " + mimeType.toUpperCase() + "MIME mapping if not correct.",
191                 workspaceName, nodePath, "mime-type", previouslyWrongValue, false, fixTask);
192     }
193 
194     protected List<Task> getBasicInstallTasks(InstallContext ctx) {
195         final List<Task> l = new ArrayList<Task>();
196         l.addAll(GenericTasks.genericTasksFor35());
197         l.add(new CheckMagnoliaDevelopProperty());
198         l.add(new CheckNodesForMixVersionable());
199         l.add(auditTrailManagerTask);
200         l.add(bootstrapFreemarker);
201         l.add(addFreemarkerSharedVariables);
202         return l;
203     }
204 
205     protected List<Condition> getInstallConditions() {
206         final ArrayList<Condition> conditions = new ArrayList<Condition>();
207         final WebXmlConditionsUtil u = new WebXmlConditionsUtil(conditions);
208         u.servletIsNowWrapped("ActivationHandler");
209         u.servletIsNowWrapped("AdminTreeServlet");
210         u.servletIsNowWrapped("classpathspool");
211         u.servletIsNowWrapped("DialogServlet");
212         u.servletIsNowWrapped("PageServlet");
213         u.servletIsNowWrapped("log4j");
214         u.servletIsNowWrapped("FCKEditorSimpleUploadServlet");
215         u.servletIsDeprecated("uuidRequestDispatcher");
216         u.filterIsDeprecated("info.magnolia.cms.filters.MagnoliaManagedFilter", "info.magnolia.cms.filters.MgnlMainFilter");
217         u.filterMustBeRegisteredWithCorrectDispatchers("info.magnolia.cms.filters.MgnlMainFilter");
218         u.listenerIsDeprecated("info.magnolia.cms.servlets.PropertyInitializer", "info.magnolia.cms.servlets.MgnlServletContextListener");
219         u.listenerIsDeprecated("info.magnolia.cms.beans.config.ShutdownManager", "info.magnolia.cms.servlets.MgnlServletContextListener");
220         final WorkspaceXmlConditionsUtil u2 = new WorkspaceXmlConditionsUtil(conditions);
221         u2.workspaceHasOldIndexer();
222 
223         conditions.add(new CheckNodeTypesDefinition());
224         return conditions;
225     }
226 }