Skip to content

Commit ee81342

Browse files
committed
fix: fix working with sites, update version and docs
1 parent de8ed75 commit ee81342

File tree

5 files changed

+91
-27
lines changed

5 files changed

+91
-27
lines changed

README.adoc

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= Liferay Portal DB setup core
22
:liferay-version: 7.4.3.125
3-
:current-db-setup-core-version: 7.4.3863
3+
:current-db-setup-core-version: 7.4.3125.0
44
:TOC:
55

66
image:https://maven-badges.herokuapp.com/maven-central/com.ableneo.liferay/com.ableneo.liferay.db.setup.core/badge.svg?color=blue[Maven Central,link=https://search.maven.org/search?q=g:com.ableneo.liferay%20AND%20a:com.ableneo.liferay.db.setup.core]
@@ -136,6 +136,7 @@ All data definitions in the setup XML file are applied according to the `configu
136136
<companywebid>liferay.com</companywebid>
137137
</company>
138138
</configuration>
139+
</setup>
139140
----
140141
=== Features
141142

@@ -147,6 +148,8 @@ If you develop new link:https://learn.liferay.com/dxp/latest/en/headless-deliver
147148
.Add new or update existing Service Access Policy by name
148149
[source, xml]
149150
----
151+
<?xml version="1.0" encoding="UTF-8"?>
152+
<setup xmlns="http://www.ableneo.com/liferay/setup">
150153
<company-settings>
151154
<service-access-policies>
152155
<service-access-policy name="MY_ACCESS_POLICY" enabled="true" unauthenticated="true">
@@ -156,23 +159,29 @@ If you develop new link:https://learn.liferay.com/dxp/latest/en/headless-deliver
156159
</allowed-service-signatures>
157160
</service-access-policy>
158161
</service-access-policies>
159-
</company>
162+
</company-settings>
163+
</setup>
160164
----
161165
<1> `allowed-service-signatures` provides the same functionality as link:https://learn.liferay.com/dxp/latest/en/installation-and-upgrades/securing-liferay/securing-web-services/setting-service-access-policies.html#creating-a-service-access-policy[_Advanced Mode_]
162166

163167
.Delete existing Service Access Policy by name
164168
[source,xml]
165169
----
170+
<?xml version="1.0" encoding="UTF-8"?>
171+
<setup xmlns="http://www.ableneo.com/liferay/setup">
166172
<company-settings>
167173
<service-access-policies>
168174
<delete-service-access-policy name="WIZARD_GUEST_ACCESS"/>
169175
</service-access-policies>
170176
</company-settings>
177+
</setup>
171178
----
172179
==== Permissions
173180
Resource permissions.
174181
[source, xml]
175182
----
183+
<?xml version="1.0" encoding="UTF-8"?>
184+
<setup xmlns="http://www.ableneo.com/liferay/setup">
176185
<resource-permissions>
177186
<resource resource-id="my.custom.resource.string">
178187
<actionId name="SPECIAL_PERMISSION">
@@ -181,6 +190,7 @@ Resource permissions.
181190
</actionId>
182191
</resource>
183192
</resource-permissions>
193+
</setup>
184194
----
185195
Resource permissions are set per company are verifiable with followin API call.
186196
[source, java]
@@ -196,6 +206,8 @@ permissionChecker.hasPermission(
196206
Portlet permissions.
197207
[source, xml]
198208
----
209+
<?xml version="1.0" encoding="UTF-8"?>
210+
<setup xmlns="http://www.ableneo.com/liferay/setup">
199211
<resource-permissions>
200212
<resource resource-id="myportlet_WAR_portlets">
201213
<actionId name="VIEW">
@@ -204,44 +216,62 @@ Portlet permissions.
204216
</actionId>
205217
</resource>
206218
</resource-permissions>
219+
</setup>
207220
----
208221
==== Roles
209222
[source, xml]
210223
----
224+
<?xml version="1.0" encoding="UTF-8"?>
225+
<setup xmlns="http://www.ableneo.com/liferay/setup">
211226
<roles>
212227
<role name="Regular Role"/>
213228
<role name="Site Role" type="site"/>
214-
<roles>
229+
</roles>
230+
</setup>
215231
----
216232
==== Expando attribute
217233
Following snippet creates expando attribute `canonical-url` with permissions to view by guest user.
218234
[source, xml]
219235
----
236+
<?xml version="1.0" encoding="UTF-8"?>
237+
<setup xmlns="http://www.ableneo.com/liferay/setup">
220238
<custom-fields>
221239
<field name="canonical-url" type="string" class-name="com.liferay.portal.kernel.model.Layout">
222240
<role-permission role-name="Guest" permission="view"/>
223241
</field>
224242
</custom-fields>
243+
</setup>
225244
----
226-
==== Site
227-
Site element must always have `site-friendly-url` attribute. Guest site is determined by `default` attribute with `true` value. All content like *pages*, *articles*, *documents* etc. is always created within a specific site.
245+
==== Site selection
246+
All content like *pages*, *articles*, *documents* etc. is always created within a specific site. You can create new or refer to existing site.
247+
228248
[source, xml]
229249
----
250+
<?xml version="1.0" encoding="UTF-8"?>
251+
<setup xmlns="http://www.ableneo.com/liferay/setup">
230252
<sites>
231-
<site default="true" site-friendly-url="/guest">
253+
<site default="true">
254+
<!-- default company site -->
255+
</site>
256+
<site global="true">
257+
<!-- global company site -->
232258
</site>
233-
<site default="false" site-friendly-url="/admin">
234-
<name>Admin</name>
259+
<site default="false" site-friendly-url="/admin" name="Admin">
260+
<!-- specific site -->
235261
<name-translation locale="en_US" text="Admin"/>
236262
</site>
237263
</sites>
264+
</setup>
238265
----
239266
==== Journal Article structure and template
240267
Files `new_structure.xml` and `new_structure_template.ftl` are deployed as a part of a module that is using the `db-setup-core` library and reside in it's classpath.
241268
[source, xml]
242269
----
270+
<?xml version="1.0" encoding="UTF-8"?>
271+
<setup xmlns="http://www.ableneo.com/liferay/setup">
243272
244-
<site site-friendly-url="/admin">
273+
<sites>
274+
<site site-friendly-url="/admin" name="Admin">
245275
<article-structure key="NEW-STRUCTURE-KEY"
246276
path="new_structure.xml"
247277
name="New Structure"/>
@@ -250,15 +280,19 @@ Files `new_structure.xml` and `new_structure_template.ftl` are deployed as a par
250280
path="new_structure_template.ftl"
251281
article-structure-key="NEW-STRUCTURE-KEY" name="New Structure Template" cacheable="true"/>
252282
253-
<name>Admin</name>
254283
</site>
284+
</sites>
285+
</setup>
255286
----
256287
==== Articles
257288
File `artcle.xml` is deployed as a part of a module that is using the `db-setup-core` library and reside in it's classpath.
258289
[source, xml]
259290
----
291+
<?xml version="1.0" encoding="UTF-8"?>
292+
<setup xmlns="http://www.ableneo.com/liferay/setup">
293+
260294
<sites>
261-
<site>
295+
<site global="true">
262296
<article
263297
title="Article Title"
264298
path="article.xml"
@@ -269,19 +303,24 @@ File `artcle.xml` is deployed as a part of a module that is using the `db-setup-
269303
</article>
270304
</site>
271305
</sites>
306+
</setup>
272307
----
273308
==== Document
274309
Document's file itself is determined by `file-system-name` attribute which defines resource on classpath.
275310
[source, xml]
276311
----
312+
<?xml version="1.0" encoding="UTF-8"?>
313+
<setup xmlns="http://www.ableneo.com/liferay/setup">
314+
277315
<sites>
278-
<site>
316+
<site name="Guest">
279317
<document file-system-name="image.svg"
280318
document-folder-name="/Images"
281319
document-filename="image.svg"
282320
document-title="image.svg"/>
283321
</site>
284322
</sites>
323+
</setup>
285324
----
286325

287326
=== Liferay Portal requirements
@@ -316,12 +355,14 @@ They are probably not perfect, please let me know if anything feels wrong or inc
316355

317356
== Changelog
318357

319-
=== Version 7.4.3860
358+
=== Version 7.4.3125.0
320359

321360
==== Features & bug fixes
322361
* switched to JDK21
323362
* api compatible with Liferay 7.4.3.125
324363
* fixed category import (updating parent)
364+
* fixed working with global/default sites <<_site_selection>>
365+
* updated docs
325366

326367
=== Version 7.4.3860
327368

@@ -365,10 +406,17 @@ They are probably not perfect, please let me know if anything feels wrong or inc
365406
.Fixed configuration
366407
[source, xml]
367408
----
409+
<?xml version="1.0" encoding="UTF-8"?>
410+
<setup xmlns="http://www.ableneo.com/liferay/setup">
411+
368412
<resource-permissions>
369413
<resource resource-id="custom.resource.id-not.a.portlet.id">
370414
<actionId name="SOME_PERMISSION">
371415
<role name="Some Portal Role"/>
416+
</actionId>
417+
</resource>
418+
</resource-permissions>
419+
</setup>
372420
----
373421

374422
==== Refactorings & project changes

com.ableneo.liferay.site.example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
<artifactId>maven-compiler-plugin</artifactId>
4848
<configuration>
4949
<encoding>UTF-8</encoding>
50-
<source>11</source>
51-
<target>11</target>
50+
<source>21</source>
51+
<target>21</target>
5252
</configuration>
5353
</plugin>
5454

pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>9</version>
99
</parent>
1010

11-
<version>7.4.3863-SNAPSHOT</version>
11+
<version>7.4.3125.0-SNAPSHOT</version>
1212
<groupId>com.ableneo.liferay</groupId>
1313
<artifactId>com.ableneo.liferay.db.setup.core</artifactId>
1414
<description>Creates Liferay Portal data (permissions, roles, sites, pages etc.) from XML declaration.</description>
@@ -100,8 +100,8 @@
100100
<artifactId>maven-compiler-plugin</artifactId>
101101
<configuration>
102102
<encoding>UTF-8</encoding>
103-
<source>11</source>
104-
<target>11</target>
103+
<source>21</source>
104+
<target>21</target>
105105
</configuration>
106106
</plugin>
107107

@@ -263,7 +263,7 @@
263263
<configuration>
264264
<rules>
265265
<requireJavaVersion>
266-
<version>11</version>
266+
<version>21</version>
267267
</requireJavaVersion>
268268
<requireMavenVersion>
269269
<version>3.8.1</version>
@@ -491,6 +491,12 @@
491491
<name>Adolfo Carlos Benitez Sanchez</name>
492492
<url>https://github.com/abenitezsan</url>
493493
</developer>
494+
<developer>
495+
<id>bimki</id>
496+
<name>Bartłomiej Knabel</name>
497+
<email>[email protected]</email>
498+
<url>https://github.com/bimki</url>
499+
</developer>
494500
<developer>
495501
<id>dmmrch</id>
496502
<name>Dmitry Marchuk</name>

src/main/java/com/ableneo/liferay/portal/setup/core/SetupSites.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.liferay.portal.kernel.model.GroupConstants;
2323
import com.liferay.portal.kernel.model.User;
2424
import com.liferay.portal.kernel.model.UserGroup;
25+
import com.liferay.portal.kernel.service.CompanyLocalServiceUtil;
2526
import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
2627
import com.liferay.portal.kernel.service.RoleLocalServiceUtil;
2728
import com.liferay.portal.kernel.service.ServiceContext;
@@ -30,6 +31,8 @@
3031
import com.liferay.portal.kernel.service.UserGroupRoleLocalServiceUtil;
3132
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
3233
import com.liferay.portal.kernel.util.UnicodeProperties;
34+
import com.liferay.portal.kernel.util.Validator;
35+
3336
import java.util.Arrays;
3437
import java.util.HashMap;
3538
import java.util.HashSet;
@@ -64,14 +67,18 @@ private static Group setupSite(Group parentGroup, long companyId, Site site) thr
6467
Group liferayGroup = null;
6568
long groupId = -1;
6669
if (site.isDefault()) {
67-
liferayGroup = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);
70+
liferayGroup = CompanyLocalServiceUtil.getCompany(companyId).getGroup();
6871
LOG.info(String.format("Setup: default site. Group ID: %1$s", groupId));
69-
} else if (site.getName() == null) {
70-
liferayGroup = GroupLocalServiceUtil.getCompanyGroup(companyId);
72+
} else if (site.isGlobal()) {
73+
liferayGroup = GroupLocalServiceUtil.fetchFriendlyURLGroup(companyId, GroupConstants.GLOBAL_FRIENDLY_URL);
7174
LOG.info(String.format("Setup: global site. Group ID: %1$s", groupId));
7275
} else {
7376
try {
74-
liferayGroup = GroupLocalServiceUtil.getGroup(companyId, site.getName());
77+
if (site.getName() != null) {
78+
liferayGroup = GroupLocalServiceUtil.getGroup(companyId, site.getName());
79+
} if (site.getSiteFriendlyUrl() != null) {
80+
liferayGroup = GroupLocalServiceUtil.fetchFriendlyURLGroup(companyId, site.getSiteFriendlyUrl());
81+
}
7582
LOG.info(
7683
String.format(
7784
"Setup: Site %1$s already exists in system, not creating... (pk=%2$s,gid=%3$s)",
@@ -114,8 +121,10 @@ private static Group setupSite(Group parentGroup, long companyId, Site site) thr
114121
);
115122
LOG.info(String.format("New site created."));
116123
} else {
117-
LOG.info(String.format("Updating site: %1$s", site.getName()));
118-
GroupLocalServiceUtil.updateFriendlyURL(liferayGroup.getGroupId(), site.getSiteFriendlyUrl());
124+
if (!Validator.isBlank(site.getSiteFriendlyUrl())) {
125+
LOG.info(String.format("Updating site: %1$s", site.getName()));
126+
GroupLocalServiceUtil.updateFriendlyURL(liferayGroup.getGroupId(), site.getSiteFriendlyUrl());
127+
}
119128
}
120129

121130
groupId = liferayGroup.getGroupId();

src/main/resources/setup_definition.xsd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@
192192
<xs:element ref="membership" minOccurs="0"/>
193193
<xs:element ref="site" minOccurs="0" maxOccurs="unbounded"/>
194194
<xs:element ref="menu" minOccurs="0" maxOccurs="unbounded"/>
195-
<xs:element name="name" type="xs:string"/>
196195
<xs:element name="name-translation" type="TranslationType" minOccurs="0" maxOccurs="unbounded"/>
197196
<xs:element name="site-preferences" type="SitePreferencesType" minOccurs="0"/>
198197
</xs:sequence>
199198
<xs:attribute name="default" type="xs:boolean" default="false"/>
199+
<xs:attribute name="global" type="xs:boolean" default="false"/>
200200
<xs:attribute name="strict-web-folder-definition" type="xs:boolean" default="false"/>
201201
<xs:attribute name="strict-document-folder-definition" type="xs:boolean" default="false"/>
202202
<xs:attribute name="maintain-site-hierarchy" type="xs:boolean" default="false"/>
203-
<xs:attribute name="site-friendly-url" type="xs:string"/>
203+
<xs:attribute name="site-friendly-url" type="xs:string" />
204+
<xs:attribute name="name" type="xs:string"/>
204205
<xs:attribute name="membership-type" type="xs:int" default="2">
205206
<xs:annotation>
206207
<xs:documentation>Uses GroupConstants.TYPE_SITE_* values, default is 'restricted'==2

0 commit comments

Comments
 (0)