FEATURE: new setting to create a linked topic on autoclosing mega topics (PR #11001)

This commit adds a site setting auto_close_topics_create_linked_topic which when enabled works in conjunction with auto_close_topics_post_count setting and creates a new linked topic for the topic just closed.

The auto-created new topic contains a link for all the previous topics and the topic titles are appended with (Part {n}).

The setting is disabled by default.


Example of a topic created automatically via auto_close_topics_create_linked_topic setting:

Screenshot from 2020-10-22 23-00-13

GitHub

The title of this pull request changed from “FEATURE: new setting to create a linked topic on autoclosing mega topics” to "[WIP] FEATURE: new setting to create a linked topic on autoclosing mega topics

The title of this pull request changed from “[WIP] FEATURE: new setting to create a linked topic on autoclosing mega topics” to "FEATURE: new setting to create a linked topic on autoclosing mega topics

Question: Why in 5 seconds?

We should use a transaction for this stuff. We wouldn’t want a title updated if something fails below.

Probably most of this job should be in a big transaction.

We should run this by @gschlager who knows best about translation keys. What do you think of this approach of building a list and sending it over to one key? (Also, it’s probably worth reading the above part that creates the topic titles.)

I just wanted to be on the safe side. In particular, my thinking here was that the PostCreator process is completed before updating the topic title.

Any drawback here if we enqueue after 5 seconds?

Noted, will do.

        parent_title = I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: parent_title, count: 1)

Hmm, would this work as well given the other changes I suggest?

        raw_title = parent_title.delete_suffix(I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: "", count: linked_topic_record.sequence))
      new_topic_title = I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: raw_title, count: sequence)

Seems fine as it just concatenates multiple Markdown strings.

    topic_title_with_sequence:
      one: "%{topic_title} (Part %{count})"
      other: "%{topic_title} (Part %{count})"

Let’s use a different translation for this so that we can avoid adding the parentheses in code. And, to be on the safe side, let’s make it a pluralized string (see locale file).

Seems like it works!

Thanks for the review @eviltrout & @gschlager. Made the required changes.