Index: db_event_handler.php =================================================================== --- db_event_handler.php (revision 14334) +++ db_event_handler.php (working copy) @@ -1571,8 +1571,7 @@ $this->setTempWindowID($event); $ids = $this->StoreSelectedIDs($event); - $var_name = $event->getPrefixSpecial().'_file_pending_actions'.$this->Application->GetVar('m_wid'); - $this->Application->RemoveVar($var_name); + $this->Application->RemoveVar( $this->_getPendingActionVariableName($event) ); $changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); $this->Application->RemoveVar($changes_var_name); @@ -1610,16 +1609,6 @@ return ; } - // Deleteing files scheduled for delete - $var_name = $event->getPrefixSpecial().'_file_pending_actions'.$this->Application->GetVar('m_wid'); - $schedule = $this->Application->RecallVar($var_name); - $schedule = $schedule ? unserialize($schedule) : array(); - foreach ($schedule as $data) { - if ($data['action'] == 'delete') { - unlink($data['file']); - } - } - if ($live_ids) { // ensure, that newly created item ids are avalable as if they were selected from grid // NOTE: only works if main item has subitems !!! @@ -2105,7 +2094,12 @@ */ function OnAfterItemCreate(&$event) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + if ( !$object->IsTempTable() ) { + $this->_proccessPendingActions($event); + } } /** @@ -2127,7 +2121,12 @@ */ function OnAfterItemUpdate(&$event) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + if ( !$object->IsTempTable() ) { + $this->_proccessPendingActions($event); + } } /** @@ -2209,7 +2208,6 @@ } /** - * !!! NOT FULLY IMPLEMENTED - SEE TEMP HANDLER COMMENTS (search by event name)!!! * Occures after an item has been copied to live table * Id of copied item is passed as event' 'id' param * @@ -2217,10 +2215,46 @@ */ function OnAfterCopyToLive(&$event) { + $this->_proccessPendingActions($event); + } + /** + * Processing file pending actions (e.g. delete scheduled files) + * + * @param kEvent $event + */ + function _proccessPendingActions(&$event) + { + $var_name = $this->_getPendingActionVariableName($event); + $schedule = $this->Application->RecallVar($var_name); + + if ( $schedule ) { + $schedule = unserialize($schedule); + + foreach ($schedule as $data) { + if ( $data['action'] == 'delete' ) { + unlink( $data['file'] ); + } + } + + $this->Application->RemoveVar($var_name); + } } /** + * Returns variable name, used to store pending file actions + * + * @param kEvent $event + * @return string + */ + function _getPendingActionVariableName(&$event) + { + $window_id = $this->Application->GetTopmostWid($event->Prefix); + + return $event->Prefix . '_file_pending_actions' . $window_id; + } + + /** * Occures before an item is cloneded * Id of ORIGINAL item is passed as event' 'id' param * Do not call object' Update method in this event, just set needed fields! @@ -2755,10 +2789,10 @@ $object =& $event->getObject( Array ('skip_autoload' => true) ); $options = $object->GetFieldOptions( $this->Application->GetVar('field') ); - $var_name = $event->getPrefixSpecial() . '_file_pending_actions' . $this->Application->GetVar('m_wid'); + $var_name = $this->_getPendingActionVariableName($event); $schedule = $this->Application->RecallVar($var_name); $schedule = $schedule ? unserialize($schedule) : Array (); - $schedule[] = Array ('action' => 'delete', 'file' => $path = FULL_PATH . $options['upload_dir'] . $this->Application->GetVar('file')); + $schedule[] = Array ('action' => 'delete', 'file' => FULL_PATH . $options['upload_dir'] . $this->Application->GetVar('file')); $this->Application->StoreVar($var_name, serialize($schedule)); }