mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Added functionality so that GridFieldOrderableRows updates *_versions table for Versioned data objects.
This commit is contained in:
parent
7d1a48c5d7
commit
04d3f368c2
@ -339,17 +339,39 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
$pool = array_values($values);
|
$pool = array_values($values);
|
||||||
sort($pool);
|
sort($pool);
|
||||||
|
|
||||||
|
// If not a ManyManyList and using versioning, detect it.
|
||||||
|
$isVersioned = false;
|
||||||
|
$class = $list->dataClass();
|
||||||
|
if ($class == $this->getSortTable($list)) {
|
||||||
|
$isVersioned = $class::has_extension('Versioned');
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
foreach(array_values($order) as $pos => $id) {
|
if (!$isVersioned) {
|
||||||
if($values[$id] != $pool[$pos]) {
|
foreach(array_values($order) as $pos => $id) {
|
||||||
DB::query(sprintf(
|
if($values[$id] != $pool[$pos]) {
|
||||||
'UPDATE "%s" SET "%s" = %d WHERE %s',
|
DB::query(sprintf(
|
||||||
$this->getSortTable($list),
|
'UPDATE "%s" SET "%s" = %d WHERE %s',
|
||||||
$this->getSortField(),
|
$this->getSortTable($list),
|
||||||
$pool[$pos],
|
$this->getSortField(),
|
||||||
$this->getSortTableClauseForIds($list, $id)
|
$pool[$pos],
|
||||||
));
|
$this->getSortTableClauseForIds($list, $id)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For versioned objects, modify them with the ORM so that the
|
||||||
|
// *_versions table is updated. This ensures re-ordering works
|
||||||
|
// similar to the SiteTree where you change the position, and then
|
||||||
|
// you go into the record and publish it.
|
||||||
|
$sortField = $this->getSortField();
|
||||||
|
foreach(array_values($order) as $pos => $id) {
|
||||||
|
if($values[$id] != $pool[$pos]) {
|
||||||
|
$record = $class::get()->byID($id);
|
||||||
|
$record->$sortField = $pool[$pos];
|
||||||
|
$record->write();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user