# استطلاع الهجرة - مشكلة ونصيحة

**URL:** <https://meta.discourse.org/t/poll-migration-problem-and-advice/89392>\
**Category:** Development\
**Created:** [7 يونيو 2018، 8:04م UTC](https://meta.discourse.org/t/poll-migration-problem-and-advice/89392 "2018-06-07T20:04:13Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)\
**Post date:** [8 يونيو 2018، 11:45م UTC](https://meta.discourse.org/t/poll-migration-problem-and-advice/89392/6 "2018-06-08T23:45:09Z")

</div>

OK, I’ve now got this working by implementing a few workarounds but it’s not clear why some things didn’t just work.

Previously, I was running the poll creation routine against already migrated posts which meant editing them and occasionally tripping the user `trust_level` validation.

I decided to move the poll creation routine into my post migration code so that I could use the `PostCreator` class which I knew runs as a system user.

I did this, created a valid `[poll]...[/poll]` structure and added it at the end of the `.raw` post content. Discourse picked up the poll, cooked the content so that it rendered correctly on the screen, and I thought I’d solved it.

However, despite rendering on screen like a poll, it would not accept votes. Looking in the database there was no corresponding `[polls]` hash structure in the `PostCustomFields` table. So there would be no way to record my votes.

If I then used the Discourse UI to make any minor change to the raw content that would force the Polls plugin to fire the post changed code, as soon as the edit was complete the poll UI allowed me to vote and the `[polls]` structure appeared in the `PostCustomFields` table.

I decided that I would implement a `:post_create_action` call back on the newly created post and edit it as an elevated user. I simply elevated the user to `trust_level` 4, added a markdown horizontal rule at the foot of the raw post content, saved it, reset the `trust_level` and it’s worked. The poll now renders fully, creates the `[polls]` structure in `PostCustomField` and accepts my migrated votes.

Why the full poll creation routine doesn’t fire after `PostCreator` finishes, but instead needs the post to be edited, I don’t know.

Thanks again for you support. 👍

---

_[View the full topic](https://meta.discourse.org/t/poll-migration-problem-and-advice/89392)._
