protected function populateSortValues(DataList $list)
{
$list = clone $list;
$field = $this->getSortField();
$table = $this->getSortTable($list);
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
$additionalSQL = !$list instanceof ManyManyList ? ', "LastEdited" = NOW()' : '';
foreach ($list->where($clause)->column('ID') as $id) {
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
$max = $max->value();
DB::query(sprintf('UPDATE "%s" SET "%s" = %d%s WHERE %s', $table, $field, $max, $additionalSQL, $this->getSortTableClauseForIds($list, $id)));
}
}