incorporating:
r1620 | chrisg23 | 2007-09-13 14:30:18 +0200 (Do, 13 Sep 2007) | 1 line Sourceforge patch 1680544 Changes to bulk publish & unpublish: Bulk publish - if a default expiry notification is set in config and an item is published with an end date, then create a notification phase to prevent pulk published items disappearing silently. Bulk unpublish - implement a folder id argument that behaves like the existing argument in BulkPublish. git-svn-id: https://svn.libreccm.org/ccm/trunk@5 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
b11efee09a
commit
28a22df347
|
|
@ -26,13 +26,17 @@ import com.arsdigita.persistence.Filter;
|
|||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.SessionManager;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.workflow.simple.Workflow;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.ContentTypeLifecycleDefinition;
|
||||
import com.arsdigita.cms.Folder;
|
||||
import com.arsdigita.cms.lifecycle.Lifecycle;
|
||||
import com.arsdigita.cms.lifecycle.LifecycleDefinition;
|
||||
import com.arsdigita.cms.lifecycle.Phase;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.OptionBuilder;
|
||||
|
|
@ -164,6 +168,10 @@ public class BulkPublish extends Program {
|
|||
}
|
||||
}.run();
|
||||
|
||||
final int expiryNotification = ContentSection.
|
||||
getConfig().getDefaultNotificationTime();
|
||||
|
||||
|
||||
final Iterator items = toPublish.iterator();
|
||||
while (items.hasNext()) {
|
||||
final OID oid = (OID) items.next();
|
||||
|
|
@ -193,7 +201,31 @@ public class BulkPublish extends Program {
|
|||
return;
|
||||
}
|
||||
|
||||
item.publish(def, new Date());
|
||||
ContentItem pending = item.publish(def, new Date());
|
||||
final Lifecycle lifecycle = pending.getLifecycle();
|
||||
Date endDate = lifecycle.getEndDate();
|
||||
if (expiryNotification > 0) {
|
||||
|
||||
if (endDate != null) {
|
||||
|
||||
Date notificationDate = new Date(endDate.getTime() - (long)expiryNotification * 3600000L);
|
||||
|
||||
Phase expirationImminentPhase =
|
||||
lifecycle.addCustomPhase("expirationImminent",
|
||||
new Long(notificationDate.getTime()),
|
||||
new Long(endDate.getTime()));
|
||||
expirationImminentPhase.
|
||||
setListenerClassName("com.arsdigita.cms.lifecycle.NotifyLifecycleListener");
|
||||
expirationImminentPhase.save();
|
||||
}
|
||||
}
|
||||
if (ContentSection.getConfig().getDeleteWorkflowAfterPublication()) {
|
||||
Workflow workflow = Workflow.getObjectWorkflow(item);
|
||||
if (workflow != null) {
|
||||
workflow.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package com.arsdigita.london.util.cmd;
|
|||
import com.arsdigita.london.util.Program;
|
||||
import com.arsdigita.london.util.Transaction;
|
||||
import com.arsdigita.persistence.CompoundFilter;
|
||||
import com.arsdigita.persistence.Filter;
|
||||
import com.arsdigita.persistence.FilterFactory;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.SessionManager;
|
||||
|
|
@ -29,6 +30,7 @@ import com.arsdigita.domain.DomainObjectFactory;
|
|||
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.Folder;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.OptionBuilder;
|
||||
|
|
@ -56,6 +58,13 @@ public class BulkUnpublish extends Program {
|
|||
.withLongOpt( "types" )
|
||||
.withDescription( "Restrict unpublishing to items of the specified content types" )
|
||||
.create( "t" ) );
|
||||
options.addOption(
|
||||
OptionBuilder
|
||||
.hasArg()
|
||||
.withLongOpt( "restrictToFolderId" )
|
||||
.withDescription( "Restrict publishing to items within the folder with the specified id" )
|
||||
.create( "f" ) );
|
||||
|
||||
options.addOption
|
||||
(OptionBuilder
|
||||
.hasArg(false)
|
||||
|
|
@ -65,6 +74,7 @@ public class BulkUnpublish extends Program {
|
|||
}
|
||||
|
||||
protected void doRun(CommandLine cmdLine) {
|
||||
final int folderId;
|
||||
final String[] types;
|
||||
final boolean ignoreErrors = cmdLine.hasOption("i");
|
||||
|
||||
|
|
@ -79,6 +89,13 @@ public class BulkUnpublish extends Program {
|
|||
types = null;
|
||||
System.out.println( "Unpublishing all live items" );
|
||||
}
|
||||
if (cmdLine.hasOption("f")) {
|
||||
folderId = Integer.parseInt(cmdLine.getOptionValue("f"));
|
||||
Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, folderId));
|
||||
System.out.println( "Unpublishing items in folder: " + folder.getDisplayName());
|
||||
} else {
|
||||
folderId = -1;
|
||||
}
|
||||
|
||||
final List toUnpublish = new ArrayList();
|
||||
new Transaction() {
|
||||
|
|
@ -89,12 +106,17 @@ public class BulkUnpublish extends Program {
|
|||
items.addEqualsFilter("version", ContentItem.LIVE);
|
||||
items.addOrder("title");
|
||||
|
||||
FilterFactory filterFactory = items.getFilterFactory();
|
||||
|
||||
if (folderId >= 0) {
|
||||
Filter filter = filterFactory.simple(" ancestors like '%/" + folderId + "/%'");
|
||||
items.addFilter(filter);
|
||||
}
|
||||
if( null != types ) {
|
||||
FilterFactory ff = items.getFilterFactory();
|
||||
CompoundFilter or = ff.or();
|
||||
CompoundFilter or = filterFactory.or();
|
||||
|
||||
for( int i = 0; i < types.length; i++ ) {
|
||||
or.addFilter( ff.equals( "objectType", types[i] ) );
|
||||
or.addFilter( filterFactory.equals( "objectType", types[i] ) );
|
||||
}
|
||||
|
||||
items.addFilter( or );
|
||||
|
|
|
|||
Loading…
Reference in New Issue