Skip to content
Merged
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
346 changes: 346 additions & 0 deletions .git-hooks-matomo/pre-push

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Plugins CI

on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches:
- '**.x-dev'
workflow_dispatch:

permissions:
actions: read
contents: read
pull-requests: read

jobs:
ci:
uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-ci.yml@main
with:
plugin-name: QueuedTracking
verify-hook: true
32 changes: 0 additions & 32 deletions .github/workflows/matomo-ai-checklist.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/phpcs.yml

This file was deleted.

14 changes: 7 additions & 7 deletions Commands/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ protected function configure()
$this->addRequiredValueOption('jumptopage', 'p', 'Jump to page (p).', 1);
}

/**
* @return int
*/
protected function doExecute(): int
{
$output = $this->getOutput();
Expand Down Expand Up @@ -112,12 +109,15 @@ protected function doExecute(): int
}

$numInQueue = 0;
// $qPerPAge is never 0 by the time we get here, so the loop below always runs,
// but PHPStan cannot see that and reads the $idx used underneath as undefined
$idx = 0;
for ($idxPage = 0; $idxPage < $qPerPAge; $idxPage++) {
$idx = ($qCurrentPage - 1) * $qPerPAge + $idxPage;
$idx = (int) (($qCurrentPage - 1) * $qPerPAge + $idxPage);
if (isset($queues[$idx])) {
$q = $queues[$idx]->getNumberOfRequestSetsInQueue();
$numInQueue += (int)$q;
$output->writeln(str_pad($idx, 10, " ", STR_PAD_LEFT) . " | " . str_pad(number_format($q), 16, " ", STR_PAD_LEFT));
$output->writeln(str_pad((string) $idx, 10, " ", STR_PAD_LEFT) . " | " . str_pad(number_format($q), 16, " ", STR_PAD_LEFT));
} else {
$output->writeln(str_pad("", 10) . " | " . str_pad("", 16));
}
Expand Down Expand Up @@ -223,7 +223,7 @@ private function getIterationsFromArg()
/**
* Loads the `rowperpage` argument from the commands arguments.
*
* @return int|null
* @return int
*/
private function getPerPageFromArg()
{
Expand All @@ -242,7 +242,7 @@ private function getPerPageFromArg()
/**
* Loads the `jumptopage` argument from the commands arguments.
*
* @return int|null
* @return int
*/
private function getJumpToPageFromArg()
{
Expand Down
5 changes: 1 addition & 4 deletions Commands/PrintQueuedRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ protected function configure()
$this->addRequiredValueOption('queue-id', null, 'If set, will print only requests of that queue');
}

/**
* @return int
*/
protected function doExecute(): int
{
$input = $this->getInput();
Expand All @@ -51,7 +48,7 @@ protected function doExecute(): int
$output->writeln(sprintf('<info>Showing requests of queue %s. Use <comment>--queue-id=%s</comment> to print only information for this queue.</info>', $thisQueueId, $thisQueueId));

$requests = $queue->getRequestSetsToProcess();
$output->writeln(var_export($requests, 1));
$output->writeln(var_export($requests, true));

$output->writeln(sprintf('<info>These were the requests of queue %s. Use <comment>--queue-id=%s</comment> to print only information for this queue.</info>', $thisQueueId, $thisQueueId));
}
Expand Down
7 changes: 3 additions & 4 deletions Commands/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected function configure()
* execute the task by calling a method of another class and output any useful information.
*
* Execute the command like: ./console queuedtracking:test --name="The Piwik Team"
* @return int
*/

protected function doExecute(): int
Expand Down Expand Up @@ -104,7 +103,7 @@ protected function doExecute(): int
}

$output->writeln('Backend version: ' . $backend->getServerVersion());
$output->writeln('Memory: ' . var_export($backend->getMemoryStats(), 1));
$output->writeln('Memory: ' . var_export($backend->getMemoryStats(), true));

$redis = $backend->getConnection();
if ($isUsingRedis && !$shouldSkipCheckingMemoryConfigValues) {
Expand Down Expand Up @@ -204,7 +203,7 @@ protected function doExecute(): int
if ($values == array('value3')) {
$output->writeln('List feature seems to work fine');
} else {
$output->writeln('List feature seems to work only partially: ' . var_export($values, 1));
$output->writeln('List feature seems to work only partially: ' . var_export($values, true));
}
} else {
$output->writeln('<error>List feature seems to not work fine: ' . $redis->getLastError() . '</error>');
Expand All @@ -217,7 +216,7 @@ protected function doExecute(): int
}

/**
* @param \Redis $redis
* @param \Redis|\RedisCluster|\Credis_Client $redis
* @param $configName
* @return string
*/
Expand Down
7 changes: 3 additions & 4 deletions Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

use Piwik\Plugins\QueuedTracking\Queue\Backend;
use Piwik\Tracker\RequestSet;
use Piwik\Plugins\QueuedTracking\Queue\Backend\Redis;

class Queue
{
public const PREFIX = 'trackingQueueV1';
public const JSON_STRING_PARAMS = [
'uadata'
'uadata',
];

/**
* @var Redis
* @var Backend
*/
private $backend;

Expand Down Expand Up @@ -119,7 +118,7 @@ public function markRequestSetsAsProcessed()
* The request array is passed by reference so that any changes are made to the original array. If any params are
* found, this simply encodes them into a JSON string again.
*
* @param array $requestArray
* @param mixed $requestArray
* @return void
*/
public function ensureJsonVarsAreStrings(&$requestArray)
Expand Down
2 changes: 2 additions & 0 deletions Queue/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function getNumValuesInList($key);

public function setIfNotExists($key, $value, $ttlInSeconds);

public function delete($key);

public function deleteIfKeyHasValue($key, $value);

public function hasAtLeastXRequestsQueued($key, $numValuesRequired);
Expand Down
7 changes: 2 additions & 5 deletions Queue/Backend/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Redis implements Backend
{
/**
* @var \Redis
* @var \Redis|null
*/
protected $redis;
protected $host;
Expand All @@ -25,7 +25,7 @@ class Redis implements Backend
protected $password;

/**
* @var int
* @var int|null
*/
protected $database;

Expand Down Expand Up @@ -177,9 +177,6 @@ public function getConnection()
return $this->redis;
}

/**
* @internal for tests only
*/
public function delete($key)
{
$this->connectIfNeeded();
Expand Down
13 changes: 7 additions & 6 deletions Queue/Backend/RedisCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
namespace Piwik\Plugins\QueuedTracking\Queue\Backend;

use Piwik\Log;
use Piwik\Piwik;
use Exception;

class RedisCluster extends Redis
{
/**
* @var \RedisCluster
* @var \RedisCluster|null
*/
protected $redis;
protected $host;
Expand Down Expand Up @@ -89,7 +91,7 @@ public function getMemoryStats()

$memory = array (
'used_memory_human' => 0,
'used_memory_peak_human' => 0
'used_memory_peak_human' => 0,
);

foreach ($hosts as $idx => $host) {
Expand Down Expand Up @@ -209,9 +211,6 @@ public function getConnection()
return $this->redis;
}

/**
* @internal for tests only
*/
public function delete($key)
{
$this->connectIfNeeded();
Expand Down Expand Up @@ -305,7 +304,9 @@ protected function connect()
throw new Exception(Piwik::translate('QueuedTracking_NumHostsNotMatchNumPorts'));
}

$hostsPorts = array_map(fn($host, $port): string => "$host:$port", $hosts, $ports);
$hostsPorts = array_map(function ($host, $port): string {
return "$host:$port";
}, $hosts, $ports);

try {
$this->redis = new \RedisCluster(null, $hostsPorts, $this->timeout, $this->timeout, true, $this->password);
Expand Down
4 changes: 2 additions & 2 deletions Queue/Backend/Sentinel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function connect()

foreach ($hosts as $index => $host) { // Sort or randomize as appropriate
try {
$configuredClient = new \Credis_Client($host, $ports[$index], $timeout = 0.5, $persistent = false);
$configuredClient = new \Credis_Client($host, (int) $ports[$index], $timeout = 0.5, $persistent = '');
$configuredClient->forceStandalone();
$configuredClient->connect();
if ($this->usePasswordForSentinelInstances && !empty($this->password)) {
Expand All @@ -52,7 +52,7 @@ protected function connect()
$this->timeout = 0.05;
}

$client = new \Credis_Client($master[0], $master[1], $this->timeout, $persistent = false, $this->database, $this->password);
$client = new \Credis_Client($master[0], $master[1], $this->timeout, $persistent = '', $this->database, $this->password);
$client->connect();

$this->redis = $client;
Expand Down
Loading
Loading