/** * Copyright (c) 2000-present Liferay, Inc. 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. */ package com.liferay.akismet.servlet; import com.liferay.expando.kernel.model.ExpandoColumnConstants; import com.liferay.expando.kernel.model.ExpandoTable; import com.liferay.expando.kernel.model.ExpandoTableConstants; import com.liferay.expando.kernel.service.ExpandoColumnLocalServiceUtil; import com.liferay.expando.kernel.service.ExpandoTableLocalServiceUtil; import com.liferay.message.boards.kernel.model.MBMessage; import com.liferay.portal.kernel.model.Company; import com.liferay.portal.kernel.service.CompanyLocalServiceUtil; import com.liferay.portal.kernel.util.BasePortalLifecycle; import java.util.List; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; /** * @author Amos Fong */ public class AkismetServletContextListener extends BasePortalLifecycle implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { portalDestroy(); } @Override public void contextInitialized(ServletContextEvent servletContextEvent) { registerPortalLifecycle(); } @Override protected void doPortalDestroy() { } @Override protected void doPortalInit() throws Exception { List<Company> companies = CompanyLocalServiceUtil.getCompanies(); for (Company company : companies) { setupExpandos(company.getCompanyId()); } } protected void setupExpandos(long companyId) throws Exception { ExpandoTable expandoTable = null; try { expandoTable = ExpandoTableLocalServiceUtil.getTable( companyId, MBMessage.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME); } catch (Exception e) { expandoTable = ExpandoTableLocalServiceUtil.addTable( companyId, MBMessage.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME); } try { ExpandoColumnLocalServiceUtil.addColumn( expandoTable.getTableId(), "akismetContentURL", ExpandoColumnConstants.STRING); } catch (Exception e) { } } }