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

Adds code to update idvisitor if changed in visits_log table, #DEV-18502 #22890

Draft
wants to merge 1 commit into
base: 5.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/Tracker/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,26 @@ public function isSiteEmpty($siteId)
return $result == null;
}

/**
* Update an existing visit in the DB
*
* @param int $idvisit
* @param string $idVisitor
*
* @throws Db\DbException
*/
public function updateVisitorIDForConversion($idvisit, $idVisitor): void
{
$table = Common::prefixTable('log_conversion');
$sqlQuery = "UPDATE $table SET idvisitor = ? WHERE idvisit = ?";

$sqlBind = [];
$sqlBind[] = $idVisitor;
$sqlBind[] = $idvisit;

$this->getDb()->query($sqlQuery, $sqlBind);
}

/**
* Build an array of fields and bind values
*
Expand Down
8 changes: 6 additions & 2 deletions core/Tracker/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Piwik\Date;
use Piwik\Exception\UnexpectedWebsiteFoundException;
use Matomo\Network\IPUtils;
use Piwik\Piwik;
use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Plugins\Actions\Tracker\ActionsRequestProcessor;
use Piwik\Plugins\UserCountry\Columns\Base;
Expand Down Expand Up @@ -429,17 +430,20 @@ protected function updateExistingVisit($valuesToUpdate)

$idSite = $this->request->getIdSite();
$idVisit = $this->visitProperties->getProperty('idvisit');
$model = $this->getModel();

$wasInserted = $this->getModel()->updateVisit($idSite, $idVisit, $valuesToUpdate);
$wasInserted = $model->updateVisit($idSite, $idVisit, $valuesToUpdate);

// Debug output
if (isset($valuesToUpdate['idvisitor'])) {
$model->updateVisitorIDForConversion($idVisit, $valuesToUpdate['idvisitor']);
Piwik::postEvent('Visit.updateIDVisitor', [$idVisit, $valuesToUpdate['idvisitor']]);
$valuesToUpdate['idvisitor'] = bin2hex($valuesToUpdate['idvisitor']);
}

if ($wasInserted) {
Common::printDebug('Updated existing visit: ' . var_export($valuesToUpdate, true));
} elseif (!$this->getModel()->hasVisit($idSite, $idVisit)) {
} elseif (!$model->hasVisit($idSite, $idVisit)) {
// mostly for WordPress. see https://github.com/matomo-org/matomo/pull/15587
// as WP doesn't set `MYSQLI_CLIENT_FOUND_ROWS` and therefore when the update succeeded but no value changed
// it would still return 0 vs OnPremise would return 1 or 2.
Expand Down
Loading