Which encoding or How polls option IDS are generated?

(Veer) #1

I am trying to insert polls from pgsql database touch. However i successfully Inserted polls with Manual ids like Option1ID:“POSTID+001” Option2ID:"POSTID+002"
Polls Markdown not generating data in the posts_custom_fields on rebake. I am trying to import data in this table directly creating manually.
The data generated by plugin look like this.


Here is how manually i achived it
Insert this ijn Posts.Row

<div class="poll" data-poll-status="open" data-poll-name="12345" data-poll-type="regular">
<div class="poll-container"><ul>
<li data-poll-option-id="1001">here</li>
<li data-poll-option-id="1002">there</li>
<li data-poll-option-id="1003">nowhere</li>
<div class="poll-info"><p><span class="info-number">0</span><span class="info-text">voters</span></p></div>
<div class="poll-buttons"><a title="Display the poll results">Show results</a></div>

Inserted This in posts_custom_fields table with correct post id and content name “polls” .
{"12345 ":{"options":[{"id":"1001","html":"here","votes":0},{"id":"1002","html":"there","votes":0},{"id":"1003","html":"nowhere","votes":0}],"voters":0,"status":"open","name":"1234","type":"regular"}}

Inserted This in posts_custom_fields table with correct post id and content name “polls-votes” .

I updated and rebaked 0.3 million posts, Polls are working now, but for more naturality i want to know how these ids are generated in polls plugin.

Polls inserted manually into database don't work right
(Gerhard Schlager) #2

The poll-option-id is the md5 hash of the options content (which is a JavaScript array) as JSON string.

So, in your case it would be md5(JSON.stringify(['here'])) which is equal to md5('["here"]')

But, it starts to get a lot more complex if your options contain Markdown. For example the option here *or* there looks like this as JSON: ["here ",["em","or"]," there"]

So, I guess using different option IDs like you did is the best way to solve this.

(Veer) #3

As raw rebaked generate correct polls now. If i use custom ids, in future.
Will plugin or discourse updates effect me if i use custom ids ?