Skip to content

Instantly share code, notes, and snippets.

@gschlager
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save gschlager/c6ba58bdd2fa2839aebd to your computer and use it in GitHub Desktop.

Select an option

Save gschlager/c6ba58bdd2fa2839aebd to your computer and use it in GitHub Desktop.
Repair votes that have been migrated from phpBB2 to phpBB3

This UPDATE statement repairs invalid votes that have been migrated from phpBB2 to phpBB3. The invalid votes usually have a poll_option_id with value 127.

You need a backup of your old phpBB2 database (schema phpbb2) and your current phpBB3 database (schema phpbb3) for this to work.

UPDATE phpbb3.phpbb_poll_votes v3
JOIN phpbb2.phpbb_vote_desc vd2 ON (v3.topic_id = vd2.topic_id)
JOIN phpbb2.phpbb_vote_voters vv2 ON (v3.vote_user_id = vv2.vote_user_id AND vd2.vote_id = vv2.vote_id)
JOIN phpbb2.phpbb_vote_results vr2 ON (vd2.vote_id = vr2.vote_id)
SET v3.poll_option_id = vr2.vote_option_id
WHERE NOT EXISTS (
SELECT 1
FROM phpbb3.phpbb_poll_options o3
WHERE o3.topic_id = v3.topic_id AND o3.poll_option_id = v3.poll_option_id
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment