Replace raw SQL query by PicoDb

This commit is contained in:
Frederic Guillot
2016-01-17 08:12:44 -05:00
parent 27b9b7a727
commit 3c57626918
3 changed files with 6 additions and 22 deletions

View File

@@ -169,14 +169,8 @@ class ProjectActivity extends Base
public function cleanup($max)
{
if ($this->db->table(self::TABLE)->count() > $max) {
$this->db->execute('
DELETE FROM '.self::TABLE.'
WHERE id <= (
SELECT id FROM (
SELECT id FROM '.self::TABLE.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.'
) foo
)'
);
$subquery = $this->db->table(self::TABLE)->desc('id')->limit($max)->columns('id');
$this->db->table(self::TABLE)->notInSubquery('id', $subquery)->remove();
}
}