View Javadoc

1   /**
2    * This file Copyright (c) 2013-2014 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.pages.setup;
35  
36  import static info.magnolia.nodebuilder.Ops.*;
37  
38  import info.magnolia.i18nsystem.setup.RemoveHardcodedI18nPropertiesFromDialogsTask;
39  import info.magnolia.i18nsystem.setup.RemoveHardcodedI18nPropertiesFromSubappsTask;
40  import info.magnolia.jcr.util.NodeTypes;
41  import info.magnolia.module.DefaultModuleVersionHandler;
42  import info.magnolia.module.InstallContext;
43  import info.magnolia.module.delta.ArrayDelegateTask;
44  import info.magnolia.module.delta.BootstrapConditionally;
45  import info.magnolia.module.delta.DeltaBuilder;
46  import info.magnolia.module.delta.IsModuleInstalledOrRegistered;
47  import info.magnolia.module.delta.NewPropertyTask;
48  import info.magnolia.module.delta.NodeExistsDelegateTask;
49  import info.magnolia.module.delta.OrderNodeAfterTask;
50  import info.magnolia.module.delta.PartialBootstrapTask;
51  import info.magnolia.module.delta.PropertyExistsDelegateTask;
52  import info.magnolia.module.delta.RemoveNodeTask;
53  import info.magnolia.module.delta.RemovePropertyTask;
54  import info.magnolia.module.delta.RenameNodesTask;
55  import info.magnolia.module.delta.SetPropertyTask;
56  import info.magnolia.module.delta.Task;
57  import info.magnolia.nodebuilder.task.ErrorHandling;
58  import info.magnolia.nodebuilder.task.NodeBuilderTask;
59  import info.magnolia.repository.RepositoryConstants;
60  import info.magnolia.ui.admincentral.setup.ConvertAclToAppPermissionTask;
61  import info.magnolia.ui.contentapp.ConfiguredContentAppDescriptor;
62  import info.magnolia.ui.contentapp.availability.IsNotVersionedDetailLocationRule;
63  import info.magnolia.ui.contentapp.browser.action.ShowVersionsActionDefinition;
64  import info.magnolia.ui.framework.setup.SetWritePermissionForActionsTask;
65  
66  import java.util.ArrayList;
67  import java.util.List;
68  
69  /**
70   * Version handler for the pages app module.
71   */
72  public class PagesModuleVersionHandler extends DefaultModuleVersionHandler {
73  
74      public static final String PAGES_APP_ACTIONS = "/modules/pages/apps/pages/subApps/browser/actions/";
75  
76      public PagesModuleVersionHandler() {
77          super();
78  
79          register(DeltaBuilder.update("5.0", "Configuration update for Magnolia 5.0")
80                  .addTask(new IsModuleInstalledOrRegistered("", "", "adminInterface",
81                          new BootstrapConditionally("Bootstrap activation commands", "Bootstraps the default activation and deletion commands which no longer reside under adminInterface.", "config.modules.pages.commands.xml")))
82                  .addTask(new ConvertAclToAppPermissionTask("Convert permissions for Pages app", "Convert ACL permissions for old 'Website' menu to new 'pages-app' permission", "/modules/adminInterface/config/menu/website", "/modules/pages/apps/pages", true)));
83  
84  
85          register(DeltaBuilder.update("5.0.1", "")
86                  .addTask(new NodeExistsDelegateTask("Remove dialog links Node", "Remove dialog definition in pages/dialogs/links", RepositoryConstants.CONFIG, "/modules/pages/dialogs/link",
87                          new RemoveNodeTask("Remove dialog links Node", "Remove dialog definition in pages/dialogs/links", RepositoryConstants.CONFIG, "/modules/pages/dialogs/link")))
88                  .addTask(new NodeExistsDelegateTask("Add title to CreatePage dialog", "", RepositoryConstants.CONFIG, "/modules/pages/dialogs/createPage/form",
89                          new NewPropertyTask("Add title to CreatePage dialog", "", RepositoryConstants.CONFIG, "/modules/pages/dialogs/createPage/form", "label", "pages.dialog.add_page"))));
90  
91          register(DeltaBuilder.update("5.0.2", "")
92                  // new action for confirmation
93                  .addTask(new PartialBootstrapTask("Add new confirmation action definition", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actions/confirmDeletion"))
94  
95                  .addTask(new NodeExistsDelegateTask("Remove action availability from delete action", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete/availability",
96                          new RemoveNodeTask("", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete/availability")))
97                  .addTask(new PropertyExistsDelegateTask("Remove label for delete action", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "label",
98                          new RemovePropertyTask("", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "label")))
99                  .addTask(new PropertyExistsDelegateTask("Remove icon for delete action", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "icon",
100                         new RemovePropertyTask("", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "icon")))
101 
102                 // update actionbar for confirmation
103                 .addTask(new NodeExistsDelegateTask("Update actionbar configuration", "Rename action mapping to new confirmation action", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar",
104                         new RenameNodesTask("Rename action bar items", "Rename delete to confirmDeletion", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar", "delete", "confirmDeletion", NodeTypes.ContentNode.NAME))));
105 
106         register(DeltaBuilder.update("5.1", "")
107                 .addTask(new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "confirmDeletion",
108                         new NewPropertyTask("", "", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "confirmDeletion/availability", "multiple", true)))
109 
110                 // add show versions action
111                 // if module diff is installed, this task will create a second node showVersions
112                 // we'll handle the renaming of the correct node in module diff
113                 .addTask(new NodeBuilderTask("Create showVersions action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, PAGES_APP_ACTIONS,
114                         addNode("showVersions", NodeTypes.ContentNode.NAME).then(
115                                 addProperty("class", ShowVersionsActionDefinition.class.getName()),
116                                 addProperty("icon", "icon-show-versions"),
117                                 addNode("availability", NodeTypes.ContentNode.NAME).then(
118                                         addProperty("ruleClass", "info.magnolia.ui.api.availability.HasVersionsRule")
119                                 )
120                         )
121                 ))
122                 // bootstrap versionActions to action bar if it doesn't exists already
123                 .addTask(new NodeExistsDelegateTask("Bootstrap actionbar section group for versionActions", "", RepositoryConstants.CONFIG, "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions", null,
124                         new PartialBootstrapTask("", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions")
125                 ))
126 
127                 // Remove hardcoded i18n properties, e.g. label, description, etc.
128                 .addTask(new RemoveHardcodedI18nPropertiesFromSubappsTask("pages"))
129 
130                 // cleanup pages commands
131                 .addTask(new NodeExistsDelegateTask("remove the activate command chain from pages app", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/activate",
132                         new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/activate")))
133                 .addTask(new NodeExistsDelegateTask("remove the deactivate command chain from pages app", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/deactivate",
134                         new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/deactivate")))
135 
136                 .addTask(new PartialBootstrapTask("Bootstrap new activate commands to website catalog.", "", "/mgnl-bootstrap/pages/config.modules.pages.commands.xml", "/commands/website/activate"))
137                 .addTask(new PartialBootstrapTask("Bootstrap new deactivate commands to website catalog.", "", "/mgnl-bootstrap/pages/config.modules.pages.commands.xml", "/commands/website/deactivate"))
138 
139                 // Add availability rules to detail view actions
140                 .addTask(new NodeBuilderTask("Add availability rule to edit action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/edit",
141                         addNode("availability", NodeTypes.ContentNode.NAME).then(
142                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
143                         )
144                 ))
145                 .addTask(new NodeBuilderTask("Add availability rule to activate action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/activate",
146                         addNode("availability", NodeTypes.ContentNode.NAME).then(
147                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
148                         )
149                 ))
150                 .addTask(new NodeBuilderTask("Add availability rule to deactivate action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/deactivate",
151                         addNode("availability", NodeTypes.ContentNode.NAME).then(
152                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
153                         )
154                 ))
155 
156                 .addTask(new PartialBootstrapTask("Bootstrap move action in Pages app", "",
157                         "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actions/move"))
158                 .addTask(new PartialBootstrapTask("Bootstrap move action to Pages app actionbar", "Adds action move to folder/editingActions section in actionbar.",
159                         "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/editingActions/items/move"))
160         );
161 
162         register(DeltaBuilder.update("5.1.1", "")
163                 .addTask(new NodeExistsDelegateTask("Add root availability to import", "Add root availability to import action in Pages app", RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "import/availability",
164                         new NewPropertyTask("Add root availability to import", "Add root availability to import action in Pages app", RepositoryConstants.CONFIG,
165                                 PAGES_APP_ACTIONS + "import/availability", "root", true))));
166 
167         register(DeltaBuilder.update("5.2.2", "")
168                 .addTask(new RemoveHardcodedI18nPropertiesFromDialogsTask("pages"))
169                 .addTask(new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages", "class", ConfiguredContentAppDescriptor.class.getName()))
170                 .addTask(new SetPropertyTask(RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "import/availability", "root", "true"))
171                 .addTask(new PartialBootstrapTask("Bootstrap restore version action", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "pages/subApps/browser/actions/restoreVersion"))
172                 .addTask(new NodeExistsDelegateTask("Bootstrap restore version action to actionbar", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items",
173                         new ArrayDelegateTask("",
174                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/restoreVersion"),
175                                 new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/showVersions",
176                                     new OrderNodeAfterTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/restoreVersion", "showVersions")))))
177         );
178 
179         register(DeltaBuilder.update("5.2.3", "")
180                 .addTask(new SetWritePermissionForActionsTask(PAGES_APP_ACTIONS,
181                         new String[] { "add", "confirmDeletion", "edit", "editPageName", "editTemplate", "restorePreviousVersion", "import", "move", "restoreVersion" }))
182                 .addTask(new SetWritePermissionForActionsTask("/modules/pages/apps/pages/subApps/detail/actions", new String[] { "edit" }))
183         );
184         register(DeltaBuilder.update("5.2.5", "")
185                 .addTask(new IsModuleInstalledOrRegistered("Configure recursive activation and deletion as asynchronous", "scheduler", new ArrayDelegateTask("",
186                         new NodeExistsDelegateTask("Configure recursive activation as asynchronous", PAGES_APP_ACTIONS + "activateRecursive",
187                                 new SetPropertyTask(RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "activateRecursive", "asynchronous", "true")),
188                         new NodeExistsDelegateTask("Configure deletion as asynchronous", PAGES_APP_ACTIONS + "delete",
189                                 new SetPropertyTask(RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "asynchronous", "true"))
190                 ))));
191 
192         register(DeltaBuilder.update("5.2.7", "")
193                 .addTask(new SetWritePermissionForActionsTask(PAGES_APP_ACTIONS, new String [] { "activate", "activateRecursive", "deactivate", "activateDeletion" }))
194         );
195     }
196 
197     @Override
198     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
199         List<Task> tasks = new ArrayList<Task>();
200         tasks.addAll(super.getExtraInstallTasks(installContext));
201         tasks.add(new IsModuleInstalledOrRegistered("Configure recursive activation and deletion as asynchronous", "scheduler", new ArrayDelegateTask("",
202                 new NodeExistsDelegateTask("Configure recursive activation as asynchronous", PAGES_APP_ACTIONS + "activateRecursive",
203                         new SetPropertyTask(RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "activateRecursive", "asynchronous", "true")),
204                 new NodeExistsDelegateTask("Configure deletion as asynchronous", PAGES_APP_ACTIONS + "delete",
205                         new SetPropertyTask(RepositoryConstants.CONFIG, PAGES_APP_ACTIONS + "delete", "asynchronous", "true"))
206         )));
207         return tasks;
208     }
209 }