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?
It seems to me that polls have two stages - setting up the poll and then voting.
Setting up the poll has two components
- placing the
[poll]...[/poll]tag into the
cookedfields - usually keyed in by our users
- recording the details of the options and votes in a
[polls]hash structure - usually handled by our polls plugin
Once these structures are in place, it is then possible to record votes against the poll using the
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
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.