Sha256: f2d33fd1ff510dc2306f05836c61b42d072e4dc4271ba249551af78862657166

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 KB

Contents

# -*- encoding : utf-8 -*-

class WatchersToFollowing < Card::CoreMigration
  def up
    
    follower_hash = Hash.new { |h, v| h[v] = [] } 

    #NOTE: this migration must find cards in the trash, because the original (1.14.0) migration attempt
    # did not successfully migration to the +*following card but did successfully delete +*watchers cards.
    # Therefore cards migrated using 1.14.0 or 1.14.1 will not have the correct migrations
    
    if watcher_card = Card.find_by_key('*watcher')
      Card.find_by_sql("select * from cards where right_id = #{watcher_card.id}").each do |card|
        card.include_set_modules

        if watched = card.left
          card.item_names.each do |user_name|
            follower_hash[user_name] << watched.name
          end
        end
      end
    
      follower_hash.each do |user, items|
        if card=Card.fetch(user) and card.account
          following = card.fetch :trait=>'following',  :new=>{:type_code=>:pointer}
          items.each { |item| following.add_item item }
          following.save!
        end
      end    
    end
    
    if watchers = Card[:watchers]
      watchers.update_attributes :codename=>nil
      watchers.delete!
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
card-1.16.6 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.5 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.4 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.16.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.7 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.6 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.5 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.4 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.pre2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.15.pre db/migrate_core_cards/20141204061304_watchers_to_following.rb