Republish working

pull/10/head
Jens Pelzetter 2021-08-18 19:12:56 +02:00
parent cfe8810666
commit e81b3fbd4a
3 changed files with 55 additions and 4 deletions

View File

@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -122,11 +123,17 @@ public class Lifecycle implements Identifiable, Serializable {
}
public Date getEndDateTime() {
return new Date(endDateTime.getTime());
return Optional
.ofNullable(endDateTime)
.map(date -> new Date(date.getTime()))
.orElse(null);
}
public void setEndDateTime(final Date endDateTime) {
this.endDateTime = new Date(endDateTime.getTime());
this.endDateTime = Optional
.ofNullable(endDateTime)
.map(date -> new Date(date.getTime()))
.orElse(null);
}
public String getListener() {

View File

@ -417,6 +417,50 @@ public class PublishStep extends AbstractMvcAuthoringStep {
return buildRedirectPathForStep();
}
@POST
@Path("/republish")
@Transactional(Transactional.TxType.REQUIRED)
public String republish() {
try {
init();
} catch (ContentSectionNotFoundException ex) {
return ex.showErrorMessage();
} catch (DocumentNotFoundException ex) {
return ex.showErrorMessage();
}
final ContentItem document = getDocument();
if (!itemManager.isLive(document)) {
models.put("republishNoneLive", true);
models.put("document", itemManager.getItemPath(document));
return TEMPLATE;
}
final ContentItem live = itemManager
.getLiveVersion(document, document.getClass())
.orElseThrow(
() -> new UnexpectedErrorException(
String.format(
"ContentItem %s is reported as live by "
+ "ContentItemManager#isLive"
+ "but has no live version.",
document.getUuid()
)
)
);
final Lifecycle lifecycle = live.getLifecycle();
final LifecycleDefinition definition = lifecycle.getDefinition();
final Date startDateTime = lifecycle.getStartDateTime();
final Date endDateTime = lifecycle.getEndDateTime();
itemManager.publish(
document, definition, startDateTime, endDateTime
);
return buildRedirectPathForStep();
}
/**
* Unpublishes the current content item.
*

View File

@ -38,7 +38,7 @@
</p>
<div class="d-flex">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@publish"
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@publish/republish"
class="mr-3"
method="post">
<button class="btn btn-primary"