mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Finds base table to update LastEdited
This commit is contained in:
parent
50ffec51e4
commit
799f0a0fe2
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user