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

**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:** 1

<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:** [7 يونيو 2018، 8:04م UTC](https://meta.discourse.org/t/poll-migration-problem-and-advice/89392/1 "2018-06-07T20:04:13Z")

</div>

Hi, my chosen approach to creating polls during a migration is functional but not without issues.

tl;dr - Is there a way that I can call `Post.save` as if I were a system user (to skip validation) - and is this advisable / desirable?

**Detail**  
It seems to me that polls have two stages - setting up the poll and then voting.

**Setting up the poll** has two components

1. placing the `[poll]...[/poll]` tag into the `Post` `raw` / `cooked` fields - usually keyed in by our users
2. recording the details of the options and votes in a `PostCustomField` under the `[polls]` hash structure - usually handled by our polls plugin

**Voting**  
Once these structures are in place, it is then possible to record votes against the poll using the `DiscoursePoll::Poll.vote` method.

The approach I took to handle step 1 of the **Setting up the poll** component was to simply append the `[poll]...[/poll]` text to the `raw` field of the `Post` in question.

Once this is saved and the raw content cooked, the Poll plugin will do its thing and create the hash structure mentioned in step 2 above.

I also had to adjust the `poll_minimum_trust_level_to_create` site setting so that my newly migrated level 0 users were able to create polls.

However, now that I have got this far, the act of re-saving the `Post` so that the [poll]…[/poll] elements are generated is tripping `Post.save` validation problems.

These validation problems were not an issue for the migrator as it seems to run as a system level `Guardian` user.

An example is where my trust level 0 users cannot mention more than two other users in a post. This wasn’t a problem in the forum I’m migrating from and neither was it a problem for the post migrator as it uses `PostCreator` as system user.

I’ve tried to follow the logic of the phpbb3 poll importer to see how it does its stuff, but I’m new to Ruby and only a part-time hacker.

It _looks_ like it re-produces the work of the poll plugin in creating the `[polls]` hash structure in the post custom field which I’m loathed to do.

Ideally, what I’d like to do is re-save the post (with the added `[poll]...[/poll]` text) as a system user so that the validation isn’t fired. Alternatively I’d like to call `Post.save` and skip user level validation.

Is that possible?

Any advice gratefully received.

---

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