Skip to content

Commit

Permalink
Merge branch '2.0' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Feb 21, 2018
2 parents ab6dfab + b6f0322 commit e2bfcd1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions code/GridFieldOrderableRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,13 @@ protected function reorderItems($list, array $values, array $sortedIDs) {
$sortTable = $this->getSortTable($list);
$additionalSQL = '';
$baseTable = $sortTable;
$now = SS_Datetime::now()->Rfc2822();
if(class_exists($sortTable)) {
$baseTable = singleton($sortTable)->baseTable();
}
$isBaseTable = ($baseTable == $sortTable);
if(!$list instanceof ManyManyList && $isBaseTable){
$additionalSQL = ', "LastEdited" = NOW()';
$additionalSQL = ", \"LastEdited\" = '$now'";
}

foreach($sortedIDs as $sortValue => $id) {
Expand All @@ -491,7 +492,7 @@ protected function reorderItems($list, array $values, array $sortedIDs) {

if(!$isBaseTable) {
DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
"UPDATE \"%s\" SET \"LastEdited\" = '$now' WHERE %s",
$baseTable,
$this->getSortTableClauseForIds($list, $id)
));
Expand Down Expand Up @@ -520,6 +521,7 @@ protected function populateSortValues(DataList $list) {
$field = $this->getSortField();
$table = $this->getSortTable($list);
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
$now = SS_Datetime::now()->Rfc2822();

$additionalSQL = '';
$baseTable = $table;
Expand All @@ -528,7 +530,7 @@ protected function populateSortValues(DataList $list) {
}
$isBaseTable = ($baseTable == $table);
if(!$list instanceof ManyManyList && $isBaseTable){
$additionalSQL = ', "LastEdited" = NOW()';
$additionalSQL = ", \"LastEdited\" = '$now'";
}

foreach($list->where($clause)->column('ID') as $id) {
Expand All @@ -546,7 +548,7 @@ protected function populateSortValues(DataList $list) {

if(!$isBaseTable) {
DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
"UPDATE \"%s\" SET \"LastEdited\" = '$now' WHERE %s",
$baseTable,
$this->getSortTableClauseForIds($list, $id)
));
Expand Down

0 comments on commit e2bfcd1

Please sign in to comment.