/**
 * Copyright (C) 2015 Thiago Moreira (tmoreira2020@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package br.com.thiagomoreira.liferay.plugins.fixvirtualhost;

import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Company;
import com.liferay.portal.service.CompanyLocalServiceUtil;

/**
 * @author Thiago Moreira
 */
public class FixVirtualHostAction extends SimpleAction {

	@Override
	public void run(String[] ids) throws ActionException {
		try {
			doRun(GetterUtil.getLong(ids[0]));
		} catch (Exception e) {
			throw new ActionException(e);
		}
	}

	private void doRun(long companyId) throws Exception {
		String liferayVirtualHost = PropsUtil.get("liferay.virtual.host");

		if (Validator.isNotNull(liferayVirtualHost)) {
			Company company = CompanyLocalServiceUtil.getCompany(companyId);

			String virtualHost = company.getVirtualHostname();
			if (!virtualHost.equals(liferayVirtualHost)) {
				CompanyLocalServiceUtil.updateCompany(companyId, liferayVirtualHost,
						company.getMx(), company.getMaxUsers(),
						company.getActive());
			}
		}
	}
}
@@ -794,24 +794,119 @@
 mpleAction;%0A
+import com.liferay.portal.kernel.log.Log;%0Aimport com.liferay.portal.kernel.log.LogFactoryUtil;%0A
 import com.l
@@ -939,24 +939,24 @@
 GetterUtil;%0A
-
 import com.l
@@ -1234,16 +1234,94 @@
 tion %7B%0A%0A
+%09private static Log log = LogFactoryUtil.getLog(FixVirtualHostAction.class);%0A%0A
 %09@Overri
@@ -1839,16 +1839,82 @@
 ost)) %7B%0A
+%09%09%09%09log.info(%22Updating virtual host to: %22 + liferayVirtualHost);%0A%0A
 %09%09%09%09Comp
@@ -1957,17 +1957,23 @@
 mpanyId,
- 
+%0A%09%09%09%09%09%09
 liferayV
@@ -1983,23 +1983,17 @@
 ualHost,
-%0A%09%09%09%09%09%09
+ 
 company.
@@ -2000,17 +2000,23 @@
 getMx(),
- 
+%0A%09%09%09%09%09%09
 company.
@@ -2029,23 +2029,17 @@
 Users(),
-%0A%09%09%09%09%09%09
+ 
 company.
@@ -2056,16 +2056,224 @@
 ));%0A%09%09%09%7D
+ else %7B%0A%09%09%09%09log.info(%22System property 'liferay.virtual.host' and virtual host has the same value: %22%0A%09%09%09%09%09%09+ liferayVirtualHost);%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09log.info(%22System property 'liferay.virtual.host' is empty%22);
 %0A%09%09%7D%0A%09%7D%0A

Add logging messages