mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add post status administration (#105)
This commit is contained in:
committed by
GitHub
parent
c5148147e3
commit
5256ea911a
22
app/workflows/EnsureCoherentOrderingWorkflow.rb
Normal file
22
app/workflows/EnsureCoherentOrderingWorkflow.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class EnsureCoherentOrderingWorkflow
|
||||
attr_accessor :entity_classname, :column_name
|
||||
|
||||
def initialize(entity_classname: "", column_name: "")
|
||||
@entity_classname = entity_classname
|
||||
@column_name = column_name
|
||||
end
|
||||
|
||||
def run
|
||||
column_name_sanitized = ActiveRecord::Base.connection.quote_column_name(column_name)
|
||||
|
||||
entity_records = entity_classname.order("#{column_name_sanitized} ASC")
|
||||
|
||||
entity_records.each_with_index do |entity_record, order|
|
||||
entity_record[column_name] = order
|
||||
end
|
||||
|
||||
entity_classname.transaction do
|
||||
entity_records.each(&:save!)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user