Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -r14572 -r14585 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14572) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14585) @@ -1,6 +1,6 @@ Application->GetVar($event->getPrefixSpecial(true) . '_PerPage'); $event->SetRedirectParam($event->getPrefixSpecial() . '_PerPage', $per_page); - $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial()); + $event->SetRedirectParam('pass', 'all,' . $event->getPrefixSpecial()); if (!$this->Application->isAdminUser) { $list_helper =& $this->Application->recallObject('ListHelper'); @@ -731,7 +731,7 @@ { $page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Page'); $event->SetRedirectParam($event->getPrefixSpecial() . '_Page', $page); - $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial()); + $event->SetRedirectParam('pass', 'all,' . $event->getPrefixSpecial()); if (!$this->Application->isAdminUser) { /*if ($page > 1) { @@ -1543,8 +1543,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); @@ -1582,16 +1581,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 !!! @@ -2077,7 +2066,12 @@ */ function OnAfterItemCreate(&$event) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + if ( !$object->IsTempTable() ) { + $this->_proccessPendingActions($event); + } } /** @@ -2099,7 +2093,12 @@ */ function OnAfterItemUpdate(&$event) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + if ( !$object->IsTempTable() ) { + $this->_proccessPendingActions($event); + } } /** @@ -2181,18 +2180,53 @@ } /** - * !!! 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 * * @param kEvent $event */ 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! @@ -2732,10 +2766,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)); } @@ -2828,6 +2862,7 @@ $field = $this->Application->GetVar('field'); $cur_value = $this->Application->GetVar('cur_value'); + $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); $object =& $event->getObject(); @@ -2841,7 +2876,7 @@ } $sql = 'SELECT DISTINCT '.$field.' - FROM '.$object->TableName.' + FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' WHERE '.$field.' LIKE '.$this->Conn->qstr($cur_value.'%').' ORDER BY '.$field.' LIMIT 0,' . $limit;