Skip to content

Commit

Permalink
Merge pull request #55 from AgID/fix/query-execution
Browse files Browse the repository at this point in the history
Fix query parameters binding
  • Loading branch information
pdavide authored Nov 16, 2023
2 parents b3d680c + 55ab84e commit ffdd29a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions DisableTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Log;


/**
* Disable Tracking plugin.
Expand Down Expand Up @@ -96,11 +98,15 @@ public static function isSiteTrackingDisabled($siteId)
count(*) AS `disabled`
FROM ' . Common::prefixTable(self::TABLE_DISABLE_TRACKING_MAP) . '
WHERE
siteId = :siteId AND
siteId = ? AND
deleted_at IS NULL;
';

$state = Db::fetchAll($sql, [':siteId' => $siteId]);
try {
$state = Db::fetchAll($sql, [$siteId]);
} catch (\Exception $ex) {
Log::error($ex->getMessage());

}
$isSiteTrackingDisabled = (bool) $state[0]['disabled'];
$cache->save('DisableTracking_' . $siteId, $isSiteTrackingDisabled);

Expand Down Expand Up @@ -170,7 +176,6 @@ public static function changeDisableState($idSites, $disabled)
if (!self::sitesExist($idSites)) {
throw new \Exception('Check given site ids');
}

foreach ($idSites as $key => $idSite) {
if ('on' === $disabled) {
if (!self::isSiteTrackingDisabled($idSite)) {
Expand All @@ -183,8 +188,12 @@ public static function changeDisableState($idSites, $disabled)
WHERE
`deleted_at` IS NULL
AND
`siteId` = :idSite';
Db::query($sql, [':idSite' => $idSite]);
`siteId` = ?';
try {
Db::query($sql, [$idSite]);
} catch (\Exception $ex) {
Log::error($ex->getMessage());
}
}

$cache = Cache::getEagerCache();
Expand All @@ -210,9 +219,13 @@ private static function disableSiteTracking($id)
INSERT INTO `' . Common::prefixTable(self::TABLE_DISABLE_TRACKING_MAP) . '`
(siteId, created_at)
VALUES
(:siteId, NOW())
(?, NOW())
';
Db::query($sql, [':siteId' => $id]);
try {
Db::query($sql, [$id]);
} catch (\Exception $ex) {
Log::error($ex->getMessage());
}
}
}

Expand Down

0 comments on commit ffdd29a

Please sign in to comment.