Permalink
Browse files

Merge pull request #898 from jimjimovich/master

Fixes GH-896
  • Loading branch information...
2 parents 0a4b9ad + 7db285a commit 993430340b00d5e0a0dbbb8ecda39d98cd291304 @ugisozols ugisozols committed Aug 22, 2011
@@ -1,8 +1,14 @@
class RemoveCachedSlugFromPages < ActiveRecord::Migration
def self.up
if ::Refinery::Page.column_names.map(&:to_s).include?('cached_slug')
- remove_column ::Refinery::Page.table_name, :cached_slug
+ say_with_time("Removing cached_slug column from ::Refinery::Page table") do
+ remove_column ::Refinery::Page.table_name, :cached_slug
+ end
+ else
+ say "Nothing done, no cached_slug field found in ::Refinery::Page table"
end
+
+ ::Refinery::Page.reset_column_information
end
def self.down
@@ -3,11 +3,15 @@ def self.up
::Refinery::Page.translated_attribute_names.map(&:to_sym).each do |column_name|
remove_column ::Refinery::Page.table_name, column_name if ::Refinery::Page.column_names.map(&:to_sym).include?(column_name)
end
+
+ ::Refinery::Page.reset_column_information
end
def self.down
::Refinery::Page.translated_attribute_names.map(&:to_sym).each do |column_name|
add_column ::Refinery::Page.table_name, column_name, Page::Translation.columns.detect{|c| c.name.to_sym == column_name}.type
end
+
+ ::Refinery::Page.reset_column_information
end
end
@@ -0,0 +1,86 @@
+class CreateSeoMeta < ActiveRecord::Migration
+
+ def self.up
+ create_table :seo_meta do |t|
+ t.integer :seo_meta_id
+ t.string :seo_meta_type
+
+ t.string :browser_title
+ t.string :meta_keywords
+ t.text :meta_description
+
+ t.timestamps
+ end
+
+ add_index :seo_meta, :id
+ add_index :seo_meta, [:seo_meta_id, :seo_meta_type]
+
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes)
+
+ # Remove columns
+ ::SeoMeta.attributes.keys.each do |field|
+ if ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field)
+ remove_column ::Refinery::Page.translation_class.table_name, field
+ end
+ end
+
+ # Reset column information because otherwise the old columns will still exist.
+ ::Refinery::Page.translation_class.reset_column_information
+
+ # Re-attach seo_meta
+ ::Refinery::Page.translation_class.send :is_seo_meta
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Refinery::Page.translation_class.find(translation['id']).update_attributes(
+ ::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }
+ )
+ end
+
+ # Reset column information again because otherwise the old columns will still exist.
+ ::Refinery::Page.reset_column_information
+ end
+
+ def self.down
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes)
+
+ # Add columns back to your model
+ ::Refinery::SeoMeta.attributes.each do |field, field_type|
+ unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field)
+ add_column ::Refinery::Page.translation_class.table_name, field, field_type
+ end
+ end
+
+ # Reset column information because otherwise the new columns won't exist yet.
+ ::Refinery::Page.translation_class.reset_column_information
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Refinery::Page.translation_class.update_all(
+ ::Refinery::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }, :id => translation['id']
+ )
+ end
+
+ ::Refinery::SeoMeta.attributes.keys.each do |k|
+ ::Refinery::Page.translation_class.module_eval %{
+ def #{k}
+ end
+
+ def #{k}=(*args)
+ end
+ }
+ end
+
+ # Reset column information again because otherwise the old columns will still exist.
+ ::Refinery::Page.reset_column_information
+
+ drop_table :seo_meta
+ end
+
+end
@@ -0,0 +1,11 @@
+class CreateAddTemplateColumns < ActiveRecord::Migration
+ def self.up
+ add_column ::Refinery::Page.table_name, :view_template, :string
+ add_column ::Refinery::Page.table_name, :layout_template, :string
+ end
+
+ def self.down
+ remove_column ::Refinery::Page.table_name, :layout_template
+ remove_column ::Refinery::Page.table_name, :view_template
+ end
+end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.version = %q{2.0.0}
s.summary = %q{Pages engine for Refinery CMS}
s.description = %q{The default content engine of Refinery CMS. This engine handles the administration and display of user-editable pages.}
- s.date = %q{2011-08-18}
+ s.date = %q{2011-08-22}
s.email = %q{info@refinerycms.com}
s.homepage = %q{http://refinerycms.com}
s.rubyforge_project = %q{refinerycms}
@@ -100,8 +100,8 @@ Gem::Specification.new do |s|
'db/migrate/20101217113425_translate_page_plugin.rb',
'db/migrate/20110307025652_translate_custom_title_on_pages.rb',
'db/migrate/20110314213540_remove_translated_fields_from_pages.rb',
- 'db/migrate/20110329080451_create_seo_meta.rb',
- 'db/migrate/20110606151235_create_add_template_columns.rb',
+ 'db/migrate/20110329222114_create_seo_meta.rb',
+ 'db/migrate/20110714071142_create_add_template_columns.rb',
'db/migrate/20110810070753_add_custom_slug_to_refinery_page_translations.rb',
'db/migrate/20110812055013_rename_custom_title_to_menu_title_in_refinery_pages.rb',
'db/seeds',
@@ -0,0 +1,22 @@
+class RemoveDuplicateUserImageSizesSetting < ActiveRecord::Migration
+ def self.up
+ if (settings = ::Refinery::Setting.where(:name => :user_image_sizes)).count > 1
+ default_value = { :small => '110x110>', :medium => '225x255>', :large => '450x450>' }
+
+ if (non_default_setting = settings.detect { |setting| setting[:value] != default_value })
+ settings.detect { |setting| setting[:value] == default_value }.destroy
+ non_default_setting[:destroyable] = false
+ non_default_setting.save
+ else
+ settings.detect { |setting| setting[:destroyable] == true }.destroy
+ end
+ say "Removed duplicate user image sizes settings"
+ else
+ say "Nothing done, no duplicate settings found"
+ end
+ end
+
+ def self.down
+ # there is no step down ...
+ end
+end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.version = %q{2.0.0}
s.summary = %q{Settings engine for Refinery CMS}
s.description = %q{The default settings engine that is required by Refinery CMS core. Adds programmer creatable, user editable settings for each engine.}
- s.date = %q{2011-08-18}
+ s.date = %q{2011-08-22}
s.email = %q{info@refinerycms.com}
s.homepage = %q{http://refinerycms.com}
s.rubyforge_project = %q{refinerycms}
@@ -74,6 +74,7 @@ Gem::Specification.new do |s|
'db/migrate',
'db/migrate/20100913234710_create_refinerycms_settings_schema.rb',
'db/migrate/20100926142529_add_value_type_to_refinery_settings.rb',
+ 'db/migrate/20110117053357_remove_duplicate_user_image_sizes_setting.rb',
'lib',
'lib/gemspec.rb',
'lib/generators',

0 comments on commit 9934303

Please sign in to comment.