Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress-Multisite: Can not migrate data other than the first site's one #65

Open
philipp-doblhofer opened this issue Apr 18, 2024 · 2 comments

Comments

@philipp-doblhofer
Copy link

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():

$this->addRequiredValueOption('source-wpsite', null, 'Source Multisite Site ID you want to migrate');

and add in Commands/Migrate.php:doExecute():

$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

@AltamashShaikh
Copy link
Contributor

@philipp-doblhofer Will you be willing to create a PR for this ?

To solve the table-prefix issue, I would recommend creating 1 more option to set the prefix with a default value wp_

@philipp-doblhofer
Copy link
Author

@AltamashShaikh yes, I can take a look on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants