Skip to content

Commit dff8227

Browse files
Neehakethidsilvam
andauthored
Issue 33063 remove content types legacy (dotCMS#33208)
### Proposed Changes * Get rid of Content types legacy from available tools ### Screenshots Original | Updated :-------------------------:|:-------------------------: ** <img width="1604" height="959" alt="Screenshot 2025-09-05 at 3 46 32 PM" src="https://github.com/user-attachments/assets/d84f846f-3d78-44a7-bb09-83890d8ca0b7" /> ** | ** <img width="1591" height="950" alt="Screenshot 2025-09-05 at 3 46 11 PM" src="https://github.com/user-attachments/assets/26e62e89-95be-4d3f-b9dd-e46871ce0682" /> ** This PR fixes: dotCMS#33063 --------- Co-authored-by: Daniel Silva <[email protected]>
1 parent 3babaf0 commit dff8227

File tree

4 files changed

+268
-1
lines changed

4 files changed

+268
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.dotmarketing.startup.runonce;
2+
3+
import com.dotmarketing.business.CacheLocator;
4+
import com.dotmarketing.common.db.DotConnect;
5+
import com.dotmarketing.exception.DotDataException;
6+
import com.dotmarketing.exception.DotRuntimeException;
7+
import com.dotmarketing.startup.StartupTask;
8+
import io.vavr.control.Try;
9+
10+
/**
11+
* Removes the legacy content-types portlet from all layouts to prevent
12+
* Portlet Exception Error when users try to search using the legacy tool.
13+
* The new content-types-angular portlet should be used instead.
14+
* @author Neeha kethi
15+
*/
16+
public class Task251029RemoveContentTypesLegacyPortletFromLayouts implements StartupTask {
17+
18+
@Override
19+
public boolean forceRun() {
20+
return Try.of(() -> new DotConnect()
21+
.setSQL("select count(portlet_id) as count from cms_layouts_portlets where portlet_id = 'content-types'")
22+
.getInt("count")).getOrElse(0) > 0;
23+
}
24+
25+
@Override
26+
public void executeUpgrade() throws DotDataException, DotRuntimeException {
27+
new DotConnect()
28+
.setSQL("delete from cms_layouts_portlets where portlet_id = 'content-types'")
29+
.loadResult();
30+
31+
CacheLocator.getLayoutCache().clearCache();
32+
}
33+
}

dotCMS/src/main/java/com/dotmarketing/util/TaskLocatorUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
import com.dotmarketing.startup.runonce.Task250603UpdateIdentifierParentPathCheckTrigger;
257257
import com.dotmarketing.startup.runonce.Task250604UpdateFolderInodes;
258258
import com.dotmarketing.startup.runonce.Task250826AddIndexesToUniqueFieldsTable;
259+
import com.dotmarketing.startup.runonce.Task251029RemoveContentTypesLegacyPortletFromLayouts;
259260
import com.dotmarketing.startup.runonce.Task250828CreateCustomAttributeTable;
260261
import com.dotmarketing.startup.runonce.Task250910AddAnalyticsDashboardPortletToMenu;
261262
import com.google.common.collect.ImmutableList;
@@ -589,6 +590,7 @@ public static List<Class<?>> getStartupRunOnceTaskClasses() {
589590
.add(Task250604UpdateFolderInodes.class)
590591
.add(Task250826AddIndexesToUniqueFieldsTable.class)
591592
.add(Task250828CreateCustomAttributeTable.class)
593+
.add(Task251029RemoveContentTypesLegacyPortletFromLayouts.class)
592594
.build();
593595

594596
return ret.stream().sorted(classNameComparator).collect(Collectors.toList());

dotCMS/src/main/resources/portal.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ system.roles=LDAP User,Scripting User,CMS Owner,CMS Anonymous,CMS Administrator,
525525
# Input a list of comma delimited portlet ids that can be added by the user
526526
# to layouts and have them available through the navigation.
527527
#
528-
portlets.excluded.from.layout=my-account,EXT_2,folders, director,events,web-forms,events-approval,EXT_WEBEVENTS,web-event-registrations, files-legacy, legacy-page-views, html-pages
528+
portlets.excluded.from.layout=my-account,EXT_2,folders, director,events,web-forms,events-approval,EXT_WEBEVENTS,web-event-registrations, files-legacy, legacy-page-views, html-pages, content-types
529529

530530
#
531531
# Specify the Struts character encoding. UTF-8 allows for the use of more
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
package com.dotmarketing.startup.runonce;
2+
3+
import com.dotmarketing.common.db.DotConnect;
4+
import com.dotmarketing.exception.DotDataException;
5+
import com.dotcms.util.IntegrationTestInitService;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import static org.junit.Assert.*;
10+
11+
/**
12+
* Integration test for Task251029RemoveContentTypesLegacyPortletFromLayouts
13+
* Tests that the startup task properly removes legacy content-types portlet from layouts.
14+
*
15+
* @author Neeha Kethi
16+
*/
17+
public class Task251029RemoveContentTypesLegacyPortletFromLayoutsTest {
18+
19+
@BeforeClass
20+
public static void prepare() throws Exception {
21+
// Initialize the H2 DB
22+
IntegrationTestInitService.getInstance().init();
23+
}
24+
25+
/**
26+
* Test the forceRun method - should return true when legacy portlets exist
27+
*/
28+
@Test
29+
public void test_forceRun_should_return_true_when_legacy_portlets_exist() throws DotDataException {
30+
// Setup: Insert a test legacy portlet entry
31+
new DotConnect()
32+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
33+
.addParam("test-legacy-id-1")
34+
.addParam("test-layout-id")
35+
.addParam("content-types")
36+
.addParam(1)
37+
.loadResult();
38+
39+
try {
40+
// Test: forceRun should return true when legacy portlets exist
41+
Task251029RemoveContentTypesLegacyPortletFromLayouts task = new Task251029RemoveContentTypesLegacyPortletFromLayouts();
42+
assertTrue("forceRun should return true when content-types portlets exist in layouts",
43+
task.forceRun());
44+
} finally {
45+
// Cleanup: Remove test data
46+
new DotConnect()
47+
.setSQL("DELETE FROM cms_layouts_portlets WHERE id = ?")
48+
.addParam("test-legacy-id-1")
49+
.loadResult();
50+
}
51+
}
52+
53+
/**
54+
* Test the forceRun method - should return false when no legacy portlets exist
55+
*/
56+
@Test
57+
public void test_forceRun_should_return_false_when_no_legacy_portlets_exist() throws DotDataException {
58+
// Ensure no legacy portlets exist
59+
new DotConnect()
60+
.setSQL("DELETE FROM cms_layouts_portlets WHERE portlet_id = ?")
61+
.addParam("content-types")
62+
.loadResult();
63+
64+
// Test: forceRun should return false when no legacy portlets exist
65+
Task251029RemoveContentTypesLegacyPortletFromLayouts task = new Task251029RemoveContentTypesLegacyPortletFromLayouts();
66+
assertFalse("forceRun should return false when no content-types portlets exist in layouts",
67+
task.forceRun());
68+
}
69+
70+
/**
71+
* Test the executeUpgrade method - should remove all legacy portlets
72+
*/
73+
@Test
74+
public void test_executeUpgrade_should_remove_all_legacy_portlets() throws Exception {
75+
// Setup: Insert multiple test legacy portlet entries
76+
new DotConnect()
77+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
78+
.addParam("test-legacy-id-2")
79+
.addParam("test-layout-id-1")
80+
.addParam("content-types")
81+
.addParam(1)
82+
.loadResult();
83+
84+
new DotConnect()
85+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
86+
.addParam("test-legacy-id-3")
87+
.addParam("test-layout-id-2")
88+
.addParam("content-types")
89+
.addParam(2)
90+
.loadResult();
91+
92+
try {
93+
// Verify setup: Should have legacy portlets before execution
94+
int countBefore = new DotConnect()
95+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
96+
.addParam("content-types")
97+
.getInt("count");
98+
assertTrue("Should have legacy portlets before executeUpgrade", countBefore >= 2);
99+
100+
// Test: Execute the upgrade task
101+
Task251029RemoveContentTypesLegacyPortletFromLayouts task = new Task251029RemoveContentTypesLegacyPortletFromLayouts();
102+
task.executeUpgrade();
103+
104+
// Verify: No legacy portlets should exist after execution
105+
int countAfter = new DotConnect()
106+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
107+
.addParam("content-types")
108+
.getInt("count");
109+
assertEquals("All content-types portlets should be removed after executeUpgrade", 0, countAfter);
110+
111+
// Verify: forceRun should return false after execution
112+
assertFalse("forceRun should return false after executeUpgrade removes all legacy portlets",
113+
task.forceRun());
114+
115+
} finally {
116+
// Cleanup: Ensure test data is removed
117+
new DotConnect()
118+
.setSQL("DELETE FROM cms_layouts_portlets WHERE id IN (?, ?)")
119+
.addParam("test-legacy-id-2")
120+
.addParam("test-legacy-id-3")
121+
.loadResult();
122+
}
123+
}
124+
125+
/**
126+
* Test the executeUpgrade method is idempotent - can run multiple times safely
127+
*/
128+
@Test
129+
public void test_executeUpgrade_is_idempotent() throws Exception {
130+
// Setup: Insert a test legacy portlet entry
131+
new DotConnect()
132+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
133+
.addParam("test-legacy-id-4")
134+
.addParam("test-layout-id-3")
135+
.addParam("content-types")
136+
.addParam(1)
137+
.loadResult();
138+
139+
try {
140+
Task251029RemoveContentTypesLegacyPortletFromLayouts task = new Task251029RemoveContentTypesLegacyPortletFromLayouts();
141+
142+
// First execution
143+
task.executeUpgrade();
144+
int countAfterFirst = new DotConnect()
145+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
146+
.addParam("content-types")
147+
.getInt("count");
148+
149+
// Second execution (should not cause errors)
150+
task.executeUpgrade();
151+
int countAfterSecond = new DotConnect()
152+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
153+
.addParam("content-types")
154+
.getInt("count");
155+
156+
// Both should result in 0 legacy portlets
157+
assertEquals("First execution should remove all legacy portlets", 0, countAfterFirst);
158+
assertEquals("Second execution should maintain 0 legacy portlets", 0, countAfterSecond);
159+
assertEquals("Multiple executions should be idempotent", countAfterFirst, countAfterSecond);
160+
161+
} finally {
162+
// Cleanup: Remove any remaining test data
163+
new DotConnect()
164+
.setSQL("DELETE FROM cms_layouts_portlets WHERE id = ?")
165+
.addParam("test-legacy-id-4")
166+
.loadResult();
167+
}
168+
}
169+
170+
/**
171+
* Test that other portlets are not affected by the task
172+
*/
173+
@Test
174+
public void test_executeUpgrade_preserves_other_portlets() throws Exception {
175+
// Setup: Insert test entries for both legacy and modern portlets
176+
new DotConnect()
177+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
178+
.addParam("test-legacy-id-5")
179+
.addParam("test-layout-id-4")
180+
.addParam("content-types")
181+
.addParam(1)
182+
.loadResult();
183+
184+
new DotConnect()
185+
.setSQL("INSERT INTO cms_layouts_portlets (id, layout_id, portlet_id, portlet_order) VALUES (?, ?, ?, ?)")
186+
.addParam("test-modern-id-1")
187+
.addParam("test-layout-id-4")
188+
.addParam("content-types-angular")
189+
.addParam(2)
190+
.loadResult();
191+
192+
try {
193+
// Verify setup
194+
int legacyCountBefore = new DotConnect()
195+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
196+
.addParam("content-types")
197+
.getInt("count");
198+
int modernCountBefore = new DotConnect()
199+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
200+
.addParam("content-types-angular")
201+
.getInt("count");
202+
203+
assertTrue("Should have legacy portlet before execution", legacyCountBefore >= 1);
204+
assertTrue("Should have modern portlet before execution", modernCountBefore >= 1);
205+
206+
// Test: Execute the upgrade task
207+
Task251029RemoveContentTypesLegacyPortletFromLayouts task = new Task251029RemoveContentTypesLegacyPortletFromLayouts();
208+
task.executeUpgrade();
209+
210+
// Verify results
211+
int legacyCountAfter = new DotConnect()
212+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
213+
.addParam("content-types")
214+
.getInt("count");
215+
int modernCountAfter = new DotConnect()
216+
.setSQL("SELECT count(*) as count FROM cms_layouts_portlets WHERE portlet_id = ?")
217+
.addParam("content-types-angular")
218+
.getInt("count");
219+
220+
assertEquals("Legacy portlets should be removed", 0, legacyCountAfter);
221+
assertEquals("Modern portlets should be preserved", modernCountBefore, modernCountAfter);
222+
223+
} finally {
224+
// Cleanup
225+
new DotConnect()
226+
.setSQL("DELETE FROM cms_layouts_portlets WHERE id IN (?, ?)")
227+
.addParam("test-legacy-id-5")
228+
.addParam("test-modern-id-1")
229+
.loadResult();
230+
}
231+
}
232+
}

0 commit comments

Comments
 (0)