-
Notifications
You must be signed in to change notification settings - Fork 10
/
refactor_template_ids.groovy
58 lines (47 loc) · 1.58 KB
/
refactor_template_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
57
58
/**
* Copyright (c) 2013 Sébastien Le Marchand, All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
//
// refactor_template_ids.groovy
//
// Refactor some templates IDs
//
// Variables to update at your convenience
groupId = 10190L // The site from getting templates
includeGlobalTemplates = true
map = [
'12807':'HEADER-TPL',
'14501':'PIECE-OF-NEWS-TPL',
'15901':'FOOTER-TPL'
]
// 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 ->
t = JournalTemplateLocalServiceUtil.getTemplate(groupId, oldId, includeGlobalTemplates)
t.setTemplateId(newId)
JournalTemplateLocalServiceUtil.updateJournalTemplate(t)
q = DynamicQueryFactoryUtil.forClass(JournalArticle.class)
q.add(PropertyFactoryUtil.forName('templateId').eq(oldId))
articles = JournalArticleLocalServiceUtil.dynamicQuery(q)
articles.each{ a ->
a.setTemplateId(newId)
JournalArticleLocalServiceUtil.updateJournalArticle(a)
}
}
} catch (e) {
e.printStackTrace(out)
}