Sha256: a791c5adb8876ae14e34f800aa7e3934ab05f3b73ad016595fb68c807436a55f

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

# Upgrade to Browsercms v3.4.0
require 'cms/upgrades/v3_4_0'
class Browsercms340 < ActiveRecord::Migration
  include Cms::Upgrades::V3_4_0::SchemaStatements

  def change
    # Prefix the correct namespace where class_names are not prefixed
    %w[HtmlBlock Category CategoryType Portlet FileBlock ImageBlock Tag].each do |content_type|
      update_content_types(content_type)
      update_connectors_table(content_type)
    end

    update_sitemap
    update_files
    standardize_foreign_keys_from_versions_tables_to_original_table
  end


  private

  def namespace_model(name)
    "Cms::#{name}"
  end

  def update_files
    %w[FileBlock ImageBlock].each do |content_type|
      Cms::AbstractFileBlock.update_all("type = '#{prefix(content_type)}'", "type = '#{content_type}'")
    end
  end

  def update_sitemap
    %w[Section Page Link Attachment].each do |addressable|
      Cms::SectionNode.where(:node_type=>addressable).each do |node|
        node.node_type = namespace_model(addressable)
        node.save!
      end
    end
  end

  def update_content_types(name)
    found = Cms::ContentType.named(name).first
    if found
      found.name = namespace_model(name)
      found.save!
    end
  end

  def update_connectors_table(name)
    Cms::Connector.where(:connectable_type => name).each do |connector|
      connector.connectable_type = prefix(name)
      connector.save!
    end
  end

  def standardize_foreign_keys_from_versions_tables_to_original_table
    models = %w[attachment dynamic_view file_block html_block link page ]
    models.each do |model|
      standardize_version_id_column(model)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
browsercms-3.4.2 db/migrate/20111130221145_browsercms340.rb
browsercms-3.4.2.rc1 db/migrate/20111130221145_browsercms340.rb
browsercms-3.4.1 db/migrate/20111130221145_browsercms340.rb
browsercms-3.4.0 db/migrate/20111130221145_browsercms340.rb