Last active
October 13, 2017 08:51
-
-
Save yogendra689/a2b5708a5c00cb747b03c6c18c7f4bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
namespace :ecl do | |
desc 'Update csv source types and sources for delimiter option' | |
task update_csv_source_types_and_sources: :environment do | |
csv_source_types = SourceType.all.select{|st| st.required_keys.include?('csv_file_url') } | |
csv_source_types.each do |cst| | |
existing_required_keys = cst.required_keys | |
existing_required_keys << 'delimiter' | |
cst.required_keys = existing_required_keys.compact.uniq | |
cst.save! | |
cst.sources.each do |cst_source| | |
cst_source.source_config['delimiter'] = ',' | |
cst_source.save! | |
end | |
end | |
end | |
end | |
namespace :ecl do | |
desc 'Update default sources' | |
task update_lynda_source_type: :environment do | |
lynda_source_type = SourceType.find_by(name: 'lynda') | |
lynda_source_type.required_keys = ["api_key", "secret_key", "domain"] | |
lynda_source_type.save! | |
lynda_source_type.sources.each do |lynda_source| | |
next if lynda_source.id == '68c2d101-21ca-4738-a289-61b33ad3e412' | |
lynda_source.source_config['domain'] ||= "edcast.com" | |
lynda_source.save! | |
end | |
# hpe source | |
source = Source.find("68c2d101-21ca-4738-a289-61b33ad3e412") | |
source.source_config['domain'] ||= "hpe.com" | |
source.save! | |
source.content_items.each do |content_item| | |
uri = URI(content_item.url) | |
params = URI.decode_www_form("") << ['org', 'hpe.com'] | |
uri.query = URI.encode_www_form(params) | |
modified_url = uri.to_s | |
content_item.url = modified_url | |
content_item.external_id = modified_url | |
if content_item.resource_metadata.present? | |
content_item.resource_metadata['url'] = modified_url | |
end | |
content_item.save! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment