From b88decd931c44f1e069a6472c9df4517b339a440 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Mon, 16 Sep 2024 09:38:41 +0530 Subject: [PATCH 1/3] Continue on duplicate entry, #PG-3865 --- Migrations/ArchiveMigration.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Migrations/ArchiveMigration.php b/Migrations/ArchiveMigration.php index 117b1fc..f524d88 100644 --- a/Migrations/ArchiveMigration.php +++ b/Migrations/ArchiveMigration.php @@ -53,7 +53,19 @@ public function migrate(Request $request, TargetDb $targetDb) if (!empty($archive['idarchive'])) { $archive['idarchive'] = $this->createArchiveId($targetDb, $archiveTable, $archive['idarchive']); $archive['idsite'] = $request->targetIdSite; - $targetDb->insert($archiveTable, $archive); + try { + $targetDb->insert($archiveTable, $archive); + } catch (\Exception $e) { + if ( + $e->getCode() == 23000 + || strpos($e->getMessage(), 'Duplicate entry') !== false + || strpos($e->getMessage(), ' 1062 ') !== false + ) { + $this->log('Duplicate entry in ' . $archiveTable . ' table for archiveID:' . $archive['idarchive'] . ' and name:' . $archive['name']); + continue; + } + throw new \Exception($e->getMessage()); + } } } } From 558e19843aa4e7b8b57520913b49303da77481d1 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Mon, 16 Sep 2024 10:07:56 +0530 Subject: [PATCH 2/3] Bumped version to 5.0.4 --- CHANGELOG.md | 3 +++ plugin.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa75e2..1d67de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 5.0.4 - 2024-09-16 +- Added code to continue import if duplicate records are found in archive table + ### 5.0.3 - Added plugin category for Marketplace diff --git a/plugin.json b/plugin.json index d74dc16..26ad54e 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.3", + "version": "5.0.4", "theme": false, "require": { "matomo": ">=5.0.0-b1,<6.0.0-b1" From 9fd902b338fff0fe85ea2696889c7b24dec57b91 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Mon, 16 Sep 2024 10:08:51 +0530 Subject: [PATCH 3/3] Applied PR feedback --- Migrations/ArchiveMigration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Migrations/ArchiveMigration.php b/Migrations/ArchiveMigration.php index f524d88..07c8d19 100644 --- a/Migrations/ArchiveMigration.php +++ b/Migrations/ArchiveMigration.php @@ -61,7 +61,7 @@ public function migrate(Request $request, TargetDb $targetDb) || strpos($e->getMessage(), 'Duplicate entry') !== false || strpos($e->getMessage(), ' 1062 ') !== false ) { - $this->log('Duplicate entry in ' . $archiveTable . ' table for archiveID:' . $archive['idarchive'] . ' and name:' . $archive['name']); + $this->log('Duplicate entry in ' . $archiveTable . ' table for archiveID: ' . $archive['idarchive'] . ' and name: ' . $archive['name']); continue; } throw new \Exception($e->getMessage());