From c757188e00f445e09da09b0eaae9945acca5285c Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 22 Mar 2012 12:59:33 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20f=C3=BCr=20Bug=20beim=20Publizieren=20von?= =?UTF-8?q?=20Bundle-Instanzen.=20Achtung:=20Nicht=20abschlie=C3=9Fend=20g?= =?UTF-8?q?etestet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1544 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/cms/ContentItem.java | 81 +++++------ .../GenericContactPersonAssocUpgrade.java | 5 +- .../src/org/undp/weblog/Initializer.java | 135 +++++++++--------- 3 files changed, 113 insertions(+), 108 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/ContentItem.java b/ccm-cms/src/com/arsdigita/cms/ContentItem.java index b948801ab..8f5991dbb 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentItem.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentItem.java @@ -617,8 +617,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy { * * The item's root is the ancestor reachable through repeated * getParent() calls whose parent is - * null. This is usually a folder, but may be any - * { + * null. This is usually a folder, but may be any { * * @see com.arsdigita.kernel.ACSObject}. * @@ -1173,7 +1172,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy { save(); PublishedLink.updateLiveLinks(version); - PublishedAssociation.updateLiveAssoications(version); + PublishedAssociation.updateLiveAssociations(version); save(); // publish item (as template or html pages) to the file @@ -1884,50 +1883,52 @@ public class ContentItem extends VersionedACSObject implements CustomCopy { == ItemCopier.VERSION_COPY) { if (parent instanceof ContentBundle) { - ContentBundle bundle = (ContentBundle) parent; - ContentBundle liveBundle = (ContentBundle) bundle. + final ContentBundle bundle = (ContentBundle) parent; + final ContentBundle oldLiveBundle = (ContentBundle) bundle. getPublicVersion(); //jensp 2012-03-07 Changes to the ContentBundle were not //published because the ContentBundle was not republished. //Moved the next lines out of the if below to enable //republishing of the ContentBundle - liveBundle = - (ContentBundle) bundle.createPendingVersion(null); - if (liveBundle == null) { - } else { - Set liveCatSet = new HashSet(); - Set draftCatSet = new HashSet(); - - CategoryCollection liveCategories = - liveBundle.getCategoryCollection(); - while (liveCategories.next()) { - liveCatSet.add(liveCategories.getCategory()); + final ContentBundle liveBundle = + (ContentBundle) bundle. + createPendingVersion(null); + /* + * if (liveBundle == null) { } else { Set liveCatSet = new + * HashSet(); Set draftCatSet = new HashSet(); + * + * CategoryCollection liveCategories = + * liveBundle.getCategoryCollection(); while + * (liveCategories.next()) { + * liveCatSet.add(liveCategories.getCategory()); } + * liveCategories.close(); + * + * CategoryCollection draftCategories = + * bundle.getCategoryCollection(); while + * (draftCategories.next()) { + * draftCatSet.add(draftCategories.getCategory()); } + * draftCategories.close(); + * + * Set catsToRemove = new HashSet(liveCatSet); + * catsToRemove.removeAll(draftCatSet); Set catsToAdd = new + * HashSet(draftCatSet); catsToAdd.removeAll(liveCatSet); + * + * Iterator removeIter = catsToRemove.iterator(); while + * (removeIter.hasNext()) { liveBundle.removeCategory( + * (Category) removeIter.next()); } Iterator addIter = + * catsToAdd.iterator(); while (addIter.hasNext()) { + * liveBundle.addCategory((Category) addIter.next()); } + * + * } + */ + if (oldLiveBundle != null) { + final ItemCollection instances = oldLiveBundle. + getInstances(); + while (instances.next()) { + liveBundle.addInstance(instances.getContentItem()); } - liveCategories.close(); - - CategoryCollection draftCategories = - bundle.getCategoryCollection(); - while (draftCategories.next()) { - draftCatSet.add(draftCategories.getCategory()); - } - draftCategories.close(); - - Set catsToRemove = new HashSet(liveCatSet); - catsToRemove.removeAll(draftCatSet); - Set catsToAdd = new HashSet(draftCatSet); - catsToAdd.removeAll(liveCatSet); - - Iterator removeIter = catsToRemove.iterator(); - while (removeIter.hasNext()) { - liveBundle.removeCategory( - (Category) removeIter.next()); - } - Iterator addIter = catsToAdd.iterator(); - while (addIter.hasNext()) { - liveBundle.addCategory((Category) addIter.next()); - } - } + setBundle(liveBundle); return true; } else if (parent instanceof Folder) { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactPersonAssocUpgrade.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactPersonAssocUpgrade.java index f1d0a7a7a..2bb8fed13 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactPersonAssocUpgrade.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactPersonAssocUpgrade.java @@ -429,7 +429,8 @@ public class GenericContactPersonAssocUpgrade extends Program { try { conn.rollback(); } catch (SQLException ex1) { - System.out.println("Rollback failed."); + System.err.println("Rollback failed."); + ex1.printStackTrace(System.err); } } @@ -437,7 +438,7 @@ public class GenericContactPersonAssocUpgrade extends Program { try { conn.close(); } catch (SQLException ex) { - System.err.println("Failed to close JDBC connectio."); + System.err.println("Failed to close JDBC connection."); printStackTrace(ex); } } diff --git a/ccm-weblog/src/org/undp/weblog/Initializer.java b/ccm-weblog/src/org/undp/weblog/Initializer.java index bb07f75d6..5bfc83e63 100755 --- a/ccm-weblog/src/org/undp/weblog/Initializer.java +++ b/ccm-weblog/src/org/undp/weblog/Initializer.java @@ -27,93 +27,96 @@ import com.arsdigita.web.ApplicationType; /** * @author Peter Kopunec */ - public class Initializer extends CompoundInitializer { - private static final Logger s_log = Logger.getLogger(Initializer.class); + private static final Logger s_log = Logger.getLogger(Initializer.class); //ublic Initializer() throws InitializationException { - public Initializer() { - final String url = RuntimeConfig.getConfig().getJDBCURL(); - final int database = DbHelper.getDatabaseFromURL(url); + public Initializer() { + final String url = RuntimeConfig.getConfig().getJDBCURL(); + final int database = DbHelper.getDatabaseFromURL(url); - add(new PDLInitializer(new ManifestSource("ccm-weblog.pdl.mf", - new NameFilter(DbHelper.getDatabaseSuffix(database), "pdl")))); - } + add(new PDLInitializer(new ManifestSource("ccm-weblog.pdl.mf", + new NameFilter(DbHelper. + getDatabaseSuffix(database), "pdl")))); + } @Override - public void init(DomainInitEvent e) { - s_log.info("WebLog Initializer starting."); + public void init(DomainInitEvent e) { + s_log.info("WebLog Initializer starting."); - boolean isMyTransaction = false; - TransactionContext txn = SessionManager.getSession() - .getTransactionContext(); - if (!txn.inTxn()) { - txn.beginTxn(); - isMyTransaction = true; - } + boolean isMyTransaction = false; + TransactionContext txn = SessionManager.getSession(). + getTransactionContext(); + if (!txn.inTxn()) { + txn.beginTxn(); + isMyTransaction = true; + } + + // register application + DomainObjectInstantiator instantiator = new ACSObjectInstantiator() { - // register application - DomainObjectInstantiator instantiator = new ACSObjectInstantiator() { @Override - protected DomainObject doNewInstance(DataObject dataObject) { - return new WebLogApplication(dataObject); - } - }; - DomainObjectFactory.registerInstantiator( - WebLogApplication.BASE_DATA_OBJECT_TYPE, instantiator); - checkSetup(); + protected DomainObject doNewInstance(DataObject dataObject) { + return new WebLogApplication(dataObject); + } + }; + DomainObjectFactory.registerInstantiator( + WebLogApplication.BASE_DATA_OBJECT_TYPE, instantiator); + checkSetup(); + + // Register the portlets + instantiator = new ACSObjectInstantiator() { - // Register the portlets - instantiator = new ACSObjectInstantiator() { @Override - protected DomainObject doNewInstance(DataObject dataObject) { - return new WebLogPortlet(dataObject); - } - }; - DomainObjectFactory.registerInstantiator( - WebLogPortlet.BASE_DATA_OBJECT_TYPE, instantiator); + protected DomainObject doNewInstance(DataObject dataObject) { + return new WebLogPortlet(dataObject); + } + }; + DomainObjectFactory.registerInstantiator( + WebLogPortlet.BASE_DATA_OBJECT_TYPE, instantiator); - if (isMyTransaction) { - txn.commitTxn(); - } + if (isMyTransaction) { + txn.commitTxn(); + } - s_log.debug("WebLog Initializer done."); - } + s_log.debug("WebLog Initializer done."); + } - private void checkSetup() { - try { - s_log.debug("WebLog Initializer - verifying setup."); - PackageType entityType = PackageType.findByKey("weblog"); - } catch (DataObjectNotFoundException e) { - setup(); - } - } + private void checkSetup() { + try { + s_log.debug("WebLog Initializer - verifying setup."); + PackageType entityType = PackageType.findByKey("weblog"); + } catch (DataObjectNotFoundException e) { + setup(); + } + } - private void setup() { - s_log.info("WebLog Initializer - setting up new package"); + private void setup() { + s_log.info("WebLog Initializer - setting up new package"); - PackageType entityType = PackageType.create("weblog", "WebLog", - "WebLogs", "http://www.undp.org/weblog"); - s_log.debug("Just added package type WebLog "); + PackageType entityType = PackageType.create("weblog", "WebLog", + "WebLogs", + "http://www.undp.org/weblog"); + s_log.debug("Just added package type WebLog "); - entityType.setDispatcherClass(WebLogDispatcher.class.getName()); + entityType.setDispatcherClass(WebLogDispatcher.class.getName()); - entityType.save(); + entityType.save(); - final ApplicationType entityAppType = ApplicationType - .createApplicationType(entityType, "WebLog Application", - WebLogApplication.BASE_DATA_OBJECT_TYPE); - entityAppType.save(); + final ApplicationType entityAppType = ApplicationType. + createApplicationType(entityType, "WebLog Application", + WebLogApplication.BASE_DATA_OBJECT_TYPE); + entityAppType.save(); - // portlet - AppPortletType portletType = AppPortletType.createAppPortletType( - "WebLog Portlet", AppPortletType.WIDE_PROFILE, - WebLogPortlet.BASE_DATA_OBJECT_TYPE); - portletType.setProviderApplicationType(entityAppType); - portletType.setPortalApplication(true); - portletType.save(); + // portlet + AppPortletType portletType = AppPortletType.createAppPortletType( + "WebLog Portlet", AppPortletType.WIDE_PROFILE, + WebLogPortlet.BASE_DATA_OBJECT_TYPE); + portletType.setProviderApplicationType(entityAppType); + portletType.setPortalApplication(true); + portletType.save(); - } + } }