/* * Copyright (C) 2011 Peter Boy . All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * 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.cms.upgrade; import com.arsdigita.cms.Loader; import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.KernelExcursion; import com.arsdigita.kernel.PackageInstance; import com.arsdigita.kernel.PackageInstanceCollection; import com.arsdigita.kernel.PackageType; import com.arsdigita.kernel.Resource; import com.arsdigita.kernel.ResourceType; import com.arsdigita.util.cmd.Program; import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.TransactionContext; import com.arsdigita.util.StringUtils; import com.arsdigita.web.Application; import com.arsdigita.web.ApplicationType; import org.apache.commons.cli.CommandLine; import org.apache.log4j.Logger; /** * Update from CCM version 6.6.1 to 6.6.2 where loader has been refactored to * use (new style) applications in package com.arsdigita.web instead of old * style applications using com.arsdigita.kermel.[Package* & SiteNode]. * * Affected are the packages CMS Workspace and Service. They are now loaded * using new style application classes Workspace and Service. * * The task at hand is to add the necessary table entries for CMS Workspace and * Service to the tables application_types and applications using the * information already existing (by old style initialization) in * apm_package_types, site_nodes, and apm_packages. * * @author pb */ public class AddNewStyleApplicationEntries extends Program { private static Logger s_log = Logger.getLogger(CreateGenericContentTypes.class); /** /* Constructor constructs a program object which initializes the CCM * runtime system and enables concatenation, so a following SQL script * may be executed. */ public AddNewStyleApplicationEntries() { super("AddNewStyleApplicationEntries", "1.0.0", "",true,true); } /** * The mandatory main method * @param args */ public static void main(final String[] args) { new AddNewStyleApplicationEntries().run(args); } /** * Worker method. Adds new style application entries. * * @param cmdLine */ public void doRun(CommandLine cmdLine) { new KernelExcursion() { public void excurse() { setEffectiveParty(Kernel.getSystemParty()); final Session session = SessionManager.getSession(); final TransactionContext tc = session.getTransactionContext(); tc.beginTxn(); // Update CMS Workspace ApplicationType appType = null; appType = Loader.loadContentCenterApplicationType(); // get corresponding package type PackageType packageType = PackageType.findByKey("content-center"); // get all installed instances PackageInstanceCollection allPackages = packageType .getInstances(); PackageInstance aPackage = null ; Resource res = null; Application app = null; while ( allPackages.next() ) { aPackage = allPackages.getPackageInstance(); res = Resource.createResource((ResourceType)appType, aPackage.getDisplayName(), null); res.setDescription("The default CMS workspace instance."); res.save(); app = Application.retrieveApplication(res.getOID()); app.setPath("/"+StringUtils.urlize(app.getTitle())+"/"); // unfortunately there seems to be no way to set the // assoziation to PackageInstance. So we must do that by // SQL magic } // Update CMS Service appType = null; appType = Loader.loadServiceApplicationType(); // get corresponding package type packageType = PackageType.findByKey("cms-service"); // get all installed instances allPackages = packageType.getInstances(); aPackage = null ; res = null; app = null; while ( allPackages.next() ) { aPackage = allPackages.getPackageInstance(); res = Resource.createResource((ResourceType)appType, aPackage.getDisplayName(), null); res.setDescription("The default CMS service instance."); res.save(); app = Application.retrieveApplication(res.getOID()); app.setPath("/"+StringUtils.urlize(app.getTitle())+"/"); // unfortunately there seems to be no way to set the // assoziation to PackageInstance. So we must do that by // SQL magic } tc.commitTxn(); } }.run(); } }