Skip to content

Commit

Permalink
Update query for current acknowledgements
Browse files Browse the repository at this point in the history
  • Loading branch information
annda committed Dec 7, 2023
1 parent 8576ca8 commit b271ebc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
54 changes: 50 additions & 4 deletions _test/HelperTest.php
Expand Up @@ -38,23 +38,26 @@ public function setUp(): void
$pages = "REPLACE INTO pages(page,lastmod)
VALUES ('dokuwiki:acktest1', 1560805365),
('dokuwiki:acktest2', 1560805365),
('dokuwiki:acktest3', 1560805365)";
('dokuwiki:acktest3', 1560805365),
('dokuwiki:acktest4', 1560805365)";
$this->db->query($pages);

$assignments = "REPLACE INTO assignments(page,pageassignees)
VALUES ('dokuwiki:acktest1', 'regular, @super'),
('dokuwiki:acktest2', '@super'),
('dokuwiki:acktest3', '@user')";
('dokuwiki:acktest3', '@user'),
('dokuwiki:acktest4', 'max')";
$this->db->query($assignments);

// outdated, current, outdated but replaced, current replacing outdated, outdated
// outdated, current, outdated but replaced, current replacing outdated, outdated, outdated
$acks = "REPLACE INTO acks(page,user,ack)
VALUES
('dokuwiki:acktest3', 'regular', 1550801270),
('dokuwiki:acktest3', 'regular', 1560805555),
('dokuwiki:acktest1', 'max', 1550805770),
('dokuwiki:acktest1', 'max', 1560805770),
('dokuwiki:acktest3', 'max', 1560805000)
('dokuwiki:acktest3', 'max', 1560805000),
('dokuwiki:acktest4', 'max', 1560805000)
";
$this->db->query($acks);
}
Expand Down Expand Up @@ -84,6 +87,12 @@ public function test_getLatestAcknowledgements()
'ack' => '1560805000',
'lastmod' => '1560805365',
],
[
'page' => 'dokuwiki:acktest4',
'user' => 'max',
'ack' => '1560805000',
'lastmod' => '1560805365',
],
];
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -141,6 +150,14 @@ public function test_getUserAssignments()
'user' => null,
'ack' => null,
],
[
'page' => 'dokuwiki:acktest4',
'pageassignees' => 'max',
'autoassignees' => '',
'lastmod' => '1560805365',
'user' => null,
'ack' => null,
],
];
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -181,6 +198,15 @@ public function test_getUserAcknowledgementsAll()
'user' => 'max',
'ack' => '1560805000',
],
// outdated
[
'page' => 'dokuwiki:acktest4',
'pageassignees' => 'max',
'autoassignees' => '',
'lastmod' => '1560805365',
'user' => 'max',
'ack' => '1560805000',
],
];
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -210,6 +236,14 @@ public function test_getUserAcknowledgementsDue()
'user' => 'max',
'ack' => '1560805000',
],
[
'page' => 'dokuwiki:acktest4',
'pageassignees' => 'max',
'autoassignees' => '',
'lastmod' => '1560805365',
'user' => 'max',
'ack' => '1560805000',
],
];
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -252,6 +286,14 @@ public function test_getUserAcknowledgementsOutdated()
'user' => 'max',
'ack' => '1560805000',
],
[
'page' => 'dokuwiki:acktest4',
'pageassignees' => 'max',
'autoassignees' => '',
'lastmod' => '1560805365',
'user' => 'max',
'ack' => '1560805000',
],
];
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -321,5 +363,9 @@ public function test_getPageAcknowledgements()
],
];
$this->assertEquals($expected, $actual);

$actual = $this->helper->getPageAcknowledgements('dokuwiki:acktest4', '', 'current');
$expected = [];
$this->assertEquals($expected, $actual);
}
}
7 changes: 6 additions & 1 deletion helper.php
Expand Up @@ -510,6 +510,7 @@ public function getUserAcknowledgements($user, $groups, $status = '')
public function getPageAcknowledgements($page, $user = '', $status = '', $max = 0)
{
$userClause = '';
$filterClause = '';
$params[] = $page;

// filtering for user from input or using saved assignees?
Expand All @@ -522,13 +523,17 @@ public function getPageAcknowledgements($page, $user = '', $status = '', $max =
if (!$users) return [];
}

if ($status === 'current') {
$filterClause = ' AND ACK >= A.lastmod ';
}

$ulist = implode(',', array_map([$this->db->getPdo(), 'quote'], $users));
$sql = "SELECT A.page, A.lastmod, B.user, MAX(B.ack) AS ack
FROM pages A
LEFT JOIN acks B
ON A.page = B.page
AND B.user IN ($ulist)
WHERE A.page = ? $userClause";
WHERE A.page = ? $userClause $filterClause";
$sql .= " GROUP BY A.page, B.user ";
if ($max) $sql .= " LIMIT $max";

Expand Down

0 comments on commit b271ebc

Please sign in to comment.