diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-01-30 23:44:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 23:44:41 +0300 |
commit | 3b836fa9e583713628e227d7bd86388ec8e2638b (patch) | |
tree | 0d4ee8917e9b5d4d5950651723ca871626b4279f /plugins/Live | |
parent | aeb7aa31a44ab422336523576a27f15559922c9f (diff) |
Trying to fix randomly failing tests (#15461)
Diffstat (limited to 'plugins/Live')
6 files changed, 63 insertions, 27 deletions
diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php index 99ff282848..fc2d29b3b0 100644 --- a/plugins/Live/Visitor.php +++ b/plugins/Live/Visitor.php @@ -16,6 +16,7 @@ use Piwik\Date; use Piwik\Metrics\Formatter; use Piwik\Plugin; use Piwik\Piwik; +use Piwik\Plugins\Live\Visualizations\VisitorLog; use Piwik\Tracker\GoalManager; class Visitor implements VisitorInterface @@ -291,7 +292,7 @@ class Visitor implements VisitorInterface $instance->filterActions($actionDetails, $visitorDetailsArray); } - usort($actionDetails, array('static', 'sortByServerTime')); + $actionDetails = self::sortActionDetails($actionDetails); $actionDetails = array_values($actionDetails); @@ -315,27 +316,21 @@ class Visitor implements VisitorInterface return $visitorDetailsArray; } - private static function sortByServerTime($a, $b) + private static function sortActionDetails($actions) { - $ta = strtotime($a['serverTimePretty']); - $tb = strtotime($b['serverTimePretty']); - - if ($ta < $tb) { - return -1; - } - - if ($ta == $tb) { - if ($a['idlink_va'] == $b['idlink_va']) { - return strcmp($a['type'], $b['type']); - } - - if ($a['idlink_va'] > $b['idlink_va']) { - return 1; + usort($actions, function ($a, $b) { + $fields = array('serverTimePretty', 'idlink_va', 'type', 'title', 'url', 'pageIdAction', 'goalId'); + foreach ($fields as $field) { + $sort = VisitorLog::sortByActionsOnPageColumn($a, $b, $field); + if ($sort !== 0) { + return $sort; + } } - return -1; - } + return 0; + }); - return 1; + return $actions; } + } diff --git a/plugins/Live/Visualizations/VisitorLog.php b/plugins/Live/Visualizations/VisitorLog.php index 31c0efcd9e..d6c3cd08a2 100644 --- a/plugins/Live/Visualizations/VisitorLog.php +++ b/plugins/Live/Visualizations/VisitorLog.php @@ -202,6 +202,23 @@ class VisitorLog extends Visualization } } + foreach ($actionGroups as $idPageView => $actionGroup) { + if (!empty($actionGroup['actionsOnPage'])) { + usort($actionGroup['actionsOnPage'], function ($a, $b) { + $fields = array('timestamp', 'title', 'url', 'type', 'pageIdAction', 'goalId', 'timeSpent'); + foreach ($fields as $field) { + $sort = self::sortByActionsOnPageColumn($a, $b, $field); + if ($sort !== 0) { + return $sort; + } + } + + return 0; + }); + $actionGroups[$idPageView]['actionsOnPage'] = $actionGroup['actionsOnPage']; + } + } + // merge action groups that have the same page url/action and no pageviewactions $actionGroups = self::mergeRefreshes($actionGroups); @@ -209,6 +226,30 @@ class VisitorLog extends Visualization } } + public static function sortByActionsOnPageColumn($a, $b, $field) + { + if (!isset($a[$field]) && !isset($b[$field])) { + return 0; + } + if (!isset($a[$field])) { + return -1; + } + if (!isset($b[$field])) { + return 1; + } + if ($field === 'serverTimePretty') { + $a[$field] = strtotime($a[$field]); + $b[$field] = strtotime($b[$field]); + } + if ($a[$field] === $b[$field]) { + return 0; + } + if ($a[$field] < $b[$field]) { + return -1; + } + return 1; + } + private static function mergeRefreshes(array $actionGroups) { $previousId = null; diff --git a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log.png b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log.png index e556fb1ffd..1128675542 100644 --- a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log.png +++ b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d3dbbfb7280b58c59197ae791c14fa7b4dcf40a4d868bd9ef77614055b05f199 -size 386906 +oid sha256:363ee1f7abca91be5422910989a2328cfc507f217d2eaf1008b8bd7862c49d1a +size 386911 diff --git a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log_expand_pageview_actions.png b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log_expand_pageview_actions.png index 1b98f667be..bca3118156 100644 --- a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log_expand_pageview_actions.png +++ b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_log_expand_pageview_actions.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:952d7e1a73a09d164f7d2b1acf83768b4d42159c46a3d11eb767d7fcd190864f -size 102198 +oid sha256:c7b27fe264d6b12a0383fe1e788c43d7544dbc7d8cd94752bedc56b081757804 +size 102195 diff --git a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile.png b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile.png index d181af2d47..3361725e7d 100644 --- a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile.png +++ b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3ac1caaa7a88f52c057c4d5331b9761a5d363a6e20f2809d60c1524461611af5 -size 418479 +oid sha256:9ca0fcc3ee5901df974c348fd7da020df9f4283bfd5768eba89b664717272000 +size 418489 diff --git a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile_limited.png b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile_limited.png index 8fea3c44f2..d46830adc0 100644 --- a/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile_limited.png +++ b/plugins/Live/tests/UI/expected-screenshots/Live_visitor_profile_limited.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:23ab3a8404d0c0fdc67fd30720968a7ba1f062e8b485f737c8894d0bc45b586b -size 310449 +oid sha256:81d25e5b1ecdd3bd0d094fccab4b387a1e00d147015b5621a68942edc2e65113 +size 310462 |