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 Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r15856 -r16001 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15856) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 16001) @@ -1,6 +1,6 @@ Application->recallObject('FileHelper'); /* @var $file_helper FileHelper */ + if ( !file_exists($data['file']) ) { + // file removal was requested too + continue; + } + $old_name = basename($data['file']); $new_name = $file_helper->ensureUniqueFilename(dirname($data['file']), kUtil::removeTempExtension($old_name)); rename($data['file'], dirname($data['file']) . '/' . $new_name); @@ -3245,7 +3250,7 @@ unlink($file); } } - } + } /** * Checks, that flash uploader is allowed to perform upload