Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
657 views
in Q2A Core by
edited by

When I click "Refill event streams" on Admin > Stats, it works for a few questions then just says "undefined". I turned on error logging and didn't see anything when I run it.

I checked the AJAX requests in Chrome. Here are the last two responses, the first one working fine and the second one causing the error.

QA_AJAX_RESPONSE
1
dorefillevents_refill,15499,213,45
Refilled for 45 of 15,499 questions...

QA_AJAX_RESPONSE
0
A database error occurred.

Also just to add, after this happened I tried again with maintenance mode running, just in case it was due to a user adding a post. Still had the problem.

Q2A version: 1.5.2
by
There should be a corresponding error in your server's error_log file?
by
edited by
OK I assumed it would be the PHP error log, but there is this in the Apache error log:

PHP Question2Answer MySQL query error 1452: Cannot add or update a child row: a foreign key constraint fails (`pokemondb`.`qa_userevents`, CONSTRAINT `qa_userevents_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `qa_users` (`userid`) ON DELETE CASCADE) - Query: INSERT INTO qa_userevents (userid, entitytype, entityid, questionid, lastpostid, updatetype, lastuserid, updated) VALUES ('87', '-', 0, 249, 2960, NULL, '229', FROM_UNIXTIME(1278214178)), referer: mysite/pokebase/admin/stats

BTW I ran the script on my "meta" site with no problems. Is this another "legacy" problem, from the Q2A database structure changing over the versions?
by
From the error you posted, it seems like this is happening because an event is being created for a user (userid 87) based on some prior activity of that user referenced in the database, but the user has been deleted. Can you please check if there is a row in qa_posts with userid set to 87 and confirm that there is no row in qa_users with that userid? Perhaps you deleted the user manually some time ago, before Q2A offered a user delete facility? If so the solution is to set the userid or lastuserid of any row in qa_posts to NULL, if it contains 87.

1 Answer

+3 votes
by
selected by
 
Best answer
Followed gidgreen's advice in the comment. I don't remember manually deleting any users but user #87 was missing and had a userid in the qa_posts table. Setting that to NULL allowed the event streams to continue OK.

I double checked all the other deleted users as well.
...