News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Converting poll options

Started by cdesseno, January 20, 2012, 10:47:30 AM

Previous topic - Next topic

cdesseno

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.
hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

Oldiesmann

What happens to the poll options after you make that change? Are they just not being imported at all?
Michael Eshom
Christian Metal Fans

cdesseno

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.

hxxp:imageshack.us/photo/my-images/3/screenshotat20120120180.png [nonactive]
hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

Oldiesmann

How does vB store vote info for poll options?

We can figure out the issue with the first letter getting cut off later...
Michael Eshom
Christian Metal Fans

cdesseno

Options are stored all in the same field with this format:
Yes|||No|||May be

hxxp:imageshack.us/photo/my-images/850/screenshotat20120121160.png/ [nonactive]
hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

Oldiesmann

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.
Michael Eshom
Christian Metal Fans

cdesseno

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?
hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

cdesseno

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],
hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

Oldiesmann

Michael Eshom
Christian Metal Fans

cdesseno

hxxp:cdesseno.com.ar [nonactive] - hxxp:forogamers.com.ar [nonactive]

Oldiesmann

Ok. Thanks for the info. I'll let the developers know so they can get the converter updated :)
Michael Eshom
Christian Metal Fans

Advertisement: