Sha256: 3fd8466679554296576589307ea175f5b2af056a88f4d7d6c86fd3c03245b7b4

Contents?: true

Size: 1.16 KB

Versions: 45

Compression:

Stored size: 1.16 KB

Contents

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

class WatchersToFollowing < Card::Migration::Core
  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

        next unless watched = card.left
        card.item_names.each do |user_name|
          follower_hash[user_name] << watched.name
        end
      end

      follower_hash.each do |user, items|
        next unless (card = Card.fetch(user)) && card.account
        following = card.fetch trait: "following",  new: { type_code: :pointer }
        items.each { |item| following.add_item item }
        following.save!
      end
    end

    if watchers = Card[:watchers]
      watchers.update_attributes codename: nil
      watchers.delete!
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
card-1.96.7 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.6 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.5 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.4 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.96.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.95.3 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.95.2 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.95.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.95.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.94.1 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.94.0 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.13 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.12 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.11 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.10 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.9 db/migrate_core_cards/20141204061304_watchers_to_following.rb
card-1.93.8 db/migrate_core_cards/20141204061304_watchers_to_following.rb