Sha256: 307106801ba4fd206e24bec391b231d361f1f74126035b4c7d5f5edcc4738e56

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

class FixesBuggyArticlesAndNotes < ActiveRecord::Migration[4.2]
  class Content < ActiveRecord::Base
  end

  class Article < Content
    def set_permalink
      return if state == "draft" || permalink.present?

      self.permalink = title.to_permalink
    end
  end

  class Note < Content
    def set_permalink
      self.permalink = "#{id}-#{body.to_permalink[0..79]}" if permalink.blank?
      save
    end

    def create_guid
      return true if guid.present?

      self.guid = UUIDTools::UUID.random_create.to_s
    end
  end

  class Page < Content
    def set_permalink
      self.name = title.to_permalink if name.blank?
    end
  end

  def self.up
    say "Fixing contents permalinks, this may take some time"

    contents = Content.where("permalink is ? or permalink = ?", nil, "")
    contents.each do |c|
      c.set_permalink
      c.save
    end

    say "Fixes empty notes GUID"
    notes = Note.where("guid is ? or guid = ?", nil, "")
    notes.each do |n|
      n.create_guid
      n.save
    end
  end

  def self.down
    say "Nothing to do here"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
publify_core-10.0.2 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-10.0.1 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-10.0.0 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.10 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.9 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.8 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.7 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.6 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.5 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.4 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.3 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.2 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.1 db/migrate/114_fixes_buggy_articles_and_notes.rb
publify_core-9.2.0 db/migrate/114_fixes_buggy_articles_and_notes.rb