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;
|
package com.arsdigita.london.util.cmd;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
import com.arsdigita.london.util.Program;
|
import com.arsdigita.london.util.Program;
|
||||||
import com.arsdigita.london.util.Transaction;
|
import com.arsdigita.london.util.Transaction;
|
||||||
import com.arsdigita.persistence.CompoundFilter;
|
import com.arsdigita.persistence.CompoundFilter;
|
||||||
|
|
@ -31,6 +32,7 @@ import com.arsdigita.cms.ContentPage;
|
||||||
import com.arsdigita.cms.ContentItem;
|
import com.arsdigita.cms.ContentItem;
|
||||||
import com.arsdigita.cms.ContentTypeLifecycleDefinition;
|
import com.arsdigita.cms.ContentTypeLifecycleDefinition;
|
||||||
import com.arsdigita.cms.Folder;
|
import com.arsdigita.cms.Folder;
|
||||||
|
import com.arsdigita.cms.installer.xml.ContentBundleHelper;
|
||||||
import com.arsdigita.cms.lifecycle.LifecycleDefinition;
|
import com.arsdigita.cms.lifecycle.LifecycleDefinition;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
|
@ -40,6 +42,7 @@ import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
@ -71,11 +74,15 @@ public class BulkPublish extends Program {
|
||||||
withDescription("The ids of items that shouldn't be published").
|
withDescription("The ids of items that shouldn't be published").
|
||||||
create("e"));
|
create("e"));
|
||||||
|
|
||||||
|
|
||||||
options.addOption(
|
options.addOption(
|
||||||
OptionBuilder.hasArg(false).withLongOpt("ignore-errors").
|
OptionBuilder.hasArg(false).withLongOpt("ignore-errors").
|
||||||
withDescription("Ignore any errors").create('i'));
|
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[] types;
|
||||||
final String[] exceptions;
|
final String[] exceptions;
|
||||||
final int folderId;
|
final int folderId;
|
||||||
|
final String language;
|
||||||
final boolean ignoreErrors = cmdLine.hasOption("i");
|
final boolean ignoreErrors = cmdLine.hasOption("i");
|
||||||
|
|
||||||
if (cmdLine.hasOption("t")) {
|
if (cmdLine.hasOption("t")) {
|
||||||
|
|
@ -120,6 +128,14 @@ public class BulkPublish extends Program {
|
||||||
exceptions = null;
|
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();
|
final List toPublish = new ArrayList();
|
||||||
new Transaction() {
|
new Transaction() {
|
||||||
|
|
||||||
|
|
@ -203,8 +219,26 @@ public class BulkPublish extends Program {
|
||||||
return;
|
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 {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.arsdigita.london.util.cmd;
|
package com.arsdigita.london.util.cmd;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
import com.arsdigita.london.util.Program;
|
import com.arsdigita.london.util.Program;
|
||||||
import com.arsdigita.london.util.Transaction;
|
import com.arsdigita.london.util.Transaction;
|
||||||
import com.arsdigita.persistence.CompoundFilter;
|
import com.arsdigita.persistence.CompoundFilter;
|
||||||
|
|
@ -39,15 +39,16 @@ import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class BulkUnpublish extends Program {
|
public class BulkUnpublish extends Program {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(BulkUnpublish.class);
|
private static final Logger s_log = Logger.getLogger(BulkUnpublish.class);
|
||||||
|
|
||||||
protected int folderId;
|
protected int folderId;
|
||||||
protected String[] types;
|
protected String[] types;
|
||||||
protected boolean ignoreErrors;
|
protected boolean ignoreErrors;
|
||||||
|
protected String language;
|
||||||
|
|
||||||
public BulkUnpublish(String name, String version) {
|
public BulkUnpublish(String name, String version) {
|
||||||
super(name, version, "");
|
super(name, version, "");
|
||||||
|
|
@ -55,56 +56,67 @@ public class BulkUnpublish extends Program {
|
||||||
Options options = getOptions();
|
Options options = getOptions();
|
||||||
|
|
||||||
options.addOption(
|
options.addOption(
|
||||||
OptionBuilder
|
OptionBuilder.hasArgs().withLongOpt("types").withDescription(
|
||||||
.hasArgs()
|
"Restrict operation to items of the specified content types").
|
||||||
.withLongOpt( "types" )
|
create("t"));
|
||||||
.withDescription( "Restrict operation to items of the specified content types" )
|
|
||||||
.create( "t" ) );
|
|
||||||
options.addOption(
|
options.addOption(
|
||||||
OptionBuilder
|
OptionBuilder.hasArg().withLongOpt("restrictToFolderId").
|
||||||
.hasArg()
|
withDescription(
|
||||||
.withLongOpt( "restrictToFolderId" )
|
"Restrict operation to items within the folder with the specified id").
|
||||||
.withDescription( "Restrict operation to items within the folder with the specified id" )
|
create("f"));
|
||||||
.create( "f" ) );
|
|
||||||
|
|
||||||
options.addOption
|
options.addOption(
|
||||||
(OptionBuilder
|
OptionBuilder.hasArg(false).withLongOpt("ignore-errors").
|
||||||
.hasArg(false)
|
withDescription("Ignore any errors").create('i'));
|
||||||
.withLongOpt("ignore-errors")
|
|
||||||
.withDescription("Ignore any errors")
|
options.addOption(
|
||||||
.create('i'));
|
OptionBuilder.hasArg().withLongOpt("language").withDescription(
|
||||||
|
"Restrict publishing to items with the specified langauge").
|
||||||
|
create("l"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doRun(CommandLine cmdLine) {
|
protected void doRun(CommandLine cmdLine) {
|
||||||
this.ignoreErrors = cmdLine.hasOption("i");
|
this.ignoreErrors = cmdLine.hasOption("i");
|
||||||
|
|
||||||
if( cmdLine.hasOption( "t" ) ) {
|
if (cmdLine.hasOption("t")) {
|
||||||
this.types = cmdLine.getOptionValues( "t" );
|
this.types = cmdLine.getOptionValues("t");
|
||||||
|
|
||||||
System.out.println( "To unpublish live items of type:" );
|
System.out.println("To unpublish live items of type:");
|
||||||
for( int i = 0; i < this.types.length; i++ ) {
|
for (int i = 0; i < this.types.length; i++) {
|
||||||
System.out.println( this.types[i] );
|
System.out.println(this.types[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.types = null;
|
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")) {
|
if (cmdLine.hasOption("f")) {
|
||||||
this.folderId = Integer.parseInt(cmdLine.getOptionValue("f"));
|
this.folderId = Integer.parseInt(cmdLine.getOptionValue("f"));
|
||||||
Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, this.folderId));
|
Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE,
|
||||||
System.out.println( "To unpublish items in folder: " + folder.getDisplayName());
|
this.folderId));
|
||||||
|
System.out.println("To unpublish items in folder: " + folder.
|
||||||
|
getDisplayName());
|
||||||
} else {
|
} else {
|
||||||
System.out.println( "To unpublish items without any folder restriction");
|
System.out.println(
|
||||||
this.folderId = -1;
|
"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.");
|
System.out.println("Processing " + toProcess.size() + " items.");
|
||||||
unpublish(toProcess);
|
unpublish(toProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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) {
|
protected List getListToProcess(final String baseObjectType) {
|
||||||
|
|
@ -113,29 +125,36 @@ public class BulkUnpublish extends Program {
|
||||||
final String[] types = this.types;
|
final String[] types = this.types;
|
||||||
|
|
||||||
new Transaction() {
|
new Transaction() {
|
||||||
|
|
||||||
public void doRun() {
|
public void doRun() {
|
||||||
DataCollection items = SessionManager.getSession().retrieve(baseObjectType);
|
DataCollection items = SessionManager.getSession().retrieve(
|
||||||
if(! baseObjectType.equals(Folder.BASE_DATA_OBJECT_TYPE)) items.addNotEqualsFilter("type.id", null);
|
baseObjectType);
|
||||||
|
if (!baseObjectType.equals(Folder.BASE_DATA_OBJECT_TYPE)) {
|
||||||
|
items.addNotEqualsFilter("type.id", null);
|
||||||
|
}
|
||||||
//items.addOrder("title");
|
//items.addOrder("title");
|
||||||
|
|
||||||
FilterFactory filterFactory = items.getFilterFactory();
|
FilterFactory filterFactory = items.getFilterFactory();
|
||||||
|
|
||||||
if (folderId >= 0) { //TODO could add logic to fetch master version if required.
|
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);
|
items.addFilter(filter);
|
||||||
}
|
}
|
||||||
if( null != types ) {
|
if (null != types) {
|
||||||
CompoundFilter or = filterFactory.or();
|
CompoundFilter or = filterFactory.or();
|
||||||
|
|
||||||
for( int i = 0; i < types.length; i++ ) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
or.addFilter( filterFactory.equals( "objectType", types[i] ) );
|
or.addFilter(
|
||||||
|
filterFactory.equals("objectType", types[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
items.addFilter( or );
|
items.addFilter(or);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (items.next()) {
|
while (items.next()) {
|
||||||
ContentItem page = (ContentItem) DomainObjectFactory.newInstance(items.getDataObject());
|
ContentItem page = (ContentItem) DomainObjectFactory.
|
||||||
|
newInstance(items.getDataObject());
|
||||||
toProcess.add(page.getDraftVersion().getOID());
|
toProcess.add(page.getDraftVersion().getOID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -153,23 +172,34 @@ public class BulkUnpublish extends Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unpublish(final OID oid) {
|
protected void unpublish(final OID oid) {
|
||||||
final boolean ignoreErrors = this.ignoreErrors;
|
final boolean ignoreErrors = this.ignoreErrors;
|
||||||
|
|
||||||
Transaction txn = new Transaction() {
|
Transaction txn = new Transaction() {
|
||||||
public void doRun() {
|
|
||||||
ContentItem item = (ContentItem)
|
public void doRun() {
|
||||||
DomainObjectFactory.newInstance(oid);
|
ContentPage item = (ContentPage) DomainObjectFactory.newInstance(
|
||||||
System.out.println("Unpublishing item " + oid + " " + item.getPath());
|
oid);
|
||||||
item.setLive(null);
|
ContentBundle bundle = item.getContentBundle();
|
||||||
}
|
Collection<String> langs = bundle.getLanguages();
|
||||||
};
|
for (String lang : langs) {
|
||||||
try {
|
if ((language == null)
|
||||||
txn.run();
|
|| language.isEmpty()
|
||||||
} catch (Throwable ex) {
|
|| lang.equals(language)) {
|
||||||
s_log.error("Cannot unpublish " + oid, ex);
|
ContentItem toUnPublish = bundle.getInstance(lang);
|
||||||
if (!ignoreErrors) {
|
System.out.println("Unpublishing item " + oid + " " + toUnPublish.
|
||||||
return;
|
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