Fix regression: make sql query compatible with Mysql

This commit is contained in:
Frederic Guillot 2016-01-17 15:27:18 -05:00
parent e94c4cab7f
commit e7a6147819
1 changed files with 5 additions and 3 deletions

View File

@ -168,9 +168,11 @@ class ProjectActivity extends Base
*/
public function cleanup($max)
{
if ($this->db->table(self::TABLE)->count() > $max) {
$subquery = $this->db->table(self::TABLE)->desc('id')->limit($max)->columns('id');
$this->db->table(self::TABLE)->notInSubquery('id', $subquery)->remove();
$total = $this->db->table(self::TABLE)->count();
if ($total > $max) {
$ids = $this->db->table(self::TABLE)->asc('id')->limit($total - $max)->findAllByColumn('id');
$this->db->table(self::TABLE)->in('id', $ids)->remove();
}
}