From 586024194bfd78b05d8d010c1da9419026828394 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 22 May 2026 08:14:40 +0530 Subject: [PATCH 1/5] Adds code to ignore migration if no option is provided explicitly, #PG-5167 --- CHANGELOG.md | 3 +++ Commands/Migrate.php | 18 +++++++++--------- plugin.json | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7805785..717edd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Commands/Migrate.php b/Commands/Migrate.php index 7b94947..b01a744 100644 --- a/Commands/Migrate.php +++ b/Commands/Migrate.php @@ -24,14 +24,14 @@ protected function configure() $this->setName('migration:measurable'); $this->setDescription('Migrates a measurable/website from one Matomo instance to another Matomo'); - $this->addRequiredValueOption('source-idsite', null, 'Source Site ID you want to migrate'); - $this->addRequiredValueOption('target-db-host', null, 'Target database host'); - $this->addRequiredValueOption('target-db-username', null, 'Target database username'); - $this->addOptionalValueOption('target-db-password', null, 'Target database password'); - $this->addRequiredValueOption('target-db-name', null, 'Target database name'); - $this->addOptionalValueOption('target-db-prefix', null, 'Target database table prefix', ''); - $this->addRequiredValueOption('target-db-port', null, 'Target database port', '3306'); - $this->addOptionalValueOption('target-db-ssl-ca', null, 'The path name to the certificate authority file.', '/etc/ssl/certs/cert.pem'); +// $this->addRequiredValueOption('source-idsite', null, 'Source Site ID you want to migrate'); +// $this->addRequiredValueOption('target-db-host', null, 'Target database host'); +// $this->addRequiredValueOption('target-db-username', null, 'Target database username'); +// $this->addOptionalValueOption('target-db-password', null, 'Target database password'); +// $this->addRequiredValueOption('target-db-name', null, 'Target database name'); +// $this->addOptionalValueOption('target-db-prefix', null, 'Target database table prefix', ''); +// $this->addRequiredValueOption('target-db-port', null, 'Target database port', '3306'); +// $this->addOptionalValueOption('target-db-ssl-ca', null, 'The path name to the certificate authority file.', '/etc/ssl/certs/cert.pem'); $this->addNoValueOption('target-db-enable-ssl', null, 'Used for establishing secure connections using SSL with target database host.'); $this->addNoValueOption('target-db-ssl-no-verify', null, 'Disable server certificate validation of the target database host.'); $this->addNoValueOption('skip-logs', null, 'Skip migration of logs'); @@ -133,6 +133,6 @@ private function makeTargetDb() private function confirmMigration($idSite): bool { - return $this->askForConfirmation('Are you sure you want to migrate the data for idSite ' . (int) $idSite . '. (y/N)'); + return $this->askForConfirmation('Are you sure you want to migrate the data for idSite ' . (int) $idSite . '. (y/N)', false); } } diff --git a/plugin.json b/plugin.json index dc3383a..01e2b8b 100644 --- a/plugin.json +++ b/plugin.json @@ -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" From 4ae0065b5bf83569080ba52008ad76342a49fe6b Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 22 May 2026 08:25:35 +0530 Subject: [PATCH 2/5] Reverted unwanted change --- Commands/Migrate.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Commands/Migrate.php b/Commands/Migrate.php index b01a744..ff6be04 100644 --- a/Commands/Migrate.php +++ b/Commands/Migrate.php @@ -24,14 +24,14 @@ protected function configure() $this->setName('migration:measurable'); $this->setDescription('Migrates a measurable/website from one Matomo instance to another Matomo'); -// $this->addRequiredValueOption('source-idsite', null, 'Source Site ID you want to migrate'); -// $this->addRequiredValueOption('target-db-host', null, 'Target database host'); -// $this->addRequiredValueOption('target-db-username', null, 'Target database username'); -// $this->addOptionalValueOption('target-db-password', null, 'Target database password'); -// $this->addRequiredValueOption('target-db-name', null, 'Target database name'); -// $this->addOptionalValueOption('target-db-prefix', null, 'Target database table prefix', ''); -// $this->addRequiredValueOption('target-db-port', null, 'Target database port', '3306'); -// $this->addOptionalValueOption('target-db-ssl-ca', null, 'The path name to the certificate authority file.', '/etc/ssl/certs/cert.pem'); + $this->addRequiredValueOption('source-idsite', null, 'Source Site ID you want to migrate'); + $this->addRequiredValueOption('target-db-host', null, 'Target database host'); + $this->addRequiredValueOption('target-db-username', null, 'Target database username'); + $this->addOptionalValueOption('target-db-password', null, 'Target database password'); + $this->addRequiredValueOption('target-db-name', null, 'Target database name'); + $this->addOptionalValueOption('target-db-prefix', null, 'Target database table prefix', ''); + $this->addRequiredValueOption('target-db-port', null, 'Target database port', '3306'); + $this->addOptionalValueOption('target-db-ssl-ca', null, 'The path name to the certificate authority file.', '/etc/ssl/certs/cert.pem'); $this->addNoValueOption('target-db-enable-ssl', null, 'Used for establishing secure connections using SSL with target database host.'); $this->addNoValueOption('target-db-ssl-no-verify', null, 'Disable server certificate validation of the target database host.'); $this->addNoValueOption('skip-logs', null, 'Skip migration of logs'); From 91bbbf10f6e8807595eac2cad0b9f8dd0fe974e4 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 22 May 2026 12:32:02 +0530 Subject: [PATCH 3/5] Fixes tests --- tests/System/Commands/MigrateTest.php | 34 +++---------------- ...mensions.getConfiguredCustomDimensions.xml | 3 ++ .../test___SitesManager.getSiteFromId.xml | 1 + 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/tests/System/Commands/MigrateTest.php b/tests/System/Commands/MigrateTest.php index cb8e5f6..f057ed6 100644 --- a/tests/System/Commands/MigrateTest.php +++ b/tests/System/Commands/MigrateTest.php @@ -73,35 +73,11 @@ public function test_runMigration() 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 +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 ', $this->applicationTester->getDisplay()); $this->assertEquals('0', $result); @@ -221,9 +197,7 @@ 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()); +Migrated archive table archive_numeric_2013_01 at 2019-01-10 02:48:01', $this->applicationTester->getDisplay()); $this->assertEquals('0', $result); $result = $this->runCommand(); $this->assertEquals('0', $result); diff --git a/tests/System/expected/test___CustomDimensions.getConfiguredCustomDimensions.xml b/tests/System/expected/test___CustomDimensions.getConfiguredCustomDimensions.xml index d4aa297..e665db8 100644 --- a/tests/System/expected/test___CustomDimensions.getConfiguredCustomDimensions.xml +++ b/tests/System/expected/test___CustomDimensions.getConfiguredCustomDimensions.xml @@ -4,6 +4,7 @@ 1 1 MyName1 + 1 visit 1 @@ -15,6 +16,7 @@ 2 1 MyName2 + 1 action 1 @@ -26,6 +28,7 @@ 3 1 MyName3 + 2 action 0 diff --git a/tests/System/expected/test___SitesManager.getSiteFromId.xml b/tests/System/expected/test___SitesManager.getSiteFromId.xml index 015ddde..c3f4de8 100644 --- a/tests/System/expected/test___SitesManager.getSiteFromId.xml +++ b/tests/System/expected/test___SitesManager.getSiteFromId.xml @@ -3,6 +3,7 @@ 1 MigrationSite + http://piwik.net 2013-01-22 00:00:00 1 From e68a7addf219d83777811aa3e0edab23d1fafb1a Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 22 May 2026 12:38:23 +0530 Subject: [PATCH 4/5] Fixes for test --- tests/System/Commands/MigrateTest.php | 36 ++++++++++++------- .../test_5-2a__SitesManager.getSiteFromId.xml | 26 ++++++++++++++ 2 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 tests/System/expected/test_5-2a__SitesManager.getSiteFromId.xml diff --git a/tests/System/Commands/MigrateTest.php b/tests/System/Commands/MigrateTest.php index f057ed6..86e649a 100644 --- a/tests/System/Commands/MigrateTest.php +++ b/tests/System/Commands/MigrateTest.php @@ -132,11 +132,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); } @@ -153,11 +149,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) { @@ -168,6 +160,22 @@ public function testApi_migrated($api, $params) $this->setTargetDbPrefix(''); } + private function getTestSuffix($api) + { + if ( + in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls'], ['SitesManager.getSiteFromId']]) + && 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 setTargetDbPrefix($prefix) { $testEnv = self::$fixture->getTestEnvironment(); @@ -196,8 +204,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', $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); diff --git a/tests/System/expected/test_5-2a__SitesManager.getSiteFromId.xml b/tests/System/expected/test_5-2a__SitesManager.getSiteFromId.xml new file mode 100644 index 0000000..b2f37bb --- /dev/null +++ b/tests/System/expected/test_5-2a__SitesManager.getSiteFromId.xml @@ -0,0 +1,26 @@ + + + + 1 + MigrationSite + http://piwik.net + 2013-01-22 00:00:00 + 1 + 1 + + + UTC + USD + 0 + + + + + + website + 0 + superUserLogin + UTC + US Dollar + + From 2bdb9ef6c89f37d71ba95d4cda5919cce6c75a41 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 22 May 2026 12:54:12 +0530 Subject: [PATCH 5/5] Fix for lower version --- tests/System/Commands/MigrateTest.php | 61 ++++++++++++++++--- ...mensions.getConfiguredCustomDimensions.xml | 36 +++++++++++ 2 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 tests/System/expected/test_5-2a__CustomDimensions.getConfiguredCustomDimensions.xml diff --git a/tests/System/Commands/MigrateTest.php b/tests/System/Commands/MigrateTest.php index 86e649a..4dcfe4c 100644 --- a/tests/System/Commands/MigrateTest.php +++ b/tests/System/Commands/MigrateTest.php @@ -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 @@ -72,14 +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 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 -', $this->applicationTester->getDisplay()); +' . $this->getExpectedArchiveMigrationOutput(); + $this->assertEquals($expectedOutput, $this->applicationTester->getDisplay()); $this->assertEquals('0', $result); } @@ -163,7 +157,7 @@ public function testApi_migrated($api, $params) private function getTestSuffix($api) { if ( - in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls'], ['SitesManager.getSiteFromId']]) + in_array($api, [['Live.getLastVisitsDetails'], ['Actions.getPageUrls'], ['SitesManager.getSiteFromId'], ['CustomDimensions.getConfiguredCustomDimensions']]) && version_compare(Version::VERSION, '5.2.0-alpha', '<') ) { return '5-2a'; @@ -176,6 +170,53 @@ private function getTestSuffix($api) 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(); diff --git a/tests/System/expected/test_5-2a__CustomDimensions.getConfiguredCustomDimensions.xml b/tests/System/expected/test_5-2a__CustomDimensions.getConfiguredCustomDimensions.xml new file mode 100644 index 0000000..18098bd --- /dev/null +++ b/tests/System/expected/test_5-2a__CustomDimensions.getConfiguredCustomDimensions.xml @@ -0,0 +1,36 @@ + + + + 1 + 1 + MyName1 + 1 + visit + 1 + + + 1 + + + 2 + 1 + MyName2 + 1 + action + 1 + + + 1 + + + 3 + 1 + MyName3 + 2 + action + 0 + + + 1 + +