Duplicate Customer Roles Bug - Still a bug?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I ran into this issue with v2.4.  There is a brief discussion about this bug in this thread.

However, I am still finding this to be an issue.  I tracked down what I think is happening.  Here is what I found and how I fixed it.

1. If you create an empty database and set your Settings.txt file config strings and run the application, all the tables are created with no installation data sans for a few exceptions.
2. RegisterDefaultPermissionsStartupTask.InstallPermissions is called which in turn calls StandardPermissionProvider.GetDefaultPermissions().  It is the later that creates 4 DefaultPermissionRecords which includes a respective CustomerRoleSystemName.
3.  Here then is where the culprit is:
//default customer role mappings
                    var defaultPermissions = permissionProvider.GetDefaultPermissions();
                    foreach (var defaultPermission in defaultPermissions)
                    {
                        var customerRole = _customerService.GetCustomerRoleBySystemName(defaultPermission.CustomerRoleSystemName);
                        if (customerRole == null)
                        {
                            //new role (save it)
                            customerRole = new CustomerRole()
                            {
                                Name = defaultPermission.CustomerRoleSystemName,
                                Active = true,
                                SystemName = defaultPermission.CustomerRoleSystemName
                            };
                            _customerService.InsertCustomerRole(customerRole);
                        }

4.  Finally if you view the db before running the install scripts, you will see the 4 customer roles already in the db.

What I did to fix:
1. Obviously we don't need to re-create these roles in InstallationService.InstallData.
2. Because these entries are already in the db BEFORE InstallData(); is called I passed in ICustomerService into the constructor of InstallationService.
3. From there I pulled necessary CustomerRoleSystemNames.
4. Here is the modified code from InstallData();
 var adminRole = _customerService.GetCustomerRoleBySystemName("Administrators");
           var registeredRole = _customerService.GetCustomerRoleBySystemName("Registered");
            var guestRole = _customerService.GetCustomerRoleBySystemName("Guests");

            //admin user
            var adminUser = new Customer
                                {
                                    CustomerGuid = Guid.NewGuid(),
                                    Email = defaultUserEmail,
                                    Password = defaultUserPassword,
                                    PasswordFormat = PasswordFormat.Clear,
                                    PasswordSalt = "",
                                    IsActive = true,
                                    CreatedOnUtc = DateTime.UtcNow,
                                    LastActivityDateUtc = DateTime.UtcNow,
                                };

            adminUser.CustomerRoles.Add(adminRole);
            adminUser.CustomerRoles.Add(registeredRole);
            _customerRepository.Insert(adminUser);

            //search engine (crawler) built-in user
            var searchEngineUser = new Customer()
            {
                Email = "builtin@search_engine_record.com",
                CustomerGuid = Guid.NewGuid(),
                PasswordFormat = PasswordFormat.Clear,
                IsActive = true,
                IsSystemAccount = true,
                SystemName = SystemCustomerNames.SearchEngine,
                CreatedOnUtc = DateTime.UtcNow,
                LastActivityDateUtc = DateTime.UtcNow,
            };
            searchEngineUser.CustomerRoles.Add(guestRole);
            _customerRepository.Insert(searchEngineUser);


That's it.  No more duplicates.  I may be missing something but I don't understand how NOT doing something like this will fix the problem.  Unless I have a version where InstallPermissions is NOT called at startup. The fact remains these roles get installed BEFORE installation data.  I think this is the right way.  We just don't need them included in InstallData();

Hope this was helpful and I welcome any comments.
t
12 years ago
The time this happened to me, I had accidentally ran the install twice.  I simply deleted the 4 roles in the database to fix it.
12 years ago
There's no such task (RegisterDefaultPermissionsStartupTask) in version 2.40. It was deleted several version ago. All permissions are created during installation (not before).

P.S. That bug (absolutely another one) was fixed in 2.20.
10 years ago
I POSTED BELOW ON ANOTHER POST

I WILL LOOK AT DATABASE NOW - SEE IF I CAN EDIT

OTHER THAN A COMPLETE REINSTALL - ANY SUGGESTIONS

I BELIEVE THAT I ALSO DID A INSTALL SEVERAL TIME TO TRY TO GET THE SITE RUNNING

AFTER IT WENT DOWN


THEN I DID SYSTEM RESTORE

IT WORKED AFTER SYSTEM RESTORE -

I HAD TO RELINK CATAGORIES


NOW DUPLICTATES AS LISTED



Ver 3.0

Duplicate stuff

I have 4 of everything in the " Message Templates"
I have 4 of all customer roles

I created a problem with adding info - after install

I thought that I had it all going well

I had to relink all items to all catagories after i deleted a site and then did a system restore.

I thought that it was OK - untill a few minutes ago - I see that I now have dupicate records.

I have 2 sites running on iis 8

I plan on several more - NOT MULTI WEB YET - INDEPENDENT WEBS

They were working Ok untill I deleted one of them - then did a system restore top correct issue

One site is working OK - the other is showing 4 duplicate items as mentioned above  

I do not want to have to do another install to correct this -

I do not have the source code version

Can I correct using fix W/O source ciode version

HELP
10 years ago
Note - I just checked DATABASE - MSSQL 2012 Standard - I see no duplicate records

I must be in NOPCOMMERCE

Can I fix w/o reinstalling - and w/o source code
10 years ago
Hello,

Did you ever fix this problem?

I have this same problem.  There are five entries for everything in Content Management/Topics, Content Management/Message Templates, Configuration/Stores, Configuration/Countries and numerous other settings in Administration.

I got everything working locally using the source version of 3.00 and this problem was not happening.  After I uploaded my site to Arvixe using the existing database that was installed locally, this problem surfaced.

The local version still works without this problem.

Does anybody have any idea of why this is happening?

Thanks,
Tony
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.