Index: branches/5.3.x/core/units/users/users_event_handler.php =================================================================== diff -u -N -r15938 -r15986 --- branches/5.3.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 15938) +++ branches/5.3.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 15986) @@ -1,6 +1,6 @@ Application->GetTempName($ug_table, 'prefix:' . $event->Prefix); } + $sql = 'SELECT COUNT(*) + FROM ' . $ug_table . ' + WHERE PortalUserId = ' . $object->GetID() . ' AND GroupId = ' . $primary_group_id; + + if ( $this->Conn->GetOne($sql) ) { + return; + } + $fields_hash = Array ( 'PortalUserId' => $object->GetID(), 'GroupId' => $primary_group_id, ); - $this->Conn->doInsert($fields_hash, $ug_table, 'REPLACE'); + if ( $object->IsTempTable() ) { + $new_id = (int)$this->Conn->GetOne('SELECT MIN(Id) FROM ' . $ug_table .' WHERE Id < 0' ); + $fields_hash['Id'] = $new_id - 1; + } + + $this->Conn->doInsert($fields_hash, $ug_table); } } Index: branches/5.3.x/core/kernel/db/cat_dbitem.php =================================================================== diff -u -N -r15938 -r15986 --- branches/5.3.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 15938) +++ branches/5.3.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 15986) @@ -1,6 +1,6 @@ Conn->Query($sql); } else { - $fields_hash = Array( + $fields_hash = Array ( 'CategoryId' => $category_id, 'ItemResourceId' => $this->GetField('ResourceId'), 'PrimaryCat' => $is_primary ? 1 : 0, 'ItemPrefix' => $this->Prefix, 'Filename' => $this->useFilenames ? (string)$this->GetDBField('Filename') : '', // because some prefixes does not use filenames, ); + if ( $this->Application->IsTempTable($table) ) { + $new_id = (int)$this->Conn->GetOne('SELECT MIN(Id) FROM ' . $table .' WHERE Id < 0' ); + $fields_hash['Id'] = $new_id - 1; + } + $this->Conn->doInsert($fields_hash, $table); } Index: branches/5.3.x/core/admin_templates/users/users_edit_groups.tpl =================================================================== diff -u -N -r15974 -r15986 --- branches/5.3.x/core/admin_templates/users/users_edit_groups.tpl (.../users_edit_groups.tpl) (revision 15974) +++ branches/5.3.x/core/admin_templates/users/users_edit_groups.tpl (.../users_edit_groups.tpl) (revision 15986) @@ -94,7 +94,7 @@ - + Index: branches/5.3.x/core/units/user_groups/user_groups_dbitem.php =================================================================== diff -u -N --- branches/5.3.x/core/units/user_groups/user_groups_dbitem.php (revision 15483) +++ branches/5.3.x/core/units/user_groups/user_groups_dbitem.php (revision 0) @@ -1,42 +0,0 @@ -getLinkedInfo($this->Special, true); - - if ( $table_info ) { - // we have parent info, then use it - $keys_hash = Array ($this->IDField => $this->GetID(), $table_info['ForeignKey'] => $table_info['ParentId']); - } - - return parent::GetKeyClause($method, $keys_hash); - } -} \ No newline at end of file Index: branches/5.3.x/core/install/install_schema.sql =================================================================== diff -u -N -r15956 -r15986 --- branches/5.3.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15956) +++ branches/5.3.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15986) @@ -407,11 +407,13 @@ ); CREATE TABLE UserGroupRelations ( + Id int(11) NOT NULL auto_increment, PortalUserId int(11) NOT NULL DEFAULT '0', GroupId int(11) NOT NULL DEFAULT '0', MembershipExpires int(10) unsigned DEFAULT NULL, ExpirationReminderSent tinyint(4) NOT NULL DEFAULT '0', - PRIMARY KEY (PortalUserId,GroupId), + PRIMARY KEY (Id), + UNIQUE KEY UserGroup (PortalUserId,GroupId), KEY GroupId (GroupId), KEY MembershipExpires (MembershipExpires), KEY ExpirationReminderSent (ExpirationReminderSent) @@ -636,11 +638,13 @@ ); CREATE TABLE CategoryItems ( + Id int(11) NOT NULL auto_increment, CategoryId int(11) NOT NULL default '0', ItemResourceId int(11) NOT NULL default '0', PrimaryCat tinyint(4) NOT NULL default '0', ItemPrefix varchar(50) NOT NULL default '', Filename varchar(255) NOT NULL default '', + PRIMARY KEY (Id), UNIQUE KEY CategoryId (CategoryId,ItemResourceId), KEY PrimaryCat (PrimaryCat), KEY ItemPrefix (ItemPrefix), @@ -1052,11 +1056,13 @@ ); CREATE TABLE SpamControl ( + Id int(11) NOT NULL auto_increment, ItemResourceId int(11) NOT NULL default '0', IPaddress varchar(20) NOT NULL default '', Expire INT UNSIGNED NULL DEFAULT NULL, PortalUserId int(11) NOT NULL default '0', DataType varchar(20) default NULL, + PRIMARY KEY (Id), KEY PortalUserId (PortalUserId), KEY Expire (Expire), KEY DataType (DataType), Index: branches/5.3.x/core/units/user_groups/user_groups_config.php =================================================================== diff -u -N -r15677 -r15986 --- branches/5.3.x/core/units/user_groups/user_groups_config.php (.../user_groups_config.php) (revision 15677) +++ branches/5.3.x/core/units/user_groups/user_groups_config.php (.../user_groups_config.php) (revision 15986) @@ -1,6 +1,6 @@ 'GroupId', 'ParentTableKey' => 'GroupId', - 'IDField' => 'PortalUserId', - 'ListSQLs' => Array ( '' => ' SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'UserGroups g ON %1$s.GroupId = g.GroupId @@ -45,7 +43,7 @@ 'GroupUsers' => Array ( 'Icons' => Array ('default' => 'icon16_item.png'), 'Fields' => Array ( - 'PortalUserId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ), + 'Id' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ), 'UserName' => Array ('title' => 'la_col_UserFirstLastName', 'width' => 200, ), 'UserLogin' => Array ('title' => 'column:la_fld_Username', 'width' => 100, ), 'PrimaryGroup' => Array ( 'title' => 'la_col_PrimaryGroup', 'filter_block' => 'grid_options_filter', 'width' => 100, ), @@ -62,7 +60,7 @@ ), ), - 'ItemClass' => Array ('class' => 'UserGroups_DBItem', 'file' => 'user_groups_dbitem.php', 'build_event' => 'OnItemBuild'), + 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), 'EventHandlerClass' => Array ('class' => 'UserGroupsEventHandler', 'file' => 'user_groups_eh.php', 'build_event' => 'OnBuild'), 'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'), @@ -76,7 +74,7 @@ 4 => 'event', ), - 'IDField' => 'GroupId', + 'IDField' => 'Id', 'TitleField' => 'GroupName', 'TableName' => TABLE_PREFIX.'UserGroupRelations', @@ -100,6 +98,7 @@ ), 'Fields' => Array ( + 'Id' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'PortalUserId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'GroupId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'MembershipExpires' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => null), @@ -124,7 +123,7 @@ 1 => 'icon16_primary.png' ), 'Fields' => Array ( - 'GroupId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ), + 'Id' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ), 'GroupName' => Array ('width' => 100, ), 'GroupDescription' => Array ('title' => 'column:la_fld_Description', 'width' => 150, ), 'PrimaryGroup' => Array ( 'title' => 'la_col_PrimaryGroup', 'filter_block' => 'grid_options_filter', 'width' => 150, ), Index: branches/5.3.x/core/units/category_items/category_items_dbitem.php =================================================================== diff -u -N --- branches/5.3.x/core/units/category_items/category_items_dbitem.php (revision 15483) +++ branches/5.3.x/core/units/category_items/category_items_dbitem.php (revision 0) @@ -1,47 +0,0 @@ -getLinkedInfo(); - - return '(CategoryId=' . $this->GetID() . ' AND ' . $table_info['ForeignKey'] . '=' . $table_info['ParentId'] . ')'; - } - - /** - * Generate and set new temporary id - * - * @return void - * @access public - */ - public function setTempID() - { - // don't set temp id for this item - } -} \ No newline at end of file Index: branches/5.3.x/core/admin_templates/groups/groups_edit_users.tpl =================================================================== diff -u -N -r15974 -r15986 --- branches/5.3.x/core/admin_templates/groups/groups_edit_users.tpl (.../groups_edit_users.tpl) (revision 15974) +++ branches/5.3.x/core/admin_templates/groups/groups_edit_users.tpl (.../groups_edit_users.tpl) (revision 15986) @@ -86,7 +86,7 @@ - + Index: branches/5.3.x/core/units/category_items/category_items_event_handler.php =================================================================== diff -u -N -r15902 -r15986 --- branches/5.3.x/core/units/category_items/category_items_event_handler.php (.../category_items_event_handler.php) (revision 15902) +++ branches/5.3.x/core/units/category_items/category_items_event_handler.php (.../category_items_event_handler.php) (revision 15986) @@ -1,6 +1,6 @@ getLinkedInfo(); $this->Conn->Query('UPDATE ' . $object->TableName . ' SET PrimaryCat = 0 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 = ' . $id . ')'); + $this->Conn->Query('UPDATE ' . $object->TableName . ' SET PrimaryCat = 1 WHERE (' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'] . ') AND (Id = ' . $id . ')'); } $event->SetRedirectParam('opener', 's'); } /** - * Apply custom processing to item - * - * @param kEvent $event - * @param string $type - * @return void - * @access protected - */ - protected function customProcessing(kEvent $event, $type) - { - if ( $event->Name == 'OnMassDelete' ) { - $object = $event->getObject(); - $table_info = $object->getLinkedInfo(); - - switch ($type) { - case 'before': - $ids = $event->getEventParam('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! - /*case 'after': - // set 1st not deleted category as primary - $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;*/ - } - } - } - - /** * Removes primary mark from cloned category items record * * @param kEvent $event