Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue caused if the LastEdited column is not on the same table …

…as the sort column
  • Loading branch information...
commit a44c66dcb923d3581b345209468ab79cb9260f70 1 parent 5af07ed
@UndefinedOffset authored
Showing with 22 additions and 4 deletions.
  1. +22 −4 code/forms/GridFieldSortableRows.php
View
26 code/forms/GridFieldSortableRows.php
@@ -183,6 +183,12 @@ protected function fixSortColumn($gridField, SS_List $dataList) {
user_error('Sort column '.$this->sortColumn.' could not be found in '.$gridField->getModelClass().'\'s ancestry', E_USER_ERROR);
exit;
}
+
+ //Find table containing the last edited column
+ $lastEditTable=false;
+ $class=$gridField->getModelClass();
+ $classes=array_keys(ClassInfo::ancestry($class, true));
+ $lastEditTable=$classes[0];
}
@@ -199,8 +205,11 @@ protected function fixSortColumn($gridField, SS_List $dataList) {
. ' WHERE "' . $componentField . '" = ' . $obj->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
}else {
DB::query('UPDATE "' . $table
- . '" SET "' . $sortColumn . '" = ' . ($max + $i) . ','
- . '"LastEdited"=\'' . date('Y-m-d H:i:s') . '\''
+ . '" SET "' . $sortColumn . '" = ' . ($max + $i)
+ . ' WHERE "ID" = '. $obj->ID);
+
+ DB::query('UPDATE "' . $lastEditTable
+ . '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\''
. ' WHERE "ID" = '. $obj->ID);
}
@@ -309,6 +318,12 @@ protected function saveGridRowSort(GridField $gridField, $data) {
user_error('Sort column '.$this->sortColumn.' could not be found in '.$gridField->getModelClass().'\'s ancestry', E_USER_ERROR);
exit;
}
+
+ //Find table containing the last edited column
+ $lastEditTable=false;
+ $class=$gridField->getModelClass();
+ $classes=array_keys(ClassInfo::ancestry($class, true));
+ $lastEditTable=$classes[0];
}
@@ -327,8 +342,11 @@ protected function saveGridRowSort(GridField $gridField, $data) {
. ' WHERE "' . $componentField . '" = ' . $id . ' AND "' . $parentField . '" = ' . $owner->ID);
} else {
DB::query('UPDATE "' . $table
- . '" SET "' . $sortColumn . '" = ' . (($sort + 1) + $pageOffset) . ','
- . '"LastEdited"=\'' . date('Y-m-d H:i:s') . '\''
+ . '" SET "' . $sortColumn . '" = ' . (($sort + 1) + $pageOffset)
+ . ' WHERE "ID" = '. $id);
+
+ DB::query('UPDATE "' . $lastEditTable
+ . '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\''
. ' WHERE "ID" = '. $id);
}
}

2 comments on commit a44c66d

@halkyon

Perhaps ClassInfo::baseDataClass() could be used here instead?

@UndefinedOffset

Ha awesome I knew there was a better way just couldn't remember what the method was :P ty

Please sign in to comment.
Something went wrong with that request. Please try again.