Simple Machines Community Forum

SMF Support => Converting to SMF => vBulletin => Topic started by: cdesseno on January 20, 2012, 10:47:30 AM

Title: Converting poll options
Post by: cdesseno on January 20, 2012, 10:47:30 AM
I am having some troubles converting vBulletin 3.8 to SMF 2.0 with 3.7 converter. All is working fine except* from this:
QuoteConverting poll options...Wrong value type sent to the database. Integer expected. (votes).

* Changing
SELECT pollid AS id_poll, options, votes
FROM {$from_prefix}poll;

to
SELECT pollid AS id_poll, options, IFNULL(votes, 0)
FROM {$from_prefix}poll;

I managed to skip that bug, but obviously poll are not being imported ok.
Title: Re: Converting poll options
Post by: Oldiesmann on January 20, 2012, 11:46:35 AM
What happens to the poll options after you make that change? Are they just not being imported at all?
Title: Re: Converting poll options
Post by: cdesseno on January 20, 2012, 04:17:48 PM
As you can see in the image, votes are always zero. Also, another strange thing is that the first letter of label was removed in each row.

http://imageshack.us/photo/my-images/3/screenshotat20120120180.png (http://imageshack.us/photo/my-images/3/screenshotat20120120180.png)
Title: Re: Converting poll options
Post by: Oldiesmann on January 21, 2012, 01:50:00 PM
How does vB store vote info for poll options?

We can figure out the issue with the first letter getting cut off later...
Title: Re: Converting poll options
Post by: cdesseno on January 21, 2012, 02:07:56 PM
Options are stored all in the same field with this format:
Yes|||No|||May be

http://imageshack.us/photo/my-images/850/screenshotat20120121160.png/
Title: Re: Converting poll options
Post by: Oldiesmann on January 21, 2012, 03:55:05 PM
I'm honestly not sure what the problem is with the votes.

This is the code SMF uses to get poll options and votes:

$ignore = true;
$no_add = true;
$keys = array('id_poll', 'id_choice', 'label', 'votes');

$options = explode('|||', $row['options']);
$votes = explode('|||', $row['votes']);

$id_poll = $row['id_poll'];
for ($i = 0, $n = count($options); $i < $n; $i++)
{
$rows[] = array(
'id_poll' => $id_poll,
'id_choice' => ($i + 1),
'label' => substr(addslashes($options[$i]), 1, 255),
'votes' => (is_numeric($votes[$i]) ? $votes[$i] : 0),
);
}


The only problem I see is with the label - that "1" should be a "0" instead.

SMF sets it to 0 automatically if the value isn't numeric, so the IFNULL shouldn't make any difference.
Title: Re: Converting poll options
Post by: cdesseno on January 21, 2012, 04:53:12 PM
You were right with the label issue! (it is strange that nobody had noticed this bug before).
With the votes problem I think it should be solved with this:
SELECT pollid AS id_poll, options, IFNULL( votes, 0 )[b] as votes[/b]
FROM foro_poll


Is there any easy way just to run the poll's section of the converter?
Title: Re: Converting poll options
Post by: cdesseno on January 22, 2012, 06:31:20 PM
Here is the diff with my working version:


< 'label' => substr(addslashes($options[$i]), 1, 255),
< 'votes' => (is_numeric($votes[$i]) ? $votes[$i] : 0),
---
> 'label' => substr(addslashes($options[$i]), 0, 255),
> 'votes' => (int) $votes[$i],
Title: Re: Converting poll options
Post by: Oldiesmann on January 25, 2012, 12:52:25 PM
Did that fix the issue then?
Title: Re: Converting poll options
Post by: cdesseno on January 25, 2012, 01:34:16 PM
Yes!
Title: Re: Converting poll options
Post by: Oldiesmann on January 25, 2012, 01:44:20 PM
Ok. Thanks for the info. I'll let the developers know so they can get the converter updated :)