staempfli/magento2-builder-tool

View on GitHub
build/xmlscripts/magento.xml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * magento.xml
 *
 * @copyright Copyright (c) 2016 Staempfli AG
 * @author    juan.alonso@staempfli.com
 */
-->
<project name="Magento" default="..." basedir=".">

    <includepath classpath="${phing.dir}/build/phpscripts/Magento"/>
    <taskdef name="setMagentoConfig" classname="EnsureConfiguration"/>

    <target name="magento:clean:setup"
            depends="magento:install,
            magento:config:set,
            magento:cache:clean"
            hidden="true">

        <echo message="****************************************************************************"/>
        <echo message="Magento has been successfully set up"/>
        <echo message=""/>
        <echo message="Admin frontname: /${magento.admin.frontname}"/>
        <echo message="Admin username: ${install.admin.username}"/>
        <echo message="Admin password: ${install.admin.password}"/>
        <echo message="****************************************************************************"/>

    </target>

    <target name="magento:module:init"
            hidden="true">

        <exec command="${bin.n98-magerun2} module:status | grep -A1 &quot;List of enabled modules:&quot; | tail -n 1"
              checkreturn="true" outputProperty="first.enabled.module"/>
        <if>
            <equals arg1="${first.enabled.module}" arg2="None"/>
            <then>
                <echo message="Enable all Modules"/>
                <exec command="${bin.n98-magerun2} module:enable --all" checkreturn="true" logoutput="true"/>
            </then>
        </if>
    </target>

    <target name="magento:install"
            depends="database:drop,
            database:create,
            magento:module:init"
            hidden="true">

        <customHook hook="before-magento-install"/>

        <echo message=""/>
        <echo message="Installing Magento..."/>

        <property name="command.magento.install" value="${bin.n98-magerun2} setup:install" />
        <property name="params.command.magento.install"
                  value="--backend-frontname=&quot;${magento.admin.frontname}&quot;
                --db-host=&quot;${database.host}&quot;
                --db-name=&quot;${database.name}&quot;
                --db-user=&quot;${database.user}&quot;
                --db-password=&quot;${database.password}&quot;
                --base-url=&quot;http://${project.name}.lo&quot;
                --language=&quot;${install.locale}&quot;
                --timezone=&quot;${install.timezone}&quot;
                --currency=&quot;${install.currency}&quot;
                --admin-firstname=&quot;${install.admin.firstname}&quot;
                --admin-lastname=&quot;${install.admin.lastname}&quot;
                --admin-email=&quot;${install.admin.email}&quot;
                --admin-user=&quot;${install.admin.username}&quot;
                --admin-password=&quot;${install.admin.password}&quot;
                --use-rewrites=1
                --cleanup-database
                ${magento.setup.install.extra.params}"
        />

        <exec command="${command.magento.install} --help" outputProperty="command.magento.install.help.output" checkreturn="true"/>
        <if>
            <contains string="${command.magento.install.help.output}" substring="--no-interaction"/>
            <then>
                <property name="params.command.magento.install" value="${params.command.magento.install} --no-interaction" override="true"/>
            </then>
        </if>

        <exec command="${command.magento.install} ${params.command.magento.install}"
              passthru="true"
              checkreturn="true"
              logoutput="true"
              outputProperty="command.magento.install.output"/>
        <phingcall target="util:check:output">
            <property name="check.output" value="${command.magento.install.output}" override="true"/>
        </phingcall>

        <customHook hook="after-magento-install"/>

    </target>

    <target name="magento:config:set"
            hidden="true">

        <setMagentoConfig/>

    </target>

    <target name="magento:setup:upgrade"
            hidden="true">
        <property name="command.magento.upgrade" value="${bin.n98-magerun2} setup:upgrade" />
        <property name="params.command.magento.upgrade" value=""/>

        <if>
            <equals arg1="${setup.upgrade.keep.generated}" arg2="1"/>
            <then>
                <property name="params.command.magento.upgrade" value="${params.command.magento.upgrade} --keep-generated" override="true"/>
            </then>
        </if>

        <exec command="${command.magento.upgrade} --help" outputProperty="command.magento.upgrade.help.output" checkreturn="true"/>
        <if>
            <contains string="${command.magento.upgrade.help.output}" substring="--no-interaction"/>
            <then>
                <property name="params.command.magento.upgrade" value="${params.command.magento.upgrade} --no-interaction" override="true"/>
            </then>
        </if>

        <echo message="${command.magento.upgrade} ${params.command.magento.upgrade}"/>
        <exec command="${command.magento.upgrade} ${params.command.magento.upgrade}"
              checkreturn="true"
              logoutput="true"
              outputProperty="command.magento.upgrade.output"/>
        <phingcall target="util:check:output">
            <property name="check.output" value="${command.magento.upgrade.output}" override="true"/>
        </phingcall>
    </target>

    <target name="magento:cache:clean"
            hidden="true">

        <property name="command.cache.clean" value="${bin.n98-magerun2} cache:clean"/>
        <echo message="running ${command.cache.clean}"/>
        <exec command="${command.cache.clean}" returnProperty="clean.cache.return"
              outputProperty="command.cache.clean.output"/>

        <if>
            <not>
                <equals arg1="${clean.cache.return}" arg2="0"/>
            </not>
            <then>
                <property name="command.cache.remove"
                          value="rm -rf ${magento.dir}/var/cache/* ${magento.dir}/var/di/* ${magento.dir}/var/generation/* ${magento.dir}/var/page_cache/*"/>
                <echo message="try removing folder directly"/>
                <echo message="running ${command.cache.remove}"/>
                <exec command="${command.cache.remove}" logoutput="true"/>
            </then>
            <else>
                <echo message="${command.cache.clean.output}"/>
            </else>
        </if>

    </target>

</project>