Index: branches/5.2.x/core/units/category_items/category_items_event_handler.php =================================================================== diff -u -N -r14989 -r15065 --- branches/5.2.x/core/units/category_items/category_items_event_handler.php (.../category_items_event_handler.php) (revision 14989) +++ branches/5.2.x/core/units/category_items/category_items_event_handler.php (.../category_items_event_handler.php) (revision 15065) @@ -1,6 +1,6 @@ Conn->Query('UPDATE ' . $object->TableName . ' SET PrimaryCat = 1 WHERE (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ') AND (CategoryId = ' . $id . ')'); } - $event->setRedirectParams(Array ('opener' => 's'), true); + $event->SetRedirectParam('opener', 's'); } /** @@ -68,32 +68,42 @@ * @return void * @access protected */ - protected function customProcessing(&$event, $type) + protected function customProcessing(kEvent &$event, $type) { - if($event->Name == 'OnMassDelete') - { + if ( $event->Name == 'OnMassDelete' ) { $object =& $event->getObject(); $table_info = $object->getLinkedInfo(); - switch ($type) - { + switch ($type) { case 'before': $ids = $event->getEventParam('ids'); - if($ids) - { - $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')'); - $event->setEventParam('ids',$ids); + + if ( $ids ) { + $sql = 'SELECT CategoryId + FROM ' . $object->TableName . ' + WHERE (PrimaryCat = 0) AND (' . $table_info['ForeignKey'] . '=' . $table_info['ParentId'] . ') AND CategoryId IN (' . implode(',', $ids) . ')'; + $event->setEventParam('ids', $this->Conn->GetCol($sql)); } break; - // not needed because 'before' does not allow to delete primary cat! + // not needed because 'before' does not allow to delete primary cat! /*case 'after': // set 1st not deleted category as primary - $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')'); - if(!$has_primary) - { - $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); - $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')'); + $sql = 'SELECT COUNT(*) + FROM ' . $object->TableName . ' + WHERE (PrimaryCat = 1) AND (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ')'; + $has_primary = $this->Conn->GetOne($sql); + + if ( !$has_primary ) { + $sql = 'SELECT CategoryId + FROM ' . $object->TableName . ' + WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId']; + $cat_id = $this->Conn->GetOne($sql); + + $sql = 'UPDATE ' . $object->TableName . ' + SET PrimaryCat = 1 + WHERE (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ') AND (CategoryId = ' . $cat_id . ')'; + $this->Conn->Query($sql); } break;*/ } @@ -104,15 +114,21 @@ * Removes primary mark from cloned category items record * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterClone(&$event) + protected function OnAfterClone(kEvent &$event) { + parent::OnAfterClone($event); + $id = $event->getEventParam('id'); $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $sql = 'UPDATE %s SET PrimaryCat = 0 WHERE %s = %s'; - $this->Conn->Query( sprintf($sql, $table, $id_field, $id) ); + $sql = 'UPDATE %s + SET PrimaryCat = 0 + WHERE %s = %s'; + $this->Conn->Query(sprintf($sql, $table, $id_field, $id)); } /**