Sha256: 40294acc8c7aae18ca9924446d904d605647e81fc95f29537b0092a8de1fa4b7

Contents?: true

Size: 1.72 KB

Versions: 33

Compression:

Stored size: 1.72 KB

Contents

class RenameTemplates < ActiveRecord::Migration
  def self.up
    mode_change = [ ['search', '*search'],
      ['admin_layout', '*adminLayout'],
      ['index', '*index'],
      ['not_found', '*notFound'],
      ['popup_layout', '*popupLayout'],
      ['login', '*login']
    ]
    mode_translation = Hash[*mode_change.flatten]
    mode_change.each do |old_name, new_name|
      execute "UPDATE #{TemplateContent.table_name} SET mode = '#{new_name}' WHERE mode = '#{old_name}'"
    end
    Template.find(:all).each do |t|
      content = TemplateContent.find(:first, :conditions => "node_id = #{t[:id]}")
      if content.klass
        # update name
        content.format ||= 'html'
        format = content.format == 'html' ? '' : "-#{content.format}"
        mode   = (content.mode || format != '') ? "-#{content.mode}" : ''
        new_name = "#{content.klass}#{mode}#{format}"
        execute "UPDATE #{Node.table_name} SET name = #{quote(new_name)} WHERE id = #{t[:id]}"
      end
      Version.find_all_by_node_id(t[:id]).each do |v|
        text = v.text
        new_text = text.gsub(/template\s*=\s*("|')([^\1]+?)\1/) do
          sep, template_name = $1, $2
          if template_name =~ /\A(\w+)(_(.+)|)(\.(\w+)|)/
            base, mode, format = $1, $3, $5
            format = (format && format != 'html') ? "-#{format}" : ''
            if mode
              mode = mode_translation[mode] || mode
              template_name = "#{base}-#{mode}#{format}"
            else
              template_name = "#{base}#{format}"
            end
          end
          "template='#{template_name}'"
        end
        execute "UPDATE #{Version.table_name} SET text = #{quote(new_text)} WHERE id = #{v[:id]}"
      end
    end
  end

  def self.down
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
zena-1.2.8 db/fix/026_rename_templates.rb
zena-1.2.7 db/fix/026_rename_templates.rb
zena-1.2.6 db/fix/026_rename_templates.rb
zena-1.2.5 db/fix/026_rename_templates.rb
zena-1.2.4 db/fix/026_rename_templates.rb
zena-1.2.3 db/fix/026_rename_templates.rb
zena-1.2.2 db/fix/026_rename_templates.rb
zena-1.2.1 db/fix/026_rename_templates.rb
zena-1.2.0 db/fix/026_rename_templates.rb
zena-1.1.3 db/fix/026_rename_templates.rb
zena-1.1.2 db/fix/026_rename_templates.rb
zena-1.1.1 db/fix/026_rename_templates.rb
zena-1.1.0 db/fix/026_rename_templates.rb
zena-1.0.0 db/fix/026_rename_templates.rb
zena-1.0.0.rc3 db/fix/026_rename_templates.rb
zena-1.0.0.rc2 db/fix/026_rename_templates.rb
zena-1.0.0.rc1 db/fix/026_rename_templates.rb
zena-0.16.9 db/migrate/026_rename_templates.rb
zena-1.0.0.beta3 db/migrate/026_rename_templates.rb
zena-0.16.8 db/migrate/026_rename_templates.rb