-
Notifications
You must be signed in to change notification settings - Fork 10
/
refactor_structure_ids_61.groovy
54 lines (43 loc) · 1.35 KB
/
refactor_structure_ids_61.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// refactor_structure_ids.groovy
//
// Author: Sébastien Le Marchand (@slemarchand)
//
// Refactor some structures IDs
//
// Variables to update at your convenience
groupId = 10190L // The site from getting structures
includeGlobalStructures = true
map = [
'10904':'HEADER-STR',
'11501':'PIECE-OF-NEWS-STR',
'11803':'FOOTER-STR'
]
// Implementation
import com.liferay.portal.kernel.dao.orm.*
import com.liferay.portal.util.*
import com.liferay.portlet.journal.model.*
import com.liferay.portlet.journal.service.*
try {
map.each{ oldId, newId ->
s = JournalStructureLocalServiceUtil.getStructure(groupId, oldId, includeGlobalStructures)
s.setStructureId(newId)
JournalStructureLocalServiceUtil.updateJournalStructure(s)
q = DynamicQueryFactoryUtil.forClass(JournalTemplate.class)
q.add(PropertyFactoryUtil.forName('structureId').eq(oldId))
templates = JournalTemplateLocalServiceUtil.dynamicQuery(q)
templates.each{ t ->
t.setStructureId(newId)
JournalTemplateLocalServiceUtil.updateJournalTemplate(t)
}
q = DynamicQueryFactoryUtil.forClass(JournalArticle.class)
q.add(PropertyFactoryUtil.forName('structureId').eq(oldId))
articles = JournalArticleLocalServiceUtil.dynamicQuery(q)
articles.each{ a ->
a.setStructureId(newId)
JournalArticleLocalServiceUtil.updateJournalArticle(a)
}
}
} catch (e) {
e.printStackTrace(out)
}