Skip to content

Commit

Permalink
Merge branch '5.x-dev' into example-plugin-record-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl authored Jun 26, 2023
2 parents 76a0fe2 + 860026e commit 9a9950a
Show file tree
Hide file tree
Showing 135 changed files with 3,379 additions and 974 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ tests/ export-ignore
.phpstorm.meta.php export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
.stylelintrc.json export-ignore
PULL_REQUEST_TEMPLATE export-ignore

# Linguist: language statistics
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/clean-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,6 @@ for x in .gitignore .gitmodules .gitattributes .git-blame-ignore-revs .bowerrc .
.phpstorm.meta.php .lfsconfig .travis.sh tsconfig.json tsconfig.spec.json \
.eslintrc.js .eslintignore .eslintrc .browserslistrc babel.config.js jest.config.js \
karma.conf.js karma-conf.js vue.config.js .npmignore .ncurc.json .prettierrc .jscsrc \
phpstan.neon phpstan.neon.dist package.xml; do
phpstan.neon phpstan.neon.dist package.xml .stylelintrc.json; do
find . -name "$x" -exec rm -f {} \;
done
29 changes: 29 additions & 0 deletions .github/workflows/stylelinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Stylelint

on: pull_request

permissions:
actions: none
checks: none
contents: none
deployments: none
issues: none
packages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: none

jobs:
phpcs:
name: stylelinter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
lfs: false
persist-credentials: false
- name: stylelint
run: |
npm install
npx stylelint "**/*.{css,less}" -f github
12 changes: 12 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"overrides": [
{
"files": ["**/*.less"],
"customSyntax": "postcss-less"
}
],
"ignoreFiles": ["node_modules/**/*", "vendor/**/*", "tests/**/*", "tmp/**/*", "misc/**/*", "plugins/*/vue/dist/*"],
"rules": {
"color-no-invalid-hex": true
}
}
10 changes: 5 additions & 5 deletions DIObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

if (!function_exists("\DI\object")) {

function object()
function object(...$params)
{
return call_user_func_array("\Piwik\DI::autowire", func_get_args());
return \Piwik\DI::autowire(...$params);
}

}

if (!function_exists("\DI\link")) {

function link()
function link(...$params)
{
return call_user_func_array("\Piwik\DI::get", func_get_args());
return \Piwik\DI::get(...$params);
}

}
}
11 changes: 6 additions & 5 deletions core/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ public function getCssInclusionDirective()
/**
* Return JS file inclusion directive(s) using the markup <script>
*
* @param bool $deferJS
* @return string
*/
public function getJsInclusionDirective()
public function getJsInclusionDirective(bool $deferJS = false): string
{
$result = "<script type=\"text/javascript\">\n" . StaticContainer::get('Piwik\Translation\Translator')->getJavascriptTranslations() . "\n</script>";

Expand All @@ -150,8 +151,8 @@ public function getJsInclusionDirective()

$result .= $this->getIndividualCoreAndNonCoreJsIncludes();
} else {
$result .= sprintf(self::JS_IMPORT_DIRECTIVE, self::GET_CORE_JS_MODULE_ACTION);
$result .= sprintf(self::JS_IMPORT_DIRECTIVE, self::GET_NON_CORE_JS_MODULE_ACTION);
$result .= sprintf($deferJS ? self::JS_DEFER_IMPORT_DIRECTIVE : self::JS_IMPORT_DIRECTIVE, self::GET_CORE_JS_MODULE_ACTION);
$result .= sprintf($deferJS ? self::JS_DEFER_IMPORT_DIRECTIVE : self::JS_IMPORT_DIRECTIVE, self::GET_NON_CORE_JS_MODULE_ACTION);

$result .= $this->getPluginUmdChunks();
}
Expand Down Expand Up @@ -376,7 +377,7 @@ private function getMergedJavascript($assetFetcher, $mergedAsset)
*
* @return string
*/
protected function getIndividualCoreAndNonCoreJsIncludes()
protected function getIndividualCoreAndNonCoreJsIncludes(): string
{
return
$this->getIndividualJsIncludesFromAssetFetcher($this->getCoreJScriptFetcher()) .
Expand All @@ -388,7 +389,7 @@ protected function getIndividualCoreAndNonCoreJsIncludes()
* @param UIAssetFetcher $assetFetcher
* @return string
*/
protected function getIndividualJsIncludesFromAssetFetcher($assetFetcher)
protected function getIndividualJsIncludesFromAssetFetcher($assetFetcher): string
{
$jsIncludeString = '';

Expand Down
6 changes: 3 additions & 3 deletions core/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public static function prefixTable($table)
/**
* Returns an array containing the prefixed table names of every passed argument.
*
* @param string ... The table names to prefix, ie "log_visit"
* @param string ...$tables The table names to prefix, ie "log_visit"
* @return array The prefixed names in an array.
*/
public static function prefixTables()
public static function prefixTables(...$tables)
{
$result = array();
foreach (func_get_args() as $table) {
foreach ($tables as $table) {
$result[] = self::prefixTable($table);
}
return $result;
Expand Down
29 changes: 13 additions & 16 deletions core/DataAccess/ArchivingDbAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,52 @@ public function __call($name, $arguments)
return call_user_func_array([$this->wrapped, $name], $arguments);
}

public function exec($sql)
public function exec($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

public function query($sql)
public function query($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

public function fetchAll($sql)
public function fetchAll($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

public function fetchRow($sql)
public function fetchRow($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

public function fetchOne($sql)
public function fetchOne($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

public function fetchAssoc($sql)
public function fetchAssoc($sql, ...$params)
{
$sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime);
$this->logSql($sql);

return call_user_func_array([$this, "callFunction"], array_merge([__FUNCTION__], func_get_args()));
return $this->callFunction(__FUNCTION__, $sql, ...$params);
}

/**
Expand All @@ -112,10 +112,7 @@ private function logSql($sql)
}
}

private function callFunction($function) {

$args = func_get_args();
unset($args[0]);
private function callFunction($function, ...$args) {

try {
return call_user_func_array([$this->wrapped, $function], $args);
Expand Down
27 changes: 2 additions & 25 deletions core/DataArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Piwik;

use Exception;
use Piwik\DataTable\Filter\EnrichRecordWithGoalMetricSums;
use Piwik\Tracker\GoalManager;

/**
Expand Down Expand Up @@ -378,31 +379,7 @@ public function enrichMetricsWithConversions()
protected function enrichWithConversions(&$data)
{
foreach ($data as &$values) {
if (!isset($values[Metrics::INDEX_GOALS])) {
continue;
}

$revenue = $conversions = 0;
foreach ($values[Metrics::INDEX_GOALS] as $idgoal => $goalValues) {
// Do not sum Cart revenue since it is a lost revenue
if ($idgoal >= GoalManager::IDGOAL_ORDER) {
$revenue += $goalValues[Metrics::INDEX_GOAL_REVENUE];
$conversions += $goalValues[Metrics::INDEX_GOAL_NB_CONVERSIONS];
}
}
$values[Metrics::INDEX_NB_CONVERSIONS] = $conversions;

// 25.00 recorded as 25
if (round($revenue) == $revenue) {
$revenue = round($revenue);
}
$values[Metrics::INDEX_REVENUE] = $revenue;

// if there are no "visit" column, we force one to prevent future complications
// eg. This helps the setDefaultColumnsToDisplay() call
if (!isset($values[Metrics::INDEX_NB_VISITS])) {
$values[Metrics::INDEX_NB_VISITS] = 0;
}
EnrichRecordWithGoalMetricSums::enrichWithConversions($values);
}
}

Expand Down
32 changes: 32 additions & 0 deletions core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class AddColumnsProcessedMetricsGoal extends AddColumnsProcessedMetrics
*/
const GOALS_FULL_TABLE = 0;

const ACTIONS_PAGE_REPORTS_WITH_GOAL_METRICS = ['Actions.getPageUrls', 'Actions.getPageTitles'];

const ACTIONS_ENTRY_PAGE_REPORTS_WITH_GOAL_METRICS = ['Actions.getEntryPageUrls', 'Actions.getEntryPageTitles'];

/**
* @var string
*/
Expand Down Expand Up @@ -218,4 +222,32 @@ private function getGoalsInTable(DataTable $table)
}
return array_unique($result);
}

/**
* Returns an idGoal override to use for the processOnlyIdGoal parameter of this filter if $requestMethod
* is for a Actions page report or an Actions entry page report.
*
* @param int|string|null $idGoal if set to ecommerceOrder or ecommerceAbandonedCart, returns a processOnlyIdGoal value
* that will result in extra ecommerce metrics being computed
* @return int|string|null
*/
public static function getProcessOnlyIdGoalToUseForReport($idGoal, string $requestMethod)
{
// Check if one of the pages display types should be used
if (in_array($requestMethod, self::ACTIONS_PAGE_REPORTS_WITH_GOAL_METRICS)) {
if ($idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER || $idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
return self::GOALS_PAGES_ECOMMERCE;
} else {
return self::GOALS_PAGES;
}
} elseif (in_array($requestMethod, self::ACTIONS_ENTRY_PAGE_REPORTS_WITH_GOAL_METRICS)) {
if ($idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER || $idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
return self::GOALS_ENTRY_PAGES_ECOMMERCE;
} else {
return self::GOALS_ENTRY_PAGES;
}
}

return $idGoal;
}
}
66 changes: 66 additions & 0 deletions core/DataTable/Filter/EnrichRecordWithGoalMetricSums.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\DataTable\Filter;

use Piwik\DataTable\BaseFilter;
use Piwik\Metrics;
use Piwik\Tracker\GoalManager;

/**
* This filter will check for goal metrics in every row in a DataTable (that is, the Metrics::INDEX_GOALS
* column), and if found, adds the sum of all goal conversions and sum of revenue as two new fields.
*
* This filter is used by RecordBuilders during archiving.
*/
class EnrichRecordWithGoalMetricSums extends BaseFilter
{
public function filter($table)
{
foreach ($table->getRows() as $row) {
$columns = $row->getColumns();
self::enrichWithConversions($columns);
$row->setColumns($columns);

$subtable = $row->getSubtable();
if ($subtable) {
$this->filter($subtable);
}
}
}

public static function enrichWithConversions(&$values): void
{
if (!isset($values[Metrics::INDEX_GOALS])) {
return;
}

$revenue = $conversions = 0;
foreach ($values[Metrics::INDEX_GOALS] as $idgoal => $goalValues) {
// Do not sum Cart revenue since it is a lost revenue
if ($idgoal >= GoalManager::IDGOAL_ORDER) {
$revenue += $goalValues[Metrics::INDEX_GOAL_REVENUE];
$conversions += $goalValues[Metrics::INDEX_GOAL_NB_CONVERSIONS];
}
}
$values[Metrics::INDEX_NB_CONVERSIONS] = $conversions;

// 25.00 recorded as 25
if (round($revenue) == $revenue) {
$revenue = round($revenue);
}
$values[Metrics::INDEX_REVENUE] = $revenue;

// if there are no "visit" column, we force one to prevent future complications
// eg. This helps the setDefaultColumnsToDisplay() call
if (!isset($values[Metrics::INDEX_NB_VISITS])) {
$values[Metrics::INDEX_NB_VISITS] = 0;
}
}
}
Loading

0 comments on commit 9a9950a

Please sign in to comment.