Fix attachment filename and title scrubbing

The structure of the attachments table has changed to use polymorphism
instead of a join table. This updates the SQL statements to match the
new database schema.

This also extracts the edition_ids and document_ids SQL fragments to
improve readability.
Scrub access limited editions of all states

The access limited flag is removed when an article is published, so
this should be more thorough and still leave preview in an acceptable
state.