matomo-org / matomo-org/plugin-Migration
Wordpress-Multisite: Can not migrate data other than the first site's one
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 7
- Forks
- 11
- Avg merge
- 4h 17m
- Merged PRs (30d)
- 2
Description
For Wordpress-Multisites with "Matomo for WordPress", each site has a different database table prefix (like wp_matomo_, wp_2_matomo_, ...).
For each table wp_X_matomo_site, there is one single entry (therefore Matomo's idsite is always 1 for each multisite site)
Therefore it is not possible to migrate other than the main site of the multisite, because idsite 2 etc. is not found.
A quick-and-dirty workaround is, to replace the database table prefix, for example with an additional parameter in [Commands/Migrate.php:configure()](https://github.com/matomo-org/plugin-Migration/blob/5.x-dev/Commands/Migrate.php#L21):
```
$this->addRequiredValueOption('source-wpsite', null, 'Source Multisite Site ID you want to migrate');
```
and add in [Commands/Migrate.php:doExecute()](https://github.com/matomo-org/plugin-Migration/blob/5.x-dev/Commands/Migrate.php#L46):
```
$multiSiteId = (int) $input->getOption('source-wpsite');
if($multiSiteId != 1) {
\Piwik\Config::getInstance()->database['tables_prefix'] = str_replace("wp_", "wp_" . $multiSiteId . "_", \Piwik\Config::getInstance()->database['tables_prefix']);
}
```
**_Warning_:** Keep in mind, that this snippet is for demonstration only. The table-prefix might not be "wp_", because it is configurable as well. Also it might be the optimal place and/or way to fix that behavior, as I'm currently not too familiar with Matomo's codebase
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading Commands/Migrate.php, especially configure() and doExecute(), and trace how the database table prefix is selected for migrations. Verify how a configurable WordPress multisite prefix can target a non-primary site without breaking the default case. Done means data from a selected multisite site can be migrated, not only the first site.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100