{% extends '@CoreUpdater/layout.twig' %}

{% block content %}

    <div class="header">
        <h1>{{ 'CoreUpdater_DatabaseUpgradeRequired'|translate }}</h1>
        <p>{{ 'CoreUpdater_YourDatabaseIsOutOfDate'|translate }}</p>
        {{ postEvent('Template.topBar')|raw }}
    </div>

    <div class="content" style="text-align:left;">

        {% set helpMessage %}
            {{ 'CoreUpdater_HelpMessageContent'|translate('<a target="_blank" href="?module=Proxy&action=redirect&url=https://matomo.org/faq/">','</a>','</li><li>')|raw }}
        {% endset %}

        {% if coreError %}
            <div class="alert alert-danger">
                {{ 'CoreUpdater_CriticalErrorDuringTheUpgradeProcess'|translate }}
                {% for message in errorMessages %}
                    <br/><strong>{{ message|raw }}</strong>
                {% endfor %}
            </div>
            <p>{{ 'CoreUpdater_HelpMessageIntroductionWhenError'|translate }}</p>
            <ul>
                <li>{{ helpMessage|raw }}</li>
            </ul>
        {% else %}

            {% if coreToUpdate or pluginNamesToUpdate|length > 0 or dimensionsToUpdate|length > 0 %}
                {% if coreToUpdate %}
                    <p>{{ 'CoreUpdater_PiwikWillBeUpgradedFromVersionXToVersionY'|translate(current_piwik_version,new_piwik_version) }}</p>
                {% endif %}

                {% if pluginNamesToUpdate|length > 0 %}
                    {% set listOfPlugins=pluginNamesToUpdate|join(', ') %}
                    <p>{{ 'CoreUpdater_TheFollowingPluginsWillBeUpgradedX'|translate(listOfPlugins) }}</p>
                {% endif %}

                {% if dimensionsToUpdate|length > 0 %}
                    {% set listOfDimensions=dimensionsToUpdate|join(', ') %}
                    <p>{{ 'CoreUpdater_TheFollowingDimensionsWillBeUpgradedX'|translate(listOfDimensions) }}</p>
                {% endif %}

                <h2>{{ 'CoreUpdater_NoteForLargePiwikInstances'|translate }}</h2>
                {% if isMajor %}
                    <div class="alert alert-danger">
                        {{ 'CoreUpdater_MajorUpdateWarning1'|translate }}
                        {{ 'CoreUpdater_MajorUpdateWarning2'|translate }}
                    </div>
                {% endif %}
                <p>{{ 'CoreUpdater_TheUpgradeProcessMayFailExecuteCommand'|translate('') }}</p>
                <pre>{{ commandUpgradePiwik }}</pre>
                <p>{{ 'CoreUpdater_HighTrafficPiwikServerEnableMaintenance'|translate('<a target="_blank" href="?module=Proxy&action=redirect&url=http%3A%2F%2Fmatomo.org%2Ffaq%2Fhow-to%2F%23faq_111">', '</a>')|raw }}</p>

                {% if queries is not empty %}
                    <p><a href="#" id="showSql">› {{ 'CoreUpdater_ClickHereToViewSqlQueries'|translate }}</a></p>
                    <div id="sqlQueries" style="display:none;">
                        <pre># {{ 'CoreUpdater_ListOfSqlQueriesFYI'|translate(piwik_version) }}<br/>{% for query in queries %}{{ query }}<br/>{% endfor %}</pre>
                    </div>
                {% endif %}

                <h2>{{ 'CoreUpdater_NeedHelpUpgrading'|translate }}</h2>
                <p>{{ 'CoreUpdater_NeedHelpUpgradingText'|translate("<a rel='noreferrer' target='_blank' href='https://matomo.org/support/upgrading-piwik/'>", "</a>")|raw }}</p>

                <h2>{{ 'CoreUpdater_ReadyToGo'|translate }}</h2>
                <p>{{ 'CoreUpdater_TheUpgradeProcessMayTakeAWhilePleaseBePatient'|translate }}</p>
            {% endif %}

            {% if warningMessages|length > 0 %}
                <div class="alert alert-info">
                    {{ warningMessages[0] }}
                    {% if warningMessages|length > 1 %}
                        <button id="more-results" class="ui-button ui-state-default ui-corner-all">{{ 'General_Details'|translate }}</button>
                    {% endif %}
                </div>
            {% endif %}

            {% if coreToUpdate or pluginNamesToUpdate|length > 0 or dimensionsToUpdate|length > 0  %}
                <form action="index.php" id="upgradeCorePluginsForm" class="clearfix" data-updating="{{ 'CoreUpdater_Updating'|translate }}...">
                    <input type="hidden" name="updateCorePlugins" value="1"/>
                    {% if queries|length == 1 %}
                        <input type="submit" class="btn right" value="{{ 'General_ContinueToPiwik'|translate }}"/>
                    {% else %}
                        <input type="submit" class="btn right" value="{{ 'CoreUpdater_UpgradePiwik'|translate }}"/>
                    {% endif %}
                </form>
            {% else %}
                {% if warningMessages|length >= 0 %}
                    <div class="alert alert-success">
                        {{ 'CoreUpdater_PiwikHasBeenSuccessfullyUpgraded'|translate }}
                    </div>
                {% endif %}
                <form action="index.php" class="clearfix">
                    <input type="submit" class="btn right" value="{{ 'General_ContinueToPiwik'|translate }}"/>
                </form>
            {% endif %}
        {% endif %}

        {% include "@Installation/_integrityDetails.twig" %}

    </div>

{% endblock %}
