From e8c10aa33e155fbcd40484c11d89ef72b6b3a266 Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 18 Apr 2011 09:23:52 +0000 Subject: [PATCH] =?UTF-8?q?BulkPublish=20und=20BulkUnpublish=20kommen=20je?= =?UTF-8?q?tzt=20mit=20mehreren=20Sprachversionen=20klar.=20=C3=9Cber=20de?= =?UTF-8?q?n=20Parameter=20-l=20kann=20optional=20angeben=20werden,=20das?= =?UTF-8?q?=20Items=20nur=20einer=20bestimmten=20Sprache=20publizert=20wer?= =?UTF-8?q?den=20sollen.=20Wenn=20keine=20Sprache=20angegeben=20ist,=20wer?= =?UTF-8?q?den=20alle=20Sprachversionen=20publiziert.=20Achtung:=20BulkUnp?= =?UTF-8?q?ublish=20ist=20*nicht*=20getestet!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@864 8810af33-2d31-482b-a856-94f89814c4df --- .../london/util/cmd/BulkPublish.java | 40 +++++- .../london/util/cmd/BulkUnpublish.java | 136 +++++++++++------- 2 files changed, 120 insertions(+), 56 deletions(-) diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java index ec27932ce..ad5ac6ce3 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java @@ -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 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 { diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java index dbc4f93e2..9a2e48dc4 100644 --- a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java @@ -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 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; + } + } } }