Finds base table to update LastEdited

This commit is contained in:
Dylan Sweetensen 2016-08-30 11:11:34 +12:00
parent 50ffec51e4
commit 799f0a0fe2

View File

@ -468,7 +468,16 @@ class GridFieldOrderableRows extends RequestHandler implements
// match to order the objects.
if (!$isVersioned) {
$sortTable = $this->getSortTable($list);
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
$additionalSQL = '';
$baseTable = $sortTable;
if(class_exists($sortTable)) {
$baseTable = singleton($sortTable)->baseTable();
}
$isBaseTable = ($baseTable == $sortTable);
if(!$list instanceof ManyManyList && $isBaseTable){
$additionalSQL = ', "LastEdited" = NOW()';
}
foreach($sortedIDs as $sortValue => $id) {
if($map[$id] != $sortValue) {
DB::query(sprintf(
@ -479,6 +488,14 @@ class GridFieldOrderableRows extends RequestHandler implements
$additionalSQL,
$this->getSortTableClauseForIds($list, $id)
));
if(!$isBaseTable) {
DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
$baseTable,
$this->getSortTableClauseForIds($list, $id)
));
}
}
}
} else {
@ -503,7 +520,16 @@ class GridFieldOrderableRows extends RequestHandler implements
$field = $this->getSortField();
$table = $this->getSortTable($list);
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
$additionalSQL = '';
$baseTable = $table;
if(class_exists($table)) {
$baseTable = singleton($table)->baseTable();
}
$isBaseTable = ($baseTable == $table);
if(!$list instanceof ManyManyList && $isBaseTable){
$additionalSQL = ', "LastEdited" = NOW()';
}
foreach($list->where($clause)->column('ID') as $id) {
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
@ -517,6 +543,14 @@ class GridFieldOrderableRows extends RequestHandler implements
$additionalSQL,
$this->getSortTableClauseForIds($list, $id)
));
if(!$isBaseTable) {
DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
$baseTable,
$this->getSortTableClauseForIds($list, $id)
));
}
}
}