Merge pull request #12488 from owncloud/activity_group_multiple_conditions
activitymanager: concatenate queries with 'or'
This commit is contained in:
commit
f0e6876f2e
|
@ -247,16 +247,28 @@ class ActivityManager implements IManager {
|
|||
* @return array
|
||||
*/
|
||||
function getQueryForFilter($filter) {
|
||||
|
||||
$conditions = array();
|
||||
$parameters = array();
|
||||
|
||||
foreach($this->extensions as $extension) {
|
||||
$c = $extension();
|
||||
if ($c instanceof IExtension) {
|
||||
$result = $c->getQueryForFilter($filter);
|
||||
if (is_array($result)) {
|
||||
return $result;
|
||||
list($condition, $parameter) = $result;
|
||||
if ($condition && is_array($parameter)) {
|
||||
$conditions[] = $condition;
|
||||
$parameters = array_merge($parameters, $parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(null, null);
|
||||
if (empty($conditions)) {
|
||||
return array(null, null);
|
||||
}
|
||||
|
||||
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,11 +87,14 @@ class Test_ActivityManager extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testQueryForFilter() {
|
||||
$this->activityManager->registerExtension(function() {
|
||||
return new SimpleExtension();
|
||||
});
|
||||
$result = $this->activityManager->getQueryForFilter('filter1');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'`app` = ? and `message` like ?',
|
||||
array('mail', 'ownCloud%')
|
||||
' and ((`app` = ? and `message` like ?) or (`app` = ? and `message` like ?))',
|
||||
array('mail', 'ownCloud%', 'mail', 'ownCloud%')
|
||||
), $result
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue