matomo-for-wordpress
matomo-for-wordpress copied to clipboard
Add ability to migrate from On-Premise to WordPress
We have the plugin https://github.com/matomo-org/plugin-Migration
It's currently not possible to migrate data from On-Premise to WordPress. The problem is that "Site migration" always creates a new site vs here we would need to migrate to an existing site. A workaround could be to migrate into a new site in Matomo for WordPress and then calling Site::map_matomo_site_id(). This would be likely the easiest and preferred solution and this way we would not alter anything in the first idsite which was created when the plugin was installed.
Also another problem is that Matomo On-Premise could be storing multiple sites while Matomo for WordPress only supports one site. Meaning it would be possible to only migrate one site basically and/or they would overwrite each other or so.
For simplicity for now we would exclude multisite from this.
I was going to say something like this might do:
diff --git a/Migrations/SiteMigration.php b/Migrations/SiteMigration.php
index 1dd232a..60012cb 100644
--- a/Migrations/SiteMigration.php
+++ b/Migrations/SiteMigration.php
@@ -11,6 +11,7 @@ namespace Piwik\Plugins\Migration\Migrations;
use Piwik\Common;
use Piwik\Db;
use Piwik\Plugins\Migration\TargetDb;
+use Piwik\SettingsServer;
class SiteMigration extends BaseMigration
{
@@ -27,6 +28,10 @@ class SiteMigration extends BaseMigration
unset($row['idsite']);
$request->targetIdSite = $targetDb->insert('site', $row);
+ if (SettingsServer::isMatomoForWordPress()) {
+ \WpMatomo\Site::map_matomo_site_id(get_current_blog_id(), $request->targetIdSite);
+ }
+
$this->log(sprintf('Target site is %s', $request->targetIdSite));
}
}
But it wouldn't because the migration would be executed on the On-Premise installation and we would have no way of knowing if the target installation is a WordPress unless we looked for WordPress specific tables on the target DB and figured out the blog ID ourselves (usually 1)
When implemented leave a comment here: https://github.com/matomo-org/matomo-for-wordpress/blob/4.3.1/classes/WpMatomo/Site.php#L31