Skip to content

Commit

Permalink
[BUGFIX] UpdateFingerprintRelationsUpgradeWizard
Browse files Browse the repository at this point in the history
* Change fingerprints count only for single visitor
* select only visitors that not already have a fingerprint
  relation in visitor column. Prevents broken relations
  on a second run, if the first was not finished.

Resolves: in2code-de#64
  • Loading branch information
Mabahe committed Nov 14, 2024
1 parent 22a6744 commit e507d40
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Classes/Update/UpdateFingerprintRelationsUpgradeWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ public function getDescription(): string

public function executeUpdate(): bool
{
$connection = DatabaseUtility::getConnectionForTable(Fingerprint::TABLE_NAME);
foreach ($this->getAllVisitors() as $visitor) {
$connectionFingerprint = DatabaseUtility::getConnectionForTable(Fingerprint::TABLE_NAME);
$connectionVisitor = DatabaseUtility::getConnectionForTable(Visitor::TABLE_NAME);
$visitors = $this->getAllVisitors();
foreach ($visitors as $visitor) {
$fingerprintIdentifiers = GeneralUtility::intExplode(',', $visitor['fingerprints'], true);
foreach ($fingerprintIdentifiers as $fingerprintIdentifier) {
if ($fingerprintIdentifier === 0) {
continue;
}
$connection->executeQuery(
$connectionFingerprint->executeQuery(
'update ' . Fingerprint::TABLE_NAME
. ' set visitor = "' . $visitor['uid'] . '" where uid=' . $fingerprintIdentifier
);
}
$connection->executeQuery(
'update ' . Visitor::TABLE_NAME . ' set fingerprints = ' . count($fingerprintIdentifiers)
$connectionVisitor->executeQuery(
'update ' . Visitor::TABLE_NAME . ' set fingerprints = ' . count($fingerprintIdentifiers) . ' WHERE uid = ' . $visitor['uid']
);
}
return true;
Expand All @@ -56,12 +58,31 @@ public function executeUpdate(): bool
protected function getAllVisitors(): array
{
$queryBuilder = DatabaseUtility::getQueryBuilderForTable(Visitor::TABLE_NAME, true);
return $queryBuilder
$fingerprintsWithVisitor = $this->getFingerprintsWithVisitor();
$query = $queryBuilder
->select('uid', 'fingerprints')
->from(Visitor::TABLE_NAME)
->where('deleted=0 and fingerprints!=\'\'')
->where('deleted=0 and fingerprints!=\'\'');
if (!empty($fingerprintsWithVisitor)) {
$query->andWhere('uid NOT IN (' . implode(',', $fingerprintsWithVisitor) . ')');
}
return $query->executeQuery()->fetchAllAssociative();
}

protected function getFingerprintsWithVisitor(): array
{
$queryBuilder = DatabaseUtility::getQueryBuilderForTable(Fingerprint::TABLE_NAME, true);
$data = $queryBuilder
->select('uid')
->from(Fingerprint::TABLE_NAME)
->where('deleted=0 and visitor != 0')
->executeQuery()
->fetchAllAssociative();
$uids = [];
foreach ($data as $item) {
$uids[] = $item['uid'];
}
return $uids;
}

public function updateNecessary(): bool
Expand Down

0 comments on commit e507d40

Please sign in to comment.