001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.threads; 029 030import org.opencms.file.CmsObject; 031import org.opencms.main.CmsLog; 032import org.opencms.main.OpenCms; 033import org.opencms.module.CmsModuleManager; 034import org.opencms.report.A_CmsReportThread; 035import org.opencms.report.I_CmsReport; 036 037import java.util.Collections; 038import java.util.Iterator; 039import java.util.List; 040 041import org.apache.commons.logging.Log; 042 043/** 044 * Deletes a module.<p> 045 * 046 * @since 6.0.0 047 */ 048public class CmsModuleDeleteThread extends A_CmsReportThread { 049 050 /** The log object for this class. */ 051 private static final Log LOG = CmsLog.getLog(CmsModuleDeleteThread.class); 052 053 /** A list of module name to delete. */ 054 private List<String> m_moduleNames; 055 056 /** mode indicating if pre-replacement or final deletion. */ 057 private boolean m_replaceMode; 058 059 /** 060 * Creates the module delete thread.<p> 061 * 062 * @param cms the current cms context 063 * @param moduleNames the name of the module 064 * @param replaceMode the replace mode 065 */ 066 public CmsModuleDeleteThread(CmsObject cms, List<String> moduleNames, boolean replaceMode) { 067 068 super(cms, Messages.get().getBundle().key(Messages.GUI_DELETE_MODULE_THREAD_NAME_1, moduleNames)); 069 m_moduleNames = moduleNames; 070 m_replaceMode = replaceMode; 071 initHtmlReport(cms.getRequestContext().getLocale()); 072 if (LOG.isDebugEnabled()) { 073 LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_CONSTRUCTED_0)); 074 } 075 } 076 077 /** 078 * @see org.opencms.report.A_CmsReportThread#getReportUpdate() 079 */ 080 @Override 081 public String getReportUpdate() { 082 083 return getReport().getReportUpdate(); 084 } 085 086 /** 087 * @see java.lang.Runnable#run() 088 */ 089 @Override 090 public void run() { 091 092 I_CmsReport report = getReport(); 093 boolean indexingAlreadyPaused = OpenCms.getSearchManager().isOfflineIndexingPaused(); 094 try { 095 if (!indexingAlreadyPaused) { 096 OpenCms.getSearchManager().pauseOfflineIndexing(); 097 } 098 if (LOG.isDebugEnabled()) { 099 LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_STARTED_0)); 100 } 101 if (!m_replaceMode) { 102 OpenCms.getModuleManager().checkModuleSelectionList(m_moduleNames, null, true); 103 } 104 m_moduleNames = CmsModuleManager.topologicalSort(m_moduleNames, null); 105 Collections.reverse(m_moduleNames); 106 107 Iterator<String> j = m_moduleNames.iterator(); 108 while (j.hasNext()) { 109 String moduleName = j.next(); 110 111 moduleName = moduleName.replace('\\', '/'); 112 113 // now delete the module 114 OpenCms.getModuleManager().deleteModule(getCms(), moduleName, m_replaceMode, report); 115 } 116 117 if (LOG.isDebugEnabled()) { 118 LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_FINISHED_0)); 119 } 120 } catch (Throwable e) { 121 report.println(e); 122 LOG.error(Messages.get().getBundle().key(Messages.LOG_MODULE_DELETE_FAILED_1, m_moduleNames), e); 123 } finally { 124 if (!indexingAlreadyPaused) { 125 OpenCms.getSearchManager().resumeOfflineIndexing(); 126 } 127 } 128 } 129}