Skip to content

Commit

Permalink
Include non-sql migrations in update dry run output. (matomo-org#14003)
Browse files Browse the repository at this point in the history
* Include non-sql migrations in update dry run output.

* More translation updates.

* Make check for by domain Matomo more robust.

* Show migrations in separate boxes based on whether they are SQL or console commands.

* Update two screenshots and fix test.
  • Loading branch information
diosmosis committed Feb 10, 2019
1 parent f768274 commit c673177
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 22 deletions.
12 changes: 11 additions & 1 deletion core/Config.php
Expand Up @@ -119,6 +119,16 @@ public static function getCommonConfigPath()
return PIWIK_USER_PATH . self::DEFAULT_COMMON_CONFIG_PATH;
}

/**
* Returns default absolute path to the local configuration file.
*
* @return string
*/
public static function getDefaultLocalConfigPath()
{
return PIWIK_USER_PATH . self::DEFAULT_LOCAL_CONFIG_PATH;
}

/**
* Returns absolute path to the local configuration file
*
Expand All @@ -130,7 +140,7 @@ public static function getLocalConfigPath()
if ($path) {
return $path;
}
return PIWIK_USER_PATH . self::DEFAULT_LOCAL_CONFIG_PATH;
return self::getDefaultLocalConfigPath();
}

private static function getLocalConfigInfoForHostname($hostname)
Expand Down
7 changes: 2 additions & 5 deletions core/Updater.php
Expand Up @@ -222,7 +222,7 @@ public function hasMajorDbUpdate()
/**
* Returns the list of SQL queries that would be executed during the update
*
* @return Sql[] of SQL queries
* @return Migration[] of SQL queries
* @throws \Exception
*/
public function getSqlQueriesToExecute()
Expand Down Expand Up @@ -250,10 +250,7 @@ public function getSqlQueriesToExecute()
$migrationsForComponent = $update->getMigrations($this);
foreach ($migrationsForComponent as $index => $migration) {
$migration = $this->keepBcForOldMigrationQueryFormat($index, $migration);

if ($migration instanceof Migration\Db) {
$queries[] = $migration;
}
$queries[] = $migration;
}
$this->hasMajorDbUpdate = $this->hasMajorDbUpdate || call_user_func(array($className, 'isMajorUpdate'));
}
Expand Down
6 changes: 5 additions & 1 deletion core/Updater/Migration/Plugin/Activate.php
Expand Up @@ -7,6 +7,7 @@
*/
namespace Piwik\Updater\Migration\Plugin;

use Piwik\Config;
use Piwik\Plugin;
use Piwik\Updater\Migration;

Expand All @@ -33,7 +34,10 @@ public function __construct(Plugin\Manager $pluginManager, $pluginName)

public function __toString()
{
return sprintf('Activating plugin "%s"', $this->pluginName);
$domain = Config::getLocalConfigPath() == Config::getDefaultLocalConfigPath() ? '' : Config::getHostname();
$domainArg = !empty($domain) ? "--matomo-domain=\"$domain\" " : '';

return sprintf('./console %splugin:activate "%s"', $domainArg, $this->pluginName);
}

public function shouldIgnoreError($exception)
Expand Down
6 changes: 5 additions & 1 deletion core/Updater/Migration/Plugin/Deactivate.php
Expand Up @@ -7,6 +7,7 @@
*/
namespace Piwik\Updater\Migration\Plugin;

use Piwik\Config;
use Piwik\Plugin;
use Piwik\Updater\Migration;

Expand All @@ -33,7 +34,10 @@ public function __construct(Plugin\Manager $pluginManager, $pluginName)

public function __toString()
{
return sprintf('Deactivating plugin "%s"', $this->pluginName);
$domain = Config::getLocalConfigPath() == Config::getDefaultLocalConfigPath() ? '' : Config::getHostname();
$domainArg = !empty($domain) ? "--matomo-domain=\"$domain\" " : '';

return sprintf('./console %splugin:deactivate "%s"', $domainArg, $this->pluginName);
}

public function shouldIgnoreError($exception)
Expand Down
31 changes: 30 additions & 1 deletion plugins/CoreUpdater/Controller.php
Expand Up @@ -29,6 +29,7 @@
use Piwik\Version;
use Piwik\View;
use Piwik\View\OneClickDone;
use Piwik\Updater\Migration\Db as DbMigration;

class Controller extends \Piwik\Plugin\Controller
{
Expand Down Expand Up @@ -255,7 +256,12 @@ public function runUpdaterAndExit($doDryRun = null)
}

if ($doDryRun) {
$viewWelcome->queries = $updater->getSqlQueriesToExecute();
$migrations = $updater->getSqlQueriesToExecute();
$queryCount = count($migrations);

$migrations = $this->groupMigrations($migrations);
$viewWelcome->migrations = $migrations;
$viewWelcome->queryCount = $queryCount;
$viewWelcome->isMajor = $updater->hasMajorDbUpdate();
$this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
return $viewWelcome->render();
Expand All @@ -274,6 +280,29 @@ public function runUpdaterAndExit($doDryRun = null)
exit;
}

private function groupMigrations($migrations)
{
$result = [];

$group = null;
foreach ($migrations as $migration) {
$type = $migration instanceof DbMigration ? 'sql' : 'command';
if ($group === null
|| $type != $group['type']
) {
$group = [
'type' => $type,
'migrations' => [],
];
$result[] = $group;
}

$result[count($result) - 1]['migrations'][] = $migration;
}

return $result;
}

private function doWelcomeUpdates($view, $componentsWithUpdateFile)
{
$view->new_piwik_version = Version::VERSION;
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreUpdater/javascripts/updateLayout.js
@@ -1,7 +1,7 @@
$(document).ready(function () {
$('#showSql').click(function (e) {
e.preventDefault();
$('#sqlQueries').toggle();
$('.sqlQueries').toggle();
});
$('#upgradeCorePluginsForm').submit(function () {
$('input[type=submit]', this)
Expand Down
8 changes: 5 additions & 3 deletions plugins/CoreUpdater/lang/en.json
@@ -1,7 +1,7 @@
{
"CoreUpdater": {
"CheckingForPluginUpdates": "Checking for new plugin updates",
"ClickHereToViewSqlQueries": "Click here to view and copy the list of SQL queries that will get executed",
"ClickHereToViewSqlQueries": "Click here to view and copy the list of SQL queries and console commands that will get executed",
"CriticalErrorDuringTheUpgradeProcess": "Critical Error during the update process:",
"DatabaseUpgradeRequired": "Database Upgrade Required",
"DisablingIncompatiblePlugins": "Disabling incompatible plugins: %s",
Expand Down Expand Up @@ -31,7 +31,9 @@
"Latest2XStableRelease": "Latest stable 2.X",
"Latest2XBetaRelease": "Latest beta 2.X",
"LtsSupportVersion": "Long Term Support version",
"ListOfSqlQueriesFYI": "FYI: these are the SQL queries that will be executed to upgrade your database to Matomo %s",
"ListOfSqlQueriesFYI": "FYI: these are the SQL queries and console commands that will be executed to upgrade your database to Matomo %s",
"TheseSqlQueriesWillBeExecuted": "These SQL queries will be executed:",
"TheseCommandsWillBeExecuted": "These console commands will be run:",
"MajorUpdateWarning1": "This is a major update! It will take longer than usual.",
"MajorUpdateWarning2": "The following advice is especially important for large installations.",
"NeedHelpUpgrading": "Need help upgrading Matomo?",
Expand Down Expand Up @@ -75,7 +77,7 @@
"DbUpgradeNotExecuted": "Database upgrade not executed.",
"ConsoleUpdateUnexpectedUserWarning": "It appears you have executed this update with user %1$s, while your Matomo files are owned by %2$s. \n\nTo ensure that the Matomo files are readable by the correct user, you may need to run the following command (or a similar command depending on your server configuration):\n\n$ %3$s",
"ConsoleUpdateFailure": "Matomo could not be updated! See above for more information.",
"ConsoleUpdateNoSqlQueries": "Note: There are no SQL queries to execute.",
"ConsoleUpdateNoSqlQueries": "Note: There are no SQL queries or console commands to execute.",
"AlreadyUpToDate": "Everything is already up to date.",
"ExecuteDbUpgrade": "A database upgrade is required. Execute update?",
"DryRun": "Note: this is a Dry Run",
Expand Down
11 changes: 7 additions & 4 deletions plugins/CoreUpdater/templates/runUpdaterAndExit_welcome.twig
Expand Up @@ -53,11 +53,14 @@
<pre>{{ commandUpgradePiwik }}</pre>
<p>{{ 'CoreUpdater_HighTrafficPiwikServerEnableMaintenance'|translate('<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/how-to/#faq_111">', '</a>')|raw }}</p>

{% if queries is not empty %}
{% if migrations is not empty %}
<p>{{ 'CoreUpdater_ListOfSqlQueriesFYI'|translate(piwik_version) }}</p>
<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>
{% for group in migrations %}
<div class="sqlQueries" style="display:none;">
<pre># {% if group.type == 'sql' %}{{ 'CoreUpdater_TheseSqlQueriesWillBeExecuted'|translate }}{% else %}{{ 'CoreUpdater_TheseCommandsWillBeExecuted'|translate }}{% endif %} <br/>{% for migration in group.migrations %}{{ migration }}<br/>{% endfor %}</pre>
</div>
{% endfor %}
{% endif %}

<h2>{{ 'CoreUpdater_NeedHelpUpgrading'|translate }}</h2>
Expand All @@ -79,7 +82,7 @@
{% 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 %}
{% if queryCount == 1 %}
<input type="submit" class="btn right" value="{{ 'General_ContinueToPiwik'|translate }}"/>
{% else %}
<input type="submit" class="btn right" value="{{ 'CoreUpdater_UpgradePiwik'|translate }}"/>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -44,7 +44,7 @@ public function test_sql_forwardsQueryAndErrorCode()
{
$migration = $this->factory->activate($this->pluginName);

$this->assertSame('Activating plugin "MyTestPluginName"', '' . $migration);
$this->assertSame('./console plugin:activate "MyTestPluginName"', '' . $migration);
}

}

0 comments on commit c673177

Please sign in to comment.