Duplicate Links for Favorited Contacts

Hello,

I am having an issue where when I favorite a contact using the star icon next to their name, the name of that person appears twice in the favorites list. See pic:

image

I have tried clearing my cache folder, Quick Repairing, messing with some php files of the Favorites module, and verifying no duplicate record exist in the database but the issue persists.

When I create a new user and favorite them, they only appear as one link. But if I unfavorite them and favorite again they appear as two. So it seems both old and new contacts are affected by this.

SuiteCRM Version used: 7.11.20
Browser name and version: Chrome version 93.0.4577.63 (Official Build)(64-bit)
Environment name and version: Microsoft SQL Server, PHP 7.3.26, been running SCRM for 8+ months
Operating System and version: Windows Server 2019 Standard build 17763

It’s Default Issue in SuiteCRM 7.11.x Versions. Once you click on the Favourite from the particular record then it’ll add the two entries of Favourite in the database for that Record.

For Solved the Duplicate Favourites Record need to change in Query:

File Path: modules/Favorites/Favorites.php

Function Name: getCurrentUserSidebarFavorites()

Thank you for the screenshot. I checked against the DB and it was creating 2 DB entries when selecting a contact as ‘favorite.’ I applied the code change and that fixed the DB and it only creates one entry now. However, now I don’t see the favorited users on the sidebar at all. Have you heard of that behavior before?
Screenshots:
Before:


image

After:


Thank you

The solution which we have given is the Display only one entry on the sidebar for favorite Contact if DB contains the two Entries for the same Contact. The function shown in the screenshot is responsible for displaying the Favorite Contact on the sidebar. We didn’t face the problem which you’re saying after applying changes which we suggested.

That proposed change causes this error in the logs:

[FATAL]  Query Failed: SELECT parent_id, parent_type FROM favorites WHERE assigned_user_id = '1' AND deleted = 0 GROUP BY parent_id ORDER BY date_entered DESC
: MySQL error 1055: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'suitecrm.favorites.parent_type' 
which is not functionally dependent on columns in GROUP BY clause; 
this is incompatible with sql_mode=only_full_group_by

That depends on a MySQL option, maybe that’s why the behaviour is different for the two of you.

Maybe it’s better to tweak the query instead of starting to change MySQL options… what exactly is the idea behind that “GROUP BY”? I’m just trying to understand.

EDIT: This fixed query seems to work:

        if ($id) {
            $idQuote = $db->quote($id);
            $query = "SELECT parent_id, parent_type FROM favorites WHERE assigned_user_id = '" .
                    $currentUserIdQuote . "' AND parent_id = '" . $idQuote .
                    "' AND deleted = 0 GROUP BY parent_id, parent_type ORDER BY MAX(date_entered) DESC";
        } else {
            $query = "SELECT parent_id, parent_type FROM favorites WHERE assigned_user_id = '" .
                    $currentUserIdQuote . "' AND deleted = 0 GROUP BY parent_id, parent_type ORDER BY MAX(date_entered) DESC";
        }

But I am afraid this is just a dirty hack to workaround the issue. The real issue is that the Favorites are created twice, I see there are two (repeated) event handlers attached to the star button… and I see other repeated buttons on my screen. I’d love to find out the root cause of this…

For reference, it seems somebody already opened an issue for this:

Not sure why this is still unfixed for so long seems like a glaring issue, I just installed suite fresh recently, but for me this only happens when the url is ajaxui, (which is almost all the time). If I go direct with index.php?module=Accounts&action=DetailView&record= then click favorite star it does 1 instead of two, so maybe someone who knows what they are doing this will be helpful

Just have to keep applying it manually until it is included in an update