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
def file_to_array(file) | |
arr = [] | |
if File.exists?(file) | |
f = File.read(file) | |
f.each_line { |line| arr << line.strip unless line == "\n" } | |
end | |
arr | |
end |
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
def array_to_file(arr, file) | |
File.open(file, 'w') { |f| f.write(arr.join("\n")) } unless arr.blank? | |
end |
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
## G5 Content Management System | |
Website.all.select { |web| web.website_template.blank? }.each do |web| | |
WebsiteSeederJob.perform_async(web.owner.id) | |
end |
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
## G5 Content Management System | |
def find_setting_value(target) | |
Setting.where(Setting.arel_table[:value].matches("%#{target}%")) | |
end | |
def find_setting_value_widgets(target) | |
find_setting_value(target).map do |setting| | |
setting.owner | |
end.uniq |
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
## G5 Hub | |
def get_urn(url) | |
url.gsub("https://","").gsub(".herokuapp.com","") | |
end | |
## Find all internal clients | |
Client.where(g5_internal: true).map { |c| get_urn(c.cms_url) } | |
## Find all real clients |
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
class Array | |
def to_file(filepath, sep="\n") | |
File.open(filepath, 'w') { |f| f.write(join(sep)) } unless blank? | |
end | |
def squash | |
blank? ? [] : flatten.compact.uniq | |
end | |
end |
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
def repair_drop_targets(html_id, widgets=[]) | |
bad = Website.all.select do |web| | |
!web.website_template.blank? && ( | |
web.website_template.drop_targets.find_by_html_id(html_id).blank? || | |
web.website_template.drop_targets.find_by_html_id(html_id).widgets.blank?) | |
end | |
bad.each do |web| | |
wt = web.website_template | |
dt = wt.drop_targets.find_by_html_id(html_id) |
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
def find_multi_website_locations | |
Location.all.select { |l| Website.where(owner_id: l.id).count > 1 } | |
end |
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
widgets = Widget.includes(:garden_widget, :settings).by_name('Phone Number').all | |
settings = widgets.map { |w| w.settings.where_name('phone_number').all }.squish.select { |s| s.value.present? && && s.value != "{{location_phone_number}}" } | |
ret = settings.inject("") { |str, s| str << "- #{s.website.name} (#{s.website.owner.urn}) - #{s.website.status}): #{s.value}\n"; str } | |
puts "#{Client.client.name} (#{Client.client.urn}):\n#{ret}\n" unless ret.blank? |
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
dups = Website.all.inject({}) { |h,w| h[w.owner_id] ||= 0; h[w.owner_id] += 1; h }.reject! { |k,v| v <= 1 } | |
bad_webs = Website.where(owner_id: dups.keys).all.sort_by(&:name) | |
bad_files = bad_webs.inject({}) do |h, w| | |
file_name = "#{w.id}-#{w.name.parameterize}" | |
mgr = Saves::WebsiteSavesManager.new("[email protected]", w.owner) | |
file_path = mgr.send(:create_save_file, file_name) | |
s3 = S3Bucket.new(w.owner, {s3_folder: 'websites-saves'}) | |
file = s3.upload(file_path, file_name) | |
h[w.id] = { owner_id: w.owner_id, file: s3.bucket_file_url(file_name) } |
OlderNewer