Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r15173 -r15252 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15173) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15252) @@ -1,6 +1,6 @@ Application->InitDone ? $this->Application->RecallVar('user_id') : USER_ROOT; $event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true)); $status_checked = false; + if ( $user_id == USER_ROOT || $this->CheckPermission($event) ) { // don't autoload item, when user doesn't have view permission $this->LoadItem($event); @@ -599,29 +600,7 @@ if ( !$perm_status ) { // when no permission to view item -> redirect to no permission template - if ( $this->Application->isDebugMode() ) { - $this->Application->Debugger->appendTrace(); - } - - trigger_error('ItemLoad Permission Failed for prefix [' . $event->getPrefixSpecial() . '] in ' . ($status_checked ? 'checkItemStatus' : 'CheckPermission') . '', E_USER_NOTICE); - $template = $this->Application->isAdmin ? 'no_permission' : $this->Application->ConfigValue('NoPermissionTemplate'); - - if ( $this->Application->GetVar('t') != $template ) { - // don't perform "no_permission" redirect if already on a "no_permission" template - if ( MOD_REWRITE ) { - $redirect_params = Array ( - 'm_cat_id' => 0, - 'next_template' => urlencode('external:' . $_SERVER['REQUEST_URI']), - ); - } - else { - $redirect_params = Array ( - 'next_template' => $this->Application->GetVar('t'), - ); - } - - $this->Application->Redirect($template, $redirect_params); - } + $this->_processItemLoadingError($event, $status_checked); } } @@ -634,6 +613,50 @@ } /** + * Processes case, when item wasn't loaded because of lack of permissions + * + * @param kEvent $event + * @param bool $status_checked + * @throws kNoPermissionException + * @return void + * @access protected + */ + protected function _processItemLoadingError($event, $status_checked) + { + $current_template = $this->Application->GetVar('t'); + $redirect_template = $this->Application->isAdmin ? 'no_permission' : $this->Application->ConfigValue('NoPermissionTemplate'); + $error_msg = 'ItemLoad Permission Failed for prefix [' . $event->getPrefixSpecial() . '] in ' . ($status_checked ? 'checkItemStatus' : 'CheckPermission') . ''; + + if ( $current_template == $redirect_template ) { + // don't perform "no_permission" redirect if already on a "no_permission" template + if ( $this->Application->isDebugMode() ) { + $this->Application->Debugger->appendTrace(); + } + + trigger_error($error_msg, E_USER_NOTICE); + + return; + } + + if ( MOD_REWRITE ) { + $redirect_params = Array ( + 'm_cat_id' => 0, + 'next_template' => urlencode('external:' . $_SERVER['REQUEST_URI']), + ); + } + else { + $redirect_params = Array ( + 'next_template' => $current_template, + ); + } + + $exception = new kNoPermissionException($error_msg); + $exception->setup($redirect_template, $redirect_params); + + throw $exception; + } + + /** * Build sub-tables array from configs * * @param kEvent $event @@ -2412,13 +2435,28 @@ * Occurs after deleting item, id of deleted item * is stored as 'id' param of event * + * Also deletes subscriptions to that particual item once it's deleted + * * @param kEvent $event * @return void * @access protected */ protected function OnAfterItemDelete(kEvent $event) { + $object = $event->getObject(); + /* @var $object kDBItem */ + $sql = 'SELECT EventId + FROM ' . TABLE_PREFIX . 'EmailEvents + WHERE BindToSystemEvent REGEXP "' . $this->Conn->escape($event->Prefix) . '[.]{0,1}([^:]*):(.*)"'; + $email_event_ids = $this->Conn->GetCol($sql); + + if ( $email_event_ids ) { + // e-mail events, connected to that unit prefix are found + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailEventSubscribers + WHERE ItemId = ' . $object->GetID() . ' AND EmailEventId IN (' . implode(',', $email_event_ids) . ')'; + $this->Conn->Query($sql); + } } /**