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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ jobs:
uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-ci.yml@main
with:
plugin-name: CustomVariables
# PHPStan has never run here and there is no phpstan.neon to run it with;
# adding one is a decision of its own.
skip-phpstan: true
11 changes: 5 additions & 6 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Piwik\Archive;
use Piwik\Container\StaticContainer;
use Piwik\DataTable;
use Piwik\Date;
use Piwik\Metrics;
use Piwik\Piwik;

Expand All @@ -28,21 +27,21 @@ class API extends \Piwik\Plugin\API
/**
* @param int $idSite
* @param string $period
* @param Date $date
* @param string $date
* @param string $segment
* @param bool $expanded
* @param int $idSubtable
* @param int|null $idSubtable
*
* @return DataTable|DataTable\Map
*/
protected function getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable)
{
$dataTable = Archive::createDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable);
$dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors');
$dataTable->queueFilter('ColumnDelete', ['nb_uniq_visitors']);

if ($flat) {
$dataTable->filterSubtables('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded));
$dataTable->queueFilterSubtables('ColumnDelete', 'nb_uniq_visitors');
$dataTable->queueFilterSubtables('ColumnDelete', ['nb_uniq_visitors']);
}

return $dataTable;
Expand Down Expand Up @@ -166,9 +165,9 @@ public function getUsagesOfSlots($idSite)
'page' => array_fill(1, $numVars, array()),
);

/** @var DataTable $customVarUsages */
$today = StaticContainer::get('CustomVariables.today');
$date = '2008-12-12,' . $today;
/** @var DataTable $customVarUsages */
$customVarUsages = Request::processRequest(
'CustomVariables.getCustomVariables',
array('idSite' => $idSite, 'period' => 'range', 'date' => $date,
Expand Down
2 changes: 1 addition & 1 deletion RecordBuilders/CustomVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function aggregate(ArchiveProcessor $archiveProcessor): array
}


protected function aggregateCustomVariable(DataTable $record, array &$metadata, array &$metadataFlat, LogAggregator $logAggregator, string $slot): void
protected function aggregateCustomVariable(DataTable $record, array &$metadata, array &$metadataFlat, LogAggregator $logAggregator, int $slot): void
{
$keyField = "custom_var_k" . $slot;
$valueField = "custom_var_v" . $slot;
Expand Down
4 changes: 1 addition & 3 deletions Reports/GetCustomVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public function getFooterMessageExplanationMissingMetrics()
// no footer message for subtables
$out = '';
Piwik::postEvent('Template.afterCustomVariablesReport', array(&$out));
if (!empty($message)) {
$message .= $out;
}
$message .= $out;
}

return $message;
Expand Down
6 changes: 5 additions & 1 deletion Tracker/CustomVariablesRequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function processRequestParams(VisitProperties $visitProperties, Request $
}

$request->setMetadata('CustomVariables', 'visitCustomVariables', $visitorCustomVariables);

return false;
}

public function onNewVisit(VisitProperties $visitProperties, Request $request)
Expand All @@ -71,7 +73,7 @@ public function afterRequestProcessed(VisitProperties $visitProperties, Request
$action = $request->getMetadata('Actions', 'action');

if (empty($action) || !($action instanceof Action)) {
return;
return false;
}

$customVariables = self::getCustomVariablesInPageScope($request);
Expand All @@ -84,6 +86,8 @@ public function afterRequestProcessed(VisitProperties $visitProperties, Request
$action->setCustomField($field, $value);
}
}

return false;
}

public static function getCustomVariablesInVisitScope(Request $request)
Expand Down
35 changes: 35 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
parameters:
level: 5
phpVersion: 80100
tmpDir: /tmp/phpstan/CustomVariables/main
paths:
- .
excludePaths:
analyseAndScan:
- tests/*
# The shared workflow leaves this helper checkout in the workspace, and `paths: .`
# would otherwise analyse it as if it were plugin code.
- github-action-tests/*
ignoreErrors:
# Row::setColumn() and deleteColumn() are untyped and only document `@param string`, while
# archiving addresses columns by the integer Metrics::INDEX_* constants throughout. Pinned
# to the five call sites that do so, so a sixth has to be looked at rather than absorbed.
-
identifier: argument.type
message: '#Row::(setColumn|deleteColumn)\(\) expects string, int given#'
path: RecordBuilders/CustomVariables.php
count: 5
# This plugin supports Matomo 5 and 6, but the analysis only ever sees one of them, so the
# version guard reads as decided. It is load-bearing on the other line.
-
identifier: ternary.alwaysTrue
path: RecordBuilders/CustomVariables.php
count: 1
bootstrapFiles:
- ../../bootstrap-phpstan.php
universalObjectCratesClasses:
- Piwik\Config
- Piwik\View
- Piwik\ViewDataTable\Config
scanDirectories:
- ../../
Loading