Sha256: 319fbcb56d201c12677de751f4cc198cd3b7fe8a4e8fd2e842891e0373ee1d54

Contents?: true

Size: 1.61 KB

Versions: 30

Compression:

Stored size: 1.61 KB

Contents

# BareMigration doesn't handle inheritance yet.  Therefore, we need
# to mimic it manually using conditions on find().  Since this script
# doesn't need to set type or id, there's no need to move either of
# the protected fields out of the way like we do in #20-23.

# BareMigration ALSO doesn't handle associations... yet.
# For now, that means your keywords won't be automatically converted
# to tags.  That might not be a bad thing...


class Bare24Article < ActiveRecord::Base
  include BareMigration
  include TypoGuid

  set_table_name :contents
  has_and_belongs_to_many :tags,
      :class_name => 'Bare24Tag', :foreign_key => 'article_id',
      :join_table => 'articles_tags', :association_foreign_key => 'tag_id'

  def keywords_to_tags
    Bare24Article.transaction do
      tags.clear
      keywords.to_s.split.uniq.each do |tagword|
        tags << Bare24Tag.get(tagword)
      end
    end
  end
end

class Bare24Tag < ActiveRecord::Base
  include BareMigration
  has_and_belongs_to_many :articles,
      :class_name => 'Bare24Article', :foreign_key => 'tag_id',
      :join_table => 'articles_tags', :association_foreign_key => 'articles_id'
end

class CleanupContents < ActiveRecord::Migration
  def self.up
    STDERR.puts "Updating all articles"
    # This is needed when migrating from 2.5.x, because we skip GUID
    # generation and tagging during earlier migrations.
    Bare24Article.transaction do
      Bare24Article.find(:all, :conditions => "type = 'Article'").each do |a|
        a.create_guid
#       a.keywords_to_tags      (not needed?)
        a.save!
      end
    end
  end

  def self.down
    # nothing
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
typo-5.5 db/migrate/024_cleanup_contents.rb
typo-5.4.4 db/migrate/024_cleanup_contents.rb
typo-5.4.3 db/migrate/024_cleanup_contents.rb
typo-5.4.2 db/migrate/024_cleanup_contents.rb
typo-5.4.1 db/migrate/024_cleanup_contents.rb
typo-5.4 db/migrate/024_cleanup_contents.rb
typo-3.99.0 db/migrate/024_cleanup_contents.rb
typo-3.99.2 db/migrate/024_cleanup_contents.rb
typo-3.99.3 db/migrate/024_cleanup_contents.rb
typo-3.99.1 db/migrate/024_cleanup_contents.rb
typo-3.99.4 db/migrate/024_cleanup_contents.rb
typo-4.0.2 db/migrate/024_cleanup_contents.rb
typo-4.0.0 db/migrate/024_cleanup_contents.rb
typo-4.0.1 db/migrate/024_cleanup_contents.rb
typo-4.1.1 db/migrate/024_cleanup_contents.rb
typo-4.0.3 db/migrate/024_cleanup_contents.rb
typo-4.1 db/migrate/024_cleanup_contents.rb
typo-5.0.1 db/migrate/024_cleanup_contents.rb
typo-5.0.2 db/migrate/024_cleanup_contents.rb
typo-5.0.3.98.1 db/migrate/024_cleanup_contents.rb