-
Notifications
You must be signed in to change notification settings - Fork 10
/
refactor_structure_ids.groovy
56 lines (42 loc) · 1.44 KB
/
refactor_structure_ids.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
55
56
/**
* refactor_structure_ids.groovy
*
* Refactor some structures IDs
*
* @author Sébastien Le Marchand (@slemarchand on github)
* @author Orin Fink (@einsty on github) -
*/
// 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.*
import com.liferay.portlet.dynamicdatamapping.model.*
import com.liferay.portlet.dynamicdatamapping.service.*
import com.liferay.portal.service.ClassNameLocalServiceUtil
try {
map.each{ oldId, newId ->
cId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class.getName())
s = DDMStructureLocalServiceUtil.getStructure(groupId, cId, oldId, includeGlobalStructures)
s
s.setStructureKey(newId)
DDMStructureLocalServiceUtil.updateDDMStructure(s)
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)
}