Class: Jobs::MigrateFeaturedLinks
- Defined in:
- app/jobs/onceoff/migrate_featured_links.rb
Instance Method Summary collapse
Methods inherited from Onceoff
enqueue_all, #execute, inherited, name_for, onceoff_job_klasses, #running_key_name
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, #execute, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Instance Method Details
#execute_onceoff(args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/jobs/onceoff/migrate_featured_links.rb', line 5 def execute_onceoff(args) TopicCustomField .where(name: "featured_link") .find_each do |tcf| Topic.where(id: tcf.topic_id).update_all(featured_link: tcf.value) if tcf.value.present? end # Plugin behaviour: only categories explicitly allowed to have featured links can have them. # All others implicitly DO NOT allow them. # If no categories were explicitly allowed to have them, then all implicitly DID allow them. allowed = CategoryCustomField .where(name: "topic_featured_link_allowed") .where(value: "true") .pluck(:category_id) if !allowed.empty? # all others are not allowed Category.where.not(id: allowed).update_all(topic_featured_link_allowed: false) else not_allowed = CategoryCustomField .where(name: "topic_featured_link_allowed") .where.not(value: "true") .pluck(:category_id) Category.where(id: not_allowed).update_all(topic_featured_link_allowed: false) end end |