fix(GridFieldOrderableRows): Added additional SQL that updates the "LastEdited" column if working with a non-ManyManyList

This commit is contained in:
Jake Bentvelzen 2016-04-16 12:49:22 +10:00
parent 11ee7b0647
commit 51b5e657d6

View File

@ -349,13 +349,15 @@ class GridFieldOrderableRows extends RequestHandler implements
// Loop through each item, and update the sort values which do not // Loop through each item, and update the sort values which do not
// match to order the objects. // match to order the objects.
if (!$isVersioned) { if (!$isVersioned) {
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
foreach(array_values($order) as $pos => $id) { foreach(array_values($order) as $pos => $id) {
if($values[$id] != $pool[$pos]) { if($values[$id] != $pool[$pos]) {
DB::query(sprintf( DB::query(sprintf(
'UPDATE "%s" SET "%s" = %d WHERE %s', 'UPDATE "%s" SET "%s" = %d%s WHERE %s',
$this->getSortTable($list), $this->getSortTable($list),
$this->getSortField(), $this->getSortField(),
$pool[$pos], $pool[$pos],
$additionalSQL,
$this->getSortTableClauseForIds($list, $id) $this->getSortTableClauseForIds($list, $id)
)); ));
} }
@ -383,16 +385,18 @@ class GridFieldOrderableRows extends RequestHandler implements
$field = $this->getSortField(); $field = $this->getSortField();
$table = $this->getSortTable($list); $table = $this->getSortTable($list);
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField()); $clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
foreach($list->where($clause)->column('ID') as $id) { foreach($list->where($clause)->column('ID') as $id) {
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table)); $max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
$max = $max->value(); $max = $max->value();
DB::query(sprintf( DB::query(sprintf(
'UPDATE "%s" SET "%s" = %d WHERE %s', 'UPDATE "%s" SET "%s" = %d%s WHERE %s',
$table, $table,
$field, $field,
$max, $max,
$additionalSQL,
$this->getSortTableClauseForIds($list, $id) $this->getSortTableClauseForIds($list, $id)
)); ));
} }