Sha256: bdf7dd5f78105f13d76fb83063719e3425755e6e9bc41243d2f6d567e955250a

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

namespace :smithy do
  desc "Track down any usage of linking directly to Smithy Assets. Use /smithy/assets/1 instead"
  task :find_direct_asset_links => :environment do
    Smithy::Template.where('content LIKE ? OR content LIKE ?', '%s3.amazonaws.com%', '%/uploads/assets/%').each do |template|
      puts "[WARNING] Direct Link found in the Template: #{template.name}"
      find_and_print_matches(template.content)
    end

    Smithy::Content.where('content LIKE ? OR content LIKE ?', '%s3.amazonaws.com%', '%/uploads/assets/%').each do |content|
      content.page_contents.each do |page_content|
        puts "[WARNING] Direct Link found in the Page: #{page_content.page.title} - #{page_content.page.url}"
        puts "  Content Block(s): #{page_content.label}"
        find_and_print_matches(content.content)
      end
    end
  end

  def find_and_print_matches(content)
    asset_regex = /(?:https?:\/\/.*s3\.amazonaws\.com|\/uploads\/assets)[a-z0-9\/\._-]+/i
    content.scan(asset_regex) do |match|
      puts "  #{match}\n"
      if Smithy::Asset.where("file_name LIKE ?", "%#{File.basename(match)}%").size > 0
        puts "    Possible Match(es):"
        Smithy::Asset.where("file_name LIKE ?", "%#{File.basename(match)}%").map{|a| "/smithy/assets/#{a.id}"}.each do |link|
          puts "    #{link}"
        end
      end
    end
    puts "\n"
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
smithycms-0.5.99.3 lib/tasks/smithy_tasks.rake
smithycms-0.6.7 lib/tasks/smithy_tasks.rake
smithycms-0.6.6 lib/tasks/smithy_tasks.rake
smithycms-0.6.5 lib/tasks/smithy_tasks.rake
smithycms-0.6.4 lib/tasks/smithy_tasks.rake
smithycms-0.6.3 lib/tasks/smithy_tasks.rake
smithycms-0.5.99.2 lib/tasks/smithy_tasks.rake