Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 5.0.6 - 2026-05-25
- Added code to ignore migration if no option is provided explicitly

### 5.0.6 - 2025-09-29
- Allow annotations migration to work with both option and annotations tables

Expand Down
2 changes: 1 addition & 1 deletion Commands/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ private function makeTargetDb()

private function confirmMigration($idSite): bool
{
return $this->askForConfirmation('<question>Are you sure you want to migrate the data for idSite ' . (int) $idSite . '. (y/N)</question>');
return $this->askForConfirmation('<question>Are you sure you want to migrate the data for idSite ' . (int) $idSite . '. (y/N)</question>', false);
}
}
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Migration",
"description": "Migrate/copy any measurable (site, app, roll-up) from one Matomo to another Matomo",
"version": "5.0.6",
"version": "5.0.7",
"theme": false,
"require": {
"matomo": ">=5.0.0-b1,<6.0.0-b1"
Expand Down
121 changes: 74 additions & 47 deletions tests/System/Commands/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function tearDown(): void
public function test_runMigration()
{
$result = $this->runCommand();
$this->assertEquals('Processing SiteMigration at 2019-01-10 02:48:01
$expectedOutput = 'Processing SiteMigration at 2019-01-10 02:48:01
Target site is 1 at 2019-01-10 02:48:01
Processed SiteMigration at 2019-01-10 02:48:01
Processing SiteUrlMigration at 2019-01-10 02:48:01
Expand Down Expand Up @@ -72,38 +72,8 @@ public function test_runMigration()
Migrated 90% of visits at 2019-01-10 02:48:01
Migrated 2 visits. The number of migrated visits may be higher if data is still tracked into the source Matomo while migrating the data at 2019-01-10 02:48:01
Processed LogMigration at 2019-01-10 02:48:01
Processing ArchiveMigration at 2019-01-10 02:48:01
Found 14 archive tables at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_02 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_02 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_03 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_03 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_04 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_04 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_05 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_05 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_06 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_06 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_07 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_07 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_08 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_08 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_09 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_09 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_10 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_10 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_11 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_11 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_12 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_12 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2014_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2014_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Processed ArchiveMigration at 2019-01-10 02:48:01
', $this->applicationTester->getDisplay());
' . $this->getExpectedArchiveMigrationOutput();
$this->assertEquals($expectedOutput, $this->applicationTester->getDisplay());
$this->assertEquals('0', $result);
}

Expand Down Expand Up @@ -156,11 +126,7 @@ public function testApi($api, $params)
FakeAccess::clearAccess(true);
$this->disableArchiving();

if (in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls']]) && version_compare(Version::VERSION, '5.2.0-alpha', '<')) {
$params['testSuffix'] = '5-2a';
} elseif ($api === ['API.get'] && version_compare(Version::VERSION, '5.2.0-b6', '<')) {
$params['testSuffix'] = '5-2b6';
}
$params['testSuffix'] = $this->getTestSuffix($api);

$this->runApiTests($api, $params);
}
Expand All @@ -177,11 +143,7 @@ public function testApi_migrated($api, $params)

FakeAccess::clearAccess($superUser = true);

if (in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls']]) && version_compare(Version::VERSION, '5.2.0-alpha', '<')) {
$params['testSuffix'] = '5-2a';
} elseif ($api === ['API.get'] && version_compare(Version::VERSION, '5.2.0-b6', '<')) {
$params['testSuffix'] = '5-2b6';
}
$params['testSuffix'] = $this->getTestSuffix($api);
try {
$this->runApiTests($api, $params);
} catch (\Exception $e) {
Expand All @@ -192,6 +154,69 @@ public function testApi_migrated($api, $params)
$this->setTargetDbPrefix('');
}

private function getTestSuffix($api)
{
if (
in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls'], ['SitesManager.getSiteFromId'], ['CustomDimensions.getConfiguredCustomDimensions']])
&& version_compare(Version::VERSION, '5.2.0-alpha', '<')
) {
return '5-2a';
}

if ($api === ['API.get'] && version_compare(Version::VERSION, '5.2.0-b6', '<')) {
return '5-2b6';
}

return '';
}

private function getExpectedArchiveMigrationOutput()
{
if (version_compare(Version::VERSION, '5.2.0-alpha', '<')) {
return 'Processing ArchiveMigration at 2019-01-10 02:48:01
Found 14 archive tables at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_02 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_02 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_03 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_03 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_04 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_04 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_05 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_05 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_06 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_06 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_07 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_07 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_08 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_08 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_09 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_09 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_10 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_10 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_11 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_11 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_12 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_12 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2014_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2014_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Processed ArchiveMigration at 2019-01-10 02:48:01
';
}

return 'Processing ArchiveMigration at 2019-01-10 02:48:01
Found 2 archive tables at 2019-01-10 02:48:01
Starting to migrate archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_blob_2013_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Processed ArchiveMigration at 2019-01-10 02:48:01
';
}

private function setTargetDbPrefix($prefix)
{
$testEnv = self::$fixture->getTestEnvironment();
Expand Down Expand Up @@ -220,10 +245,12 @@ private function disableArchiving()
public function test_runMigration_CanBeExecutedMultipleTimesWithoutAnyIdProblems()
{
$result = $this->runCommand();
$this->assertStringContainsString('Starting to migrate archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01
Starting to migrate archive table archive_numeric_2013_02 at 2019-01-10 02:48:01
Migrated archive table archive_numeric_2013_02 at 2019-01-10 02:48:01', $this->applicationTester->getDisplay());
$output = $this->applicationTester->getDisplay();
$this->assertTrue(
strpos($output, 'Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01') !== false
|| strpos($output, 'Skipping table because it is a target table targetdb_archive_numeric_2013_01 and source prefix is: at 2019-01-10 02:48:01') !== false,
$output
);
$this->assertEquals('0', $result);
$result = $this->runCommand();
$this->assertEquals('0', $result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<row>
<idcustomdimension>1</idcustomdimension>
<idsite>1</idsite>
<name>MyName1</name>
<index>1</index>
<scope>visit</scope>
<active>1</active>
<extractions>
</extractions>
<case_sensitive>1</case_sensitive>
</row>
<row>
<idcustomdimension>2</idcustomdimension>
<idsite>1</idsite>
<name>MyName2</name>
<index>1</index>
<scope>action</scope>
<active>1</active>
<extractions>
</extractions>
<case_sensitive>1</case_sensitive>
</row>
<row>
<idcustomdimension>3</idcustomdimension>
<idsite>1</idsite>
<name>MyName3</name>
<index>2</index>
<scope>action</scope>
<active>0</active>
<extractions>
</extractions>
<case_sensitive>1</case_sensitive>
</row>
</result>
26 changes: 26 additions & 0 deletions tests/System/expected/test_5-2a__SitesManager.getSiteFromId.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<row>
<idsite>1</idsite>
<name>MigrationSite</name>
<main_url>http://piwik.net</main_url>
<ts_created>2013-01-22 00:00:00</ts_created>
<ecommerce>1</ecommerce>
<sitesearch>1</sitesearch>
<sitesearch_keyword_parameters />
<sitesearch_category_parameters />
<timezone>UTC</timezone>
<currency>USD</currency>
<exclude_unknown_urls>0</exclude_unknown_urls>
<excluded_ips />
<excluded_parameters />
<excluded_user_agents />
<excluded_referrers />
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
</result>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<idcustomdimension>1</idcustomdimension>
<idsite>1</idsite>
<name>MyName1</name>
<description/>
<index>1</index>
<scope>visit</scope>
<active>1</active>
Expand All @@ -15,6 +16,7 @@
<idcustomdimension>2</idcustomdimension>
<idsite>1</idsite>
<name>MyName2</name>
<description/>
<index>1</index>
<scope>action</scope>
<active>1</active>
Expand All @@ -26,6 +28,7 @@
<idcustomdimension>3</idcustomdimension>
<idsite>1</idsite>
<name>MyName3</name>
<description/>
<index>2</index>
<scope>action</scope>
<active>0</active>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<row>
<idsite>1</idsite>
<name>MigrationSite</name>
<description/>
<main_url>http://piwik.net</main_url>
<ts_created>2013-01-22 00:00:00</ts_created>
<ecommerce>1</ecommerce>
Expand Down
Loading