From 7ff2c94e15f19473d0ffd94ba528c8852eda42a0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 12 Jul 2014 21:58:43 +0200 Subject: [PATCH 1/2] Add broken unit test for group order issue --- tests/grouphelpertest.php | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/grouphelpertest.php b/tests/grouphelpertest.php index 8279de0d..5d37451c 100644 --- a/tests/grouphelpertest.php +++ b/tests/grouphelpertest.php @@ -153,6 +153,82 @@ class GroupHelperTest extends \PHPUnit_Framework_TestCase { ), ), ), + array( + true, + array( + array( + 'activity_id' => 3, + 'user' => 'user', + 'affecteduser' => 'affecteduser', + 'app' => 'files', + 'type' => 'file_created', + 'subject' => 'created_self', + 'subjectparams' => serialize(array('testing/file3.txt')), + 'message' => '', + 'messageparams' => serialize(array()), + 'file' => 'testing/file3.txt', + 'timestamp' => time(), + ), + array( + 'activity_id' => 2, + 'user' => 'user', + 'affecteduser' => 'affecteduser', + 'app' => 'files', + 'type' => 'file_created', + 'subject' => 'created_self', + 'subjectparams' => serialize(array('testing/file2.txt')), + 'message' => '', + 'messageparams' => serialize(array()), + 'file' => 'testing/file2.txt', + 'timestamp' => time(), + ), + array( + 'activity_id' => 1, + 'user' => 'user', + 'affecteduser' => 'affecteduser', + 'app' => 'files', + 'type' => 'shared', + 'subject' => 'shared_link_self', + 'subjectparams' => serialize(array('testing/file1.txt')), + 'message' => '', + 'messageparams' => serialize(array()), + 'file' => 'testing/file1.txt', + 'timestamp' => time() - 10, + ), + ), + array( + array( + 'activity_id' => 3, + 'activity_ids' => array(3, 2), + 'user' => 'user', + 'affecteduser' => 'affecteduser', + 'app' => 'files', + 'type' => 'file_created', + 'subject' => 'created_self', + 'subjectparams' => array(array( + 'testing/file3.txt', + 'testing/file2.txt', + )), + 'message' => '', + 'messageparams' => array(), + 'file' => 'testing/file3.txt', + 'typeicon' => 'icon-add-color', + ), + array( + 'activity_id' => 1, + 'user' => 'user', + 'affecteduser' => 'affecteduser', + 'app' => 'files', + 'type' => 'shared', + 'subject' => 'shared_link_self', + 'subjectparams' => array('testing/file1.txt'), + 'message' => '', + 'messageparams' => array(), + 'file' => 'testing/file1.txt', + 'typeicon' => 'icon-share', + ), + ), + ), array( true, array( From a1b35825ecbdcb6e4be68a7b2ba9043b95b086e6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 12 Jul 2014 21:44:51 +0200 Subject: [PATCH 2/2] Correctly close group before adding non-grouped activity --- lib/data.php | 2 +- lib/grouphelper.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/data.php b/lib/data.php index 730d70d1..e7c607f1 100755 --- a/lib/data.php +++ b/lib/data.php @@ -210,7 +210,7 @@ class Data 'SELECT * ' . ' FROM `*PREFIX*activity` ' . ' WHERE `affecteduser` = ? ' . $limitActivities - . ' ORDER BY `timestamp` desc', + . ' ORDER BY `timestamp` DESC', $count, $start); $result = $query->execute($parameters); diff --git a/lib/grouphelper.php b/lib/grouphelper.php index 55643f56..1086d592 100644 --- a/lib/grouphelper.php +++ b/lib/grouphelper.php @@ -64,6 +64,12 @@ class GroupHelper } if (!$this->getGroupKey($activity)) { + if (!empty($this->openGroup)) { + $this->activities[] = $this->openGroup; + $this->openGroup = array(); + $this->groupKey = ''; + $this->groupTime = 0; + } $this->activities[] = $activity; return; }