BulkPublish und BulkUnpublish kommen jetzt mit mehreren Sprachversionen klar. Über den Parameter -l kann optional angeben werden, das Items nur einer bestimmten
Sprache publizert werden sollen. Wenn keine Sprache angegeben ist, werden alle Sprachversionen publiziert. Achtung: BulkUnpublish ist *nicht* getestet! git-svn-id: https://svn.libreccm.org/ccm/trunk@864 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
bfef7db7b6
commit
e8c10aa33e
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package com.arsdigita.london.util.cmd;
|
||||
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.london.util.Program;
|
||||
import com.arsdigita.london.util.Transaction;
|
||||
import com.arsdigita.persistence.CompoundFilter;
|
||||
|
|
@ -31,6 +32,7 @@ import com.arsdigita.cms.ContentPage;
|
|||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentTypeLifecycleDefinition;
|
||||
import com.arsdigita.cms.Folder;
|
||||
import com.arsdigita.cms.installer.xml.ContentBundleHelper;
|
||||
import com.arsdigita.cms.lifecycle.LifecycleDefinition;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
|
|
@ -40,6 +42,7 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -71,11 +74,15 @@ public class BulkPublish extends Program {
|
|||
withDescription("The ids of items that shouldn't be published").
|
||||
create("e"));
|
||||
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.hasArg(false).withLongOpt("ignore-errors").
|
||||
withDescription("Ignore any errors").create('i'));
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.hasArg().withLongOpt("language").withDescription(
|
||||
"Restrict publishing to items with the specified langauge").
|
||||
create("l"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,6 +93,7 @@ public class BulkPublish extends Program {
|
|||
final String[] types;
|
||||
final String[] exceptions;
|
||||
final int folderId;
|
||||
final String language;
|
||||
final boolean ignoreErrors = cmdLine.hasOption("i");
|
||||
|
||||
if (cmdLine.hasOption("t")) {
|
||||
|
|
@ -120,6 +128,14 @@ public class BulkPublish extends Program {
|
|||
exceptions = null;
|
||||
}
|
||||
|
||||
if (cmdLine.hasOption("l")) {
|
||||
language = cmdLine.getOptionValue("l");
|
||||
System.out.printf("Publishing only items with language: %s\n",
|
||||
language);
|
||||
} else {
|
||||
language = null;
|
||||
}
|
||||
|
||||
final List toPublish = new ArrayList();
|
||||
new Transaction() {
|
||||
|
||||
|
|
@ -203,8 +219,26 @@ public class BulkPublish extends Program {
|
|||
return;
|
||||
}
|
||||
|
||||
ContentItem pending = item.publish(def, new Date());
|
||||
pending.getLifecycle().start();
|
||||
/*
|
||||
* Fix by jensp 2011-04-18: Bulk publish was aware of
|
||||
* content bundles and different languages...
|
||||
*/
|
||||
ContentBundle bundle = item.getContentBundle();
|
||||
Collection<String> langs = bundle.getLanguages();
|
||||
for (String lang : langs) {
|
||||
if ((language == null)
|
||||
|| language.isEmpty()
|
||||
|| lang.equals(language)) {
|
||||
ContentItem toPublish = bundle.getInstance(lang);
|
||||
ContentItem pending = toPublish.publish(def,
|
||||
new Date());
|
||||
pending.getLifecycle().start();
|
||||
}
|
||||
}
|
||||
|
||||
//ContentItem pending = item.publish(def, new Date());
|
||||
|
||||
//pending.getLifecycle().start();
|
||||
}
|
||||
};
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.arsdigita.london.util.cmd;
|
||||
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.london.util.Program;
|
||||
import com.arsdigita.london.util.Transaction;
|
||||
import com.arsdigita.persistence.CompoundFilter;
|
||||
|
|
@ -39,15 +39,16 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BulkUnpublish extends Program {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(BulkUnpublish.class);
|
||||
|
||||
protected int folderId;
|
||||
protected String[] types;
|
||||
protected boolean ignoreErrors;
|
||||
protected String language;
|
||||
|
||||
public BulkUnpublish(String name, String version) {
|
||||
super(name, version, "");
|
||||
|
|
@ -55,56 +56,67 @@ public class BulkUnpublish extends Program {
|
|||
Options options = getOptions();
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder
|
||||
.hasArgs()
|
||||
.withLongOpt( "types" )
|
||||
.withDescription( "Restrict operation to items of the specified content types" )
|
||||
.create( "t" ) );
|
||||
OptionBuilder.hasArgs().withLongOpt("types").withDescription(
|
||||
"Restrict operation to items of the specified content types").
|
||||
create("t"));
|
||||
options.addOption(
|
||||
OptionBuilder
|
||||
.hasArg()
|
||||
.withLongOpt( "restrictToFolderId" )
|
||||
.withDescription( "Restrict operation to items within the folder with the specified id" )
|
||||
.create( "f" ) );
|
||||
OptionBuilder.hasArg().withLongOpt("restrictToFolderId").
|
||||
withDescription(
|
||||
"Restrict operation to items within the folder with the specified id").
|
||||
create("f"));
|
||||
|
||||
options.addOption
|
||||
(OptionBuilder
|
||||
.hasArg(false)
|
||||
.withLongOpt("ignore-errors")
|
||||
.withDescription("Ignore any errors")
|
||||
.create('i'));
|
||||
options.addOption(
|
||||
OptionBuilder.hasArg(false).withLongOpt("ignore-errors").
|
||||
withDescription("Ignore any errors").create('i'));
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.hasArg().withLongOpt("language").withDescription(
|
||||
"Restrict publishing to items with the specified langauge").
|
||||
create("l"));
|
||||
}
|
||||
|
||||
protected void doRun(CommandLine cmdLine) {
|
||||
this.ignoreErrors = cmdLine.hasOption("i");
|
||||
|
||||
if( cmdLine.hasOption( "t" ) ) {
|
||||
this.types = cmdLine.getOptionValues( "t" );
|
||||
if (cmdLine.hasOption("t")) {
|
||||
this.types = cmdLine.getOptionValues("t");
|
||||
|
||||
System.out.println( "To unpublish live items of type:" );
|
||||
for( int i = 0; i < this.types.length; i++ ) {
|
||||
System.out.println( this.types[i] );
|
||||
System.out.println("To unpublish live items of type:");
|
||||
for (int i = 0; i < this.types.length; i++) {
|
||||
System.out.println(this.types[i]);
|
||||
}
|
||||
} else {
|
||||
this.types = null;
|
||||
System.out.println( "To unpublish without item type restriction" );
|
||||
System.out.println("To unpublish without item type restriction");
|
||||
}
|
||||
if (cmdLine.hasOption("f")) {
|
||||
this.folderId = Integer.parseInt(cmdLine.getOptionValue("f"));
|
||||
Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, this.folderId));
|
||||
System.out.println( "To unpublish items in folder: " + folder.getDisplayName());
|
||||
Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE,
|
||||
this.folderId));
|
||||
System.out.println("To unpublish items in folder: " + folder.
|
||||
getDisplayName());
|
||||
} else {
|
||||
System.out.println( "To unpublish items without any folder restriction");
|
||||
this.folderId = -1;
|
||||
System.out.println(
|
||||
"To unpublish items without any folder restriction");
|
||||
this.folderId = -1;
|
||||
}
|
||||
|
||||
final List toProcess = getListToProcess(ContentPage.BASE_DATA_OBJECT_TYPE);
|
||||
if (cmdLine.hasOption("l")) {
|
||||
language = cmdLine.getOptionValue("l");
|
||||
System.out.printf("Publishing only items with language: %s\n",
|
||||
language);
|
||||
} else {
|
||||
language = null;
|
||||
}
|
||||
|
||||
final List toProcess = getListToProcess(
|
||||
ContentPage.BASE_DATA_OBJECT_TYPE);
|
||||
System.out.println("Processing " + toProcess.size() + " items.");
|
||||
unpublish(toProcess);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BulkUnpublish("Bulk Unpublish","1.0.0").run(args);
|
||||
new BulkUnpublish("Bulk Unpublish", "1.0.0").run(args);
|
||||
}
|
||||
|
||||
protected List getListToProcess(final String baseObjectType) {
|
||||
|
|
@ -113,29 +125,36 @@ public class BulkUnpublish extends Program {
|
|||
final String[] types = this.types;
|
||||
|
||||
new Transaction() {
|
||||
|
||||
public void doRun() {
|
||||
DataCollection items = SessionManager.getSession().retrieve(baseObjectType);
|
||||
if(! baseObjectType.equals(Folder.BASE_DATA_OBJECT_TYPE)) items.addNotEqualsFilter("type.id", null);
|
||||
DataCollection items = SessionManager.getSession().retrieve(
|
||||
baseObjectType);
|
||||
if (!baseObjectType.equals(Folder.BASE_DATA_OBJECT_TYPE)) {
|
||||
items.addNotEqualsFilter("type.id", null);
|
||||
}
|
||||
//items.addOrder("title");
|
||||
|
||||
FilterFactory filterFactory = items.getFilterFactory();
|
||||
|
||||
if (folderId >= 0) { //TODO could add logic to fetch master version if required.
|
||||
Filter filter = filterFactory.simple(" ancestors like '%/" + folderId + "/%'");
|
||||
Filter filter = filterFactory.simple(" ancestors like '%/"
|
||||
+ folderId + "/%'");
|
||||
items.addFilter(filter);
|
||||
}
|
||||
if( null != types ) {
|
||||
if (null != types) {
|
||||
CompoundFilter or = filterFactory.or();
|
||||
|
||||
for( int i = 0; i < types.length; i++ ) {
|
||||
or.addFilter( filterFactory.equals( "objectType", types[i] ) );
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
or.addFilter(
|
||||
filterFactory.equals("objectType", types[i]));
|
||||
}
|
||||
|
||||
items.addFilter( or );
|
||||
items.addFilter(or);
|
||||
}
|
||||
|
||||
while (items.next()) {
|
||||
ContentItem page = (ContentItem) DomainObjectFactory.newInstance(items.getDataObject());
|
||||
ContentItem page = (ContentItem) DomainObjectFactory.
|
||||
newInstance(items.getDataObject());
|
||||
toProcess.add(page.getDraftVersion().getOID());
|
||||
}
|
||||
}
|
||||
|
|
@ -153,23 +172,34 @@ public class BulkUnpublish extends Program {
|
|||
}
|
||||
|
||||
protected void unpublish(final OID oid) {
|
||||
final boolean ignoreErrors = this.ignoreErrors;
|
||||
final boolean ignoreErrors = this.ignoreErrors;
|
||||
|
||||
Transaction txn = new Transaction() {
|
||||
public void doRun() {
|
||||
ContentItem item = (ContentItem)
|
||||
DomainObjectFactory.newInstance(oid);
|
||||
System.out.println("Unpublishing item " + oid + " " + item.getPath());
|
||||
item.setLive(null);
|
||||
}
|
||||
};
|
||||
try {
|
||||
txn.run();
|
||||
} catch (Throwable ex) {
|
||||
s_log.error("Cannot unpublish " + oid, ex);
|
||||
if (!ignoreErrors) {
|
||||
return;
|
||||
Transaction txn = new Transaction() {
|
||||
|
||||
public void doRun() {
|
||||
ContentPage item = (ContentPage) DomainObjectFactory.newInstance(
|
||||
oid);
|
||||
ContentBundle bundle = item.getContentBundle();
|
||||
Collection<String> langs = bundle.getLanguages();
|
||||
for (String lang : langs) {
|
||||
if ((language == null)
|
||||
|| language.isEmpty()
|
||||
|| lang.equals(language)) {
|
||||
ContentItem toUnPublish = bundle.getInstance(lang);
|
||||
System.out.println("Unpublishing item " + oid + " " + toUnPublish.
|
||||
getPath());
|
||||
item.setLive(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
txn.run();
|
||||
} catch (Throwable ex) {
|
||||
s_log.error("Cannot unpublish " + oid, ex);
|
||||
if (!ignoreErrors) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue