News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[SMF 2.1.4] Duplicate entry for key smf_user_likes

Started by MobileCS, November 25, 2023, 11:09:10 AM

Previous topic - Next topic

MobileCS

Just saw this for the first time this morning :

Type of error
Database

Error message
Database Error: Duplicate entry '700264-msg-19297' for key 'smf_user_likes.PRIMARY'

File
/www/example.com/httpdocs/forum/Sources/Likes.php

Line
342

URL of page causing the error
hxxps://example.com/forum/index.php?action=likes;ltype=msg;sa=like;like=700264;e00412418867=445d96d2e4fb245e9b9eeac0de580599;js=1&_=1700913478921

Backtrace information
#0: smf_db_error()
Called from /www/example.com/httpdocs/forum/Sources/Subs-Db-mysql.php on line 494
#1: smf_db_query()
Called from /www/example.com/httpdocs/forum/Sources/Subs-Db-mysql.php on line 802
#2: smf_db_insert()
Called from /www/example.com/httpdocs/forum/Sources/Likes.php on line 342
#3: insert()
Called from /www/example.com/httpdocs/forum/Sources/Likes.php on line 430
#4: like()
Called from /www/example.com/httpdocs/forum/Sources/Likes.php on line 150
#5: call()
Called from /www/example.com/httpdocs/forum/index.php on line 184

GL700Wing

It's a known issue that occurs when the 'Like' button is clicked twice in quick succession (it was first reported in the Thanks for SMF 2.1 mod which is a clone of the 'Likes' system in SMF 2.1).

The fix is to change two database "insert" actions to "ignore" actions in ./Sources/Likes.php as follows:

Find:
    // Insert the like.
    $smcFunc['db_insert']('insert',

Replace With:
    // Insert the like.
    $smcFunc['db_insert']('ignore',


Find:
    if ($this->_type == 'msg')
        $smcFunc['db_insert']('insert',

Replace With:
    if ($this->_type == 'msg')
        $smcFunc['db_insert']('ignore',
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

MobileCS

If I make this change, will this mess up the 2.1.5 update? (show errors during install)

GL700Wing

#3
Quote from: MobileCS on November 25, 2023, 09:57:54 PMIf I make this change, will this mess up the 2.1.5 update? (show errors during install)
Only if the SMF 2.1.5 update modifies this file to fix this issue rather than replacing it (and even if the update modifies this file you would be aware of the reason for these specific install errors) ...
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

MobileCS


Aleksi "Lex" Kilpinen

Do we have an issue logged in Github, or is this already fixed for 2.1.5? This does sound like a bug, but I'm unsure if this is actually solved or not.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: