Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU-1711: CMS: Page Expire Date #358

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6282b8c
GPU-1727: Add db migration, implement entity and service to create an…
guggi Sep 2, 2024
0854957
GPU-1722: REST design and implementation, improvements, javadoc
guggi Sep 3, 2024
a57b1b9
Make obj column an index and add changelog
guggi Sep 3, 2024
05d81d0
Only return object with view permission
guggi Sep 3, 2024
d0ce3d9
Protect resources, fix permission error response
guggi Sep 5, 2024
d487044
GPU-1726: Include PR feedback, make service static, use type and obj_…
guggi Sep 10, 2024
81b3b4f
GPU-1726: Alway add ONE log entry independent if service implementati…
guggi Sep 10, 2024
6c07ff7
GPU-1723: Implement test for publishing and unpublishing for pages an…
guggi Sep 10, 2024
5d313f0
GPU-1726: Add unpublish info to rest page, retrieve and include this …
guggi Sep 11, 2024
22f6765
GPU-1726: Also add unpublished info to form endpoint, genralize metho…
guggi Sep 11, 2024
d9b4f08
GPU-1724: Integrate into UI
guggi Sep 11, 2024
91a503d
GPU-1724: Integrate into UI
guggi Sep 11, 2024
b3cbb25
GPU-1726: Add unpublish info to node objects directly, add db migrati…
guggi Sep 12, 2024
af2324e
GPU-1726: Use base class for publishable rest objects, align node pro…
guggi Sep 16, 2024
fbcb1ad
GPU-1804: Set publish/unpublish info when actual publishing, remove p…
guggi Sep 19, 2024
3ea5cb3
GPU-1803: UI Integrate publish protocol
guggi Sep 24, 2024
3793215
GPU-1803: Improvements & Cleanup
guggi Sep 24, 2024
1d15e52
GPU-1804: Fix timemanagment user, add future publisher and unpublishe…
guggi Sep 25, 2024
7aeaa61
GPU-1804: Add fields to rest model for page, add validation to endpoints
guggi Sep 25, 2024
3453df2
GPU-1803, GPU-1804: Fix discrepancy between actual publisher and futu…
guggi Sep 26, 2024
efdb90f
Throw error instead of default value
guggi Sep 26, 2024
c4cc28d
Fix changelog
guggi Sep 26, 2024
4d6b72c
Fix publish log for form: make component generic
guggi Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.gentics.contentnode.factory.object;

import java.util.List;

import com.gentics.api.lib.exception.NodeException;
import com.gentics.contentnode.object.PublishableNodeObject;
import com.gentics.contentnode.publish.protocol.PublishProtocolUtil;
import com.gentics.contentnode.publish.protocol.PublishState;
import java.util.List;

/**
* Interface for {@link PublishableNodeObject}s, which allow to add hooks for specific actions on them (like saving, deleting, publishing and taking offline)
Expand All @@ -23,6 +24,8 @@ public interface ExtensiblePublishableObject<T extends PublishableNodeObject> ex
* @throws NodeException when publishing has to fail
*/
default void onPublish(T object, boolean wasOnline, int userId) throws NodeException {
PublishProtocolUtil.logPublishState(object, PublishState.ONLINE.getValue(), userId);

for (ExtensiblePublishableObjectService<T> service : getServices()) {
service.onPublish(object, wasOnline, userId);
}
Expand All @@ -37,6 +40,8 @@ default void onPublish(T object, boolean wasOnline, int userId) throws NodeExcep
* @throws NodeException when taking offline has to fail
*/
default void onTakeOffline(T object, boolean wasOnline, int userId) throws NodeException {
PublishProtocolUtil.logPublishState(object, PublishState.OFFLINE.getValue(), userId);

for (ExtensiblePublishableObjectService<T> service : getServices()) {
service.onTakeOffline(object, wasOnline, userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ private static class FactoryForm extends AbstractContentObject implements Form,
@Unversioned
protected ContentNodeDate pDate = new ContentNodeDate(0);

@DataField("unpublishedDate")
guggi marked this conversation as resolved.
Show resolved Hide resolved
@Updateable
@Unversioned
protected ContentNodeDate unpublishedDate = new ContentNodeDate(0);

@DataField("unpublisher")
@Updateable
@Unversioned
protected int unpublisher = 0;

@DataField("publisher")
@Updateable
@Unversioned
Expand Down Expand Up @@ -329,13 +339,47 @@ public ContentNodeDate getPDate() {
return pDate;
}

@Override
public ContentNodeDate getUnpublishedDate() {
try {
guggi marked this conversation as resolved.
Show resolved Hide resolved
return DBUtils.select("SELECT unpublished_date FROM form WHERE id = ?", stmt -> {
stmt.setInt(1, getId());
}, resultSet -> {
if (resultSet.next()) {
int unpublishedDate = resultSet.getInt("unpublished_date");
this.unpublishedDate = new ContentNodeDate(unpublishedDate);
}
return this.unpublishedDate;
}
);
} catch (NodeException e) {
logger.error("Unable to get unpublished date from form with id: "+ getId(), e);
}

return this.unpublishedDate;
}

@Override
public SystemUser getPublisher() throws NodeException {
SystemUser publisher = TransactionManager.getCurrentTransaction().getObject(SystemUser.class, publisherId);
assertNodeObjectNotNull(publisher, publisherId, "Publisher", true);
return publisher;
}

@Override
public SystemUser getUnpublisher() throws NodeException {
return DBUtils.select("SELECT unpublisher FROM form WHERE id = ?", stmt -> {
stmt.setInt(1, getId());
}, resultSet -> {
if (resultSet.next()) {
int unpublisherId = resultSet.getInt("unpublisher");
return TransactionManager.getCurrentTransaction().getObject(SystemUser.class, unpublisherId);
}
return null;
}
);
}

@Override
public void publish(int at, boolean keepTimePubVersion) throws ReadOnlyException, NodeException {
Transaction t = TransactionManager.getCurrentTransaction();
Expand Down Expand Up @@ -463,6 +507,9 @@ public void takeOffline(int at) throws ReadOnlyException, NodeException {

// we need to sent the NOTIFY event for the form in order to allow indexing (for feature ELASTICSEARCH)
t.addTransactional(new TransactionalTriggerEvent(Form.class, getId(), INDEXED_STATUS_ATTRIBUTES, Events.NOTIFY));

int unpublishedAt = at == 0 ? TransactionManager.getCurrentTransaction().getUnixTimestamp() : at;
DBUtils.update("UPDATE form SET unpublished_date = ?, unpublisher = ? WHERE id = ?", unpublishedAt, t.getUserId(), getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private static class FactoryPage extends AbstractPage implements DisinheritableI
protected ContentNodeDate eDate = new ContentNodeDate(0);
protected ContentNodeDate customEDate = new ContentNodeDate(0);
protected ContentNodeDate pDate = new ContentNodeDate(0);
protected ContentNodeDate unpublishedDate = new ContentNodeDate(0);
protected Integer creatorId = 0;
protected Integer editorId = 0;
protected Integer publisherId = 0;
Expand Down Expand Up @@ -744,6 +745,19 @@ public SystemUser getPublisher() throws NodeException {
return publisher;
}

public SystemUser getUnpublisher() throws NodeException {
return DBUtils.select("SELECT unpublisher FROM page WHERE id = ?", stmt -> {
stmt.setInt(1, getId());
}, resultSet -> {
if (resultSet.next()) {
int unpublisherId = resultSet.getInt("unpublisher");
return TransactionManager.getCurrentTransaction().getObject(SystemUser.class, unpublisherId);
}
return null;
}
);
}

public List<Page> getLanguageVariants(boolean considerNodeLanguages) throws NodeException {
return loadLanguageVariants(considerNodeLanguages);
}
Expand Down Expand Up @@ -1128,6 +1142,27 @@ protected void setPDate(int timestamp) {
}
}

public ContentNodeDate getUnpublishedDate() {
try {
return DBUtils.select("SELECT unpublished_date FROM page WHERE id = ?", stmt -> {
stmt.setInt(1, getId());
}, resultSet -> {
if (resultSet.next()) {
int unpublishedDate = resultSet.getInt("unpublished_date");
this.unpublishedDate = new ContentNodeDate(unpublishedDate);
}
return this.unpublishedDate;
}
);
} catch (NodeException e) {
logger.error("Unable to get unpublished date from page with id: "+ getId(), e);
}

return this.unpublishedDate;
}



/**
* Get the pdate of the page. If a value is stored as transaction attribute, it will modify the current pdate.
* @return pdate
Expand Down Expand Up @@ -2591,6 +2626,7 @@ public void takeOffline(int timestamp) throws ReadOnlyException, NodeException {
// set the planned offline time and clear queue for planned offline time
Transaction t = TransactionManager.getCurrentTransaction();
DBUtils.update("UPDATE page SET time_off = ?, off_queue = ?, time_off_queue = ? WHERE id = ?", timestamp, 0, 0, getId());

timeOff = new ContentNodeDate(timestamp);
offQueueUserId = 0;
timeOffQueue = new ContentNodeDate(0);
Expand All @@ -2599,6 +2635,9 @@ public void takeOffline(int timestamp) throws ReadOnlyException, NodeException {
// we need to sent the NOTIFY event for the page in order to allow indexing (for feature ELASTICSEARCH)
t.addTransactional(new TransactionalTriggerEvent(Page.class, getId(), INDEXED_STATUS_ATTRIBUTES, Events.NOTIFY));
}
Transaction t = TransactionManager.getCurrentTransaction();
guggi marked this conversation as resolved.
Show resolved Hide resolved
int unpublishedAt = timestamp == 0 ? TransactionManager.getCurrentTransaction().getUnixTimestamp() : timestamp;
DBUtils.update("UPDATE page SET unpublished_date = ?, unpublisher = ? WHERE id = ?", unpublishedAt, t.getUserId(), getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,26 @@ public interface PublishableNodeObject extends NodeObject {
*/
ContentNodeDate getPDate();

/**
* get the unpublish date as a unix timestamp
* @return unpublish date unix timestamp
*/
ContentNodeDate getUnpublishedDate();

/**
* Get the user, who published the object (last)
* @return last publisher, may be null
* @throws NodeException
*/
SystemUser getPublisher() throws NodeException;

/**
* Get the user, who unpublished the object (last)
* @return last unpublisher, may be null
* @throws NodeException
*/
SystemUser getUnpublisher() throws NodeException;

/**
* Publish the object
* @throws ReadOnlyException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @author Stefan Hepp
* @date 23.1.2006
* @version $Id: PublishStatus.java,v 1.2 2006-02-05 18:16:44 stefan Exp $
* @version $Id: PublishState.java,v 1.2 2006-02-05 18:16:44 stefan Exp $
*/
package com.gentics.contentnode.publish;

Expand Down
Loading