How can I move all old user groups to the new _Default_

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
mlarsen
Ensign (ENS)
Ensign (ENS)
Posts: 16
Joined: Thu Jun 10, 2010 8:24 am

How can I move all old user groups to the new _Default_

Post by mlarsen » Thu Dec 18, 2014 4:41 am

I have a lot of users who are part of a one person group with the group name of their email address. Is there a bulk way of converting all of them to the new _Default_ Group?

I tried the following

update ac_UserGroups
set groupid = 383 ' _Default_ group
where groupid <> 383
and groupid > 9 ' all my admin groups are below nine.

I get this error
Msg 2601, Level 14, State 1, Line 1
Cannot insert duplicate key row in object 'dbo.ac_UserGroups' with unique index 'ac_UserGroups_CK'.
The statement has been terminated.

I don't see a way to do this in the admin either other than one at a time and that is WAY to many...

Thanks

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How can I move all old user groups to the new _Default_

Post by jmestep » Fri Dec 19, 2014 3:19 am

It looks like you might need to add a criteria that the userid is not already in group 383. It looks like Able adds users to the default group at upgrade time.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
Naveed
Rear Admiral (RADM)
Rear Admiral (RADM)
Posts: 611
Joined: Thu Apr 03, 2008 4:48 am

Re: How can I move all old user groups to the new _Default_

Post by Naveed » Fri Dec 19, 2014 5:18 am

Use this query, it will add new user -> group relation for all users except admin users (groupId > 9) and anonymous users and users which are already not assigned to default group.

Code: Select all

INSERT INTO ac_UserGroups(UserId, GroupId)
	SELECT UserId, 383  
	FROM ac_Users WHERE UserId NOT IN 
		(SELECT DISTINCT U.UserId FROM ac_Users U LEFT JOIN ac_UserGroups UG ON U.UserId = UG.UserId 
		WHERE (UG.GroupId = 383 OR UG.UserId IS NOT NULL OR UG.GroupId < 9)) 
	AND IsAnonymous = 0

mlarsen
Ensign (ENS)
Ensign (ENS)
Posts: 16
Joined: Thu Jun 10, 2010 8:24 am

Re: How can I move all old user groups to the new _Default_

Post by mlarsen » Fri Dec 19, 2014 6:35 am

Thanks for the script but it returns 0 rows affected and in fact did not affect any of the user group assignments. Any other ideas?

rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Re: How can I move all old user groups to the new _Default_

Post by rmaweb » Fri Dec 19, 2014 2:13 pm

Are you going to use the old groups anymore? If not just delete them and if there are users in that group, the admin page will go to another that will allow you to select the group you want those users to be moved to.
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

mlarsen
Ensign (ENS)
Ensign (ENS)
Posts: 16
Joined: Thu Jun 10, 2010 8:24 am

Re: How can I move all old user groups to the new _Default_

Post by mlarsen » Fri Dec 19, 2014 4:22 pm

Yes I can do that but each user is in their own group. so I have LOTS of groups each with 1 member. I don't know if that was the original design of Able or a result of my accounting system integration with Able but that is where it is and I don't have the time to change the group of each user one at a time. I was hoping for a script to move them all to the _Default_ Group and then I can just delete the unused groups.

rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Re: How can I move all old user groups to the new _Default_

Post by rmaweb » Fri Dec 19, 2014 7:28 pm

Ah. Well if you don't have a time emergency , I might be able to have a solution available after Christmas that you can use.
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How can I move all old user groups to the new _Default_

Post by jmestep » Mon Dec 22, 2014 4:12 am

Did you look at some of the users in the admin to make sure they are not in the default group already? Or do you have some custom code to create users that overrode the upgrade?
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

mlarsen
Ensign (ENS)
Ensign (ENS)
Posts: 16
Joined: Thu Jun 10, 2010 8:24 am

Re: How can I move all old user groups to the new _Default_

Post by mlarsen » Tue Dec 23, 2014 3:03 pm

I resorted to brute force and got everyone in the office removing the people for the groups and assigning them to the default. tedious but done.

Post Reply