Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with guest posts & external database integration #244

Closed
toby78 opened this issue May 24, 2015 · 3 comments
Closed

error with guest posts & external database integration #244

toby78 opened this issue May 24, 2015 · 3 comments

Comments

@toby78
Copy link

toby78 commented May 24, 2015

The following happens with you are using an external user database, allow guest questions and ask a question with the same name as an existing users:

[Sun May 24 20:18:09 2015] [error] [client 149.126.78.65] PHP Question2Answer MySQL query error 1452: Cannot add or update a child row: a foreign key constraint fails (qanda.qa_posts, CONSTRAINT qa_posts_ibfk_1 FOREIGN KEY (userid) REFERENCES qa_users (userid) ON DELETE SET NULL) - Query: INSERT INTO qa_posts (categoryid, type, parentid, userid, cookieid, createip, title, content, format, tags, notify, name, created) VALUES (8, 'Q', NULL, '508815', NULL, INET_ATON('\0\0\0\0\0\0\0\0\0\0\0\0]\x86\xf3U'), 'This ijust a qeustion from real me', 'what happens if someone else asks in my name?', '', 'question', '@', NULL, NOW()),

@pupi1985
Copy link
Contributor

When using external users, you can't violate a constraint that is only created when using internal users... unless you've created the tables using internal users and then switched to external. If you could start from scratch that would be probably the best way to go. If it is already too late you can take a look at this function to see what are the operations you'll need to undo.

@toby78
Copy link
Author

toby78 commented May 25, 2015

I think for external users on donut theme, the following is required in qa-donut-utils.php

         if (!defined('donut_get_user_data')) {
function donut_get_user_data($handle){
    $userid = qa_get_logged_in_userid();
    $user = array();
                  $u_rank = qa_db_select_with_pending(qa_db_user_rank_selectspec($userid,true));
                  $u_points = qa_db_select_with_pending(qa_db_user_points_selectspec($userid,true));

        $userinfo = array();
        $user_info = get_userdata( $userid );
        $userinfo['userid'] = $userid;
        $userinfo['handle'] = $handle;
        $userinfo['email'] = $user_info->user_email;

        $user[0] = $userinfo;
        $user[1]['rank'] = $u_rank;
        $user[2] = $u_points;
        $user = ($user[0]+ $user[1]+ $user[2]);

    $user['account'] = qa_db_select_with_pending( qa_db_user_account_selectspec($userid, true) );
    $user['rank'] = qa_db_select_with_pending( qa_db_user_rank_selectspec($userid) );
    $user['points'] = qa_db_select_with_pending( qa_db_user_points_selectspec($userid) );

    $user['followers'] = qa_db_read_one_value( qa_db_query_sub('SELECT count(*) FROM ^userfavorites WHERE ^userfavorites.entityid = # and ^userfavorites.entitytype = "U" ', $userid), true );


    $user['following'] = qa_db_read_one_value( qa_db_query_sub('SELECT count(*) FROM ^userfavorites WHERE ^userfavorites.userid = # and ^userfavorites.entitytype = "U" ', $userid), true );

@svivian
Copy link
Collaborator

svivian commented Aug 1, 2015

Sounds like this is a problem with an external theme, so you should suggest your fix to the author of that theme.

@svivian svivian closed this as completed Aug 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants