app/models/run.rb
# logically delete records of states of self's run in span time range
# return set of ids of states deleted
logically delete records of states of self's run in span time range
return set of ids of states deleted
logically delete records of states of self ' s run in span time range return set of ids of states deleted
def delete_run!(span = (@@show_time..Future), time = @@action_time)
    @@current_account && @@current_account.role != "guest" or fail
    span.is_a?(Range) or span = (span..Future)
    span.begin.is_a?(DateTime) || span.end.is_a?(DateTime) or fail "span '#{span}' must be Range of DateTime"
    delete_related_state_ids = []
    involved_states = history(:show_time => time.ago(QTIME), :assert_time => span)
    involved_states.blank? and return []
    delete_related_state_ids = involved_states.map(&:id)
    first_state, last_state = involved_states.first, involved_states.last
    delete_attrs = {Deleted_at => time.ago(QTIME).to_s(:db), Deleted_by => @@current_user.run_id}      
    transaction do
      involved_states.each do |state|
        state.attributes = state.attributes.merge(delete_attrs)
        state.save(false)
      end
      if first_state.send(Since).to_s(:db) < span.begin.to_s(:db) && span.begin.to_s(:db) < first_state.send(Till).to_s(:db)
        attrs = first_state.attributes.update Till=> span.begin.ago(QTIME)
        attrs.delete(Created_at)
        attrs.delete(Deleted_at)
        attrs.delete(Deleted_by)
        state = add_state! attrs, false
        delete_related_state_ids << state.id
      end
      if last_state.send(Since).to_s(:db)< span.end.to_s(:db) && span.end.to_s(:db)< last_state.send(Till).to_s(:db)
        attrs = last_state.attributes.update Since => span.end.in(QTIME)
        attrs.delete(Created_at)
        attrs.delete(Deleted_at)
        attrs.delete(Deleted_by)
        state = add_state! attrs, false
        delete_related_state_ids << state.id
      end
    end
    delete_related_state_ids
  end
def delete_run! ( span = ( @@show_time .. Future ) , time = @@action_time ) @@current_account && @@current_account . role != "guest" or fail span . is_a? ( Range ) or span = ( span .. Future ) span . begin . is_a? ( DateTime ) || span . end . is_a? ( DateTime ) or fail "span '#{span}' must be Range of DateTime" delete_related_state_ids = [ ] involved_states = history ( :show_time => time . ago ( QTIME ) , :assert_time => span ) involved_states . blank? and return [ ] delete_related_state_ids = involved_states . map ( & :id ) first_state , last_state = involved_states . first , involved_states . last delete_attrs = { Deleted_at => time . ago ( QTIME ) . to_s ( :db ) , Deleted_by => @@current_user . run_id } transaction do involved_states . each do | state | state . attributes = state . attributes . merge ( delete_attrs ) state . save ( false ) end if first_state . send ( Since ) . to_s ( :db ) < span . begin . to_s ( :db ) && span . begin . to_s ( :db ) < first_state . send ( Till ) . to_s ( :db ) attrs = first_state . attributes . update Till => span . begin . ago ( QTIME ) attrs . delete ( Created_at ) attrs . delete ( Deleted_at ) attrs . delete ( Deleted_by ) state = add_state! attrs , false delete_related_state_ids << state . id end if last_state . send ( Since ) . to_s ( :db ) < span . end . to_s ( :db ) && span . end . to_s ( :db ) < last_state . send ( Till ) . to_s ( :db ) attrs = last_state . attributes . update Since => span . end . in ( QTIME ) attrs . delete ( Created_at ) attrs . delete ( Deleted_at ) attrs . delete ( Deleted_by ) state = add_state! attrs , false delete_related_state_ids << state . id end end delete_related_state_ids end
logically delete records of states of self's run in span time range
return set of ids of states deleted
logically delete records of states of self ' s run in span time range return set of ids of states deleted
# reject against anonymous user # mark logical deletion to states even in the case that invalid state is originally saved with some reason. #  do not apply Rails "update" method since it veriifies when save. # recreate first and last edge states of the run if overlapped in span
span
<not_specific>
time
<not_specific>