Commenting module
Edition |
Incubator (services) |
||
Issues |
|||
Git |
|||
Latest |
1.1.4
|
This module offers commenting features as well as the possibility of liking or disliking comments. You can moderate comments or mark as author´s favourite. The commenting module provides a REST API for commenting and a Content App to view comments of an item.
It uses an external database to store the commenting data.
This module is at the INCUBATOR level. |
Installing with Maven
Maven is the easiest way to install the module. Add the following to your bundle.
Don’t forget about the JDBC drivers. |
<dependency>
<groupId>info.magnolia.commenting</groupId>
<artifactId>magnolia-commenting-app</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>info.magnolia.commenting</groupId>
<artifactId>magnolia-commenting-rest</artifactId>
<version>1.1.4</version>
</dependency>
Ensure the Tools module is part of your webapp. Webapp
|
JDBC drivers
You’ll also need to make sure you have your desired JDBC driver as part of your webapp.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
If you want to use an IDE like Eclipse or IntelliJ, you will need to configure the agent based on the |
Usage
This section guides you on setting up the module.
It contains the following sections:
Define the database connection
You can configure the database connection in the JCR or the File System (YAML) under: /src/main/resources/commenting-core/config.yaml
.
For MySQL
datasource:
username: user
password: password
url: jdbc:mysql://127.0.0.1:3306/comments
driver: com.mysql.cj.jdbc.Driver
migration:
path: dbmigration/mysql
run: true
If you have an error like: error
Add the following code to your url property in /commenting-core/config.yaml
|
For PostgreSQL
The snippet below doesn’t actually create the database, but rather points to it. Therefore, the defined database must already exist.
Ensure that the existing databse you’re using has the following rights:
|
datasource:
username: user
password: password
url: jdbc:postgresql://localhost:5432/comments
driver: org.postgresql.Driver
migration:
path: dbmigration/pg
run: true
Database schema
The table(s) required are created automatically by the init scripts in the magnolia-commenting-core
module. For these scripts to be executed the first time the module is installed (or whenever the database is empty) the migration node in the datasource is used:
-
path
: The path of the init script.-
dbmigration/mysql
for MySQL schema -
dbmigration/pg
for PostgreSQL schema
-
-
run
: this property needs to be true when the database is empty.Default value: false
Anonymous comments
If you need anonymous comments in your site, add the following to your commenting-rest module:
config:
allowAnonymous: true
Cache Be aware on Public instances, anonymous comments is cached on Magnolia by default. To prevent caching, add an entry in cache’s excludes section for URIs starting with |
Limit requests
To configure a limit on the request see Throttling Filter.
Content App Comments
Content App is hidden because it has no sense to view all comments without filter by an item. To view comments of a concrete item you need to select a node from a workspace and then click on "View Comments" action:
Once you have clicked on the action, you can view the "Comments" app per item selected:
In this app you can:
-
View comments (and their details).
-
Delete comments.
-
Moderate comments.
-
Author choice: favourite comment from Editors.
You can configure the action on each ContentApp simply by adding "commenting" action like the following example: |
subApps:
browser:
actions:
commenting:
appName: commenting
class: info.magnolia.commenting.action.BrowseCommentingActionDefinition
icon: icon-message
subAppId: browser
availability:
writePermissionRequired: false
rules:
IsNotDeletedRule:
implementationClass: info.magnolia.ui.framework.availability.IsNotDeletedRule
actionbar:
sections:
pageActions:
groups:
editActions:
items:
commenting: {}
Database action triggers
DB action triggers is a feature that allows triggering (calling) magnolia commands based on database action (CRUD). There are three types of actions that can be triggered:
To allow DB actions to trigger commands, we need to set magnolia property. Please set ebean.listeners.enabled
to "true"
in the corresponding magnolia.properties file.
ebean.listeners.enabled = true
Database trigger pass affected Entity objects to the command through the context. The User is able to get the Entity object (for example: info.magnolia.commenting.domain.Comment
) from the context (object is passed to context by key "data"
).
Comment comment = (Comment) ctx.get("data");
Persist
To execute magnolia command on persist (add) DB action:
-
name
command: prePersist or postPersist-
prePersist
is triggered before persist (add) action -
postPersist
is triggered after persist (add) action
-
-
put
command definition in catalog that is named based on the database entity for which we want to trigger command
'commenting-core':
'commands':
'comment':
'postPersist':
'class': 'info.magnolia.module.mail.commands.MailCommand' (1)
1 | Sends an email message when a new comment is added to the database. |
Update
To execute magnolia command on update DB action:
-
name
command: preUpdate or postUpdate-
preUpdate
is triggered before update action -
postUpdate
is triggered after update action
-
-
put
command definition in catalog that is named based on the database entity for which we want to trigger command
'commenting-core':
'commands':
'comment':
'postUpdate':
'class': 'info.magnolia.module.mail.commands.MailCommand' (1)
1 | Send an email message when a comment is updated in the database. |
Remove
To execute magnolia command on remove DB action:
-
name
command: preRemove or postRemove -
preRemove
is triggered before remove (delete) action -
postRemove
is triggered after remove (delete) action -
put
command definition in catalog that is named based on the database entity for which we want to trigger command
'commenting-core':
'commands':
'comment':
'postRemove':
'class': 'info.magnolia.module.mail.commands.MailCommand' (1)
1 | Sends an email message when a comment is deleted from the database. |
Templating functions: commfn
A set of templating functions is exposed as commfn
to allow developers use it in templates. This set of functions provides a set of methods to work with comments such as: liking a comment, reporting Abuse, disliking comments, etc,.
comments
Return a list of comments that match the search criteria.
- Method signature
-
List<Comments> comments(String mgnlWorkspace, String mgnlUuid, Integer limit, Integer offset, Long parent, String sort)
- Returns
-
List<Comments>
- Usage
[#assign commentsList= commfn.comments("website","b06b82a2-74b0-4994-8015-028c4fd60716",15,0,15,'created asc')]
Arguments
All arguments are required unless otherwise noted.
Argument | Description | ||
---|---|---|---|
|
The workspace you are working on.
|
||
|
The UUID of the item from where you want to get the comments. |
||
|
Number of results to return. |
||
|
Starting number of the rows to be returned. |
||
|
Sort parameter in form (ie: "created asc", "created desc" or "modified desc") |
||
|
optional
|
Deactivate ebeans log
Add the following to your log4js.xml
file to deactivate the ebeans log.
<!-- Ebean -->
<logger name="io.ebean.SQL" level="INFO"/>
<logger name="io.ebean.TXN" level="INFO"/>
<logger name="io.ebean.SUM" level="INFO"/>
<logger name="io.ebean.QUERY" level="INFO"/>
<logger name="io.ebean.BEAN" level="INFO"/>
<logger name="io.ebean.COLL" level="INFO"/>
<logger name="io.ebean.NATKEY" level="INFO"/>