Queue model tweaks.

- Change the way foreign IDs are generated.
- Allow peremoderation events to set queue fields.
- Hook into log model inserts and restores.