Index: branches/5.2.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r15733 -r16001 --- branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 15733) +++ branches/5.2.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 16001) @@ -1,6 +1,6 @@ Application->RemoveVar($var_name); } else { - $this->Application->StoreVar($var_name, serialize($pending_actions)); + $this->Application->StoreVar($var_name, serialize($this->sortPendingActions($pending_actions))); } } /** + * Sorts pending actions the way, that `delete` action will come before other actions. + * + * @param array $pending_actions Pending actions. + * + * @return array + */ + protected function sortPendingActions(array $pending_actions) + { + usort($pending_actions, array($this, 'comparePendingActions')); + + return $pending_actions; + } + + protected function comparePendingActions($pending_action_a, $pending_action_b) + { + if ( $pending_action_a['action'] == $pending_action_b['action'] ) { + return 0; + } + + return $pending_action_a['action'] == 'delete' ? -1 : 1; + } + + /** * Allows to skip certain fields from getting into sql queries * * @param string $field_name