Skip to content

Instantly share code, notes, and snippets.

View julesce's full-sized avatar

James Thompson julesce

  • Hampshire, United Kingdom
View GitHub Profile
<% @teams.each do |team| %>
<% team.admin_users.each do |user| %>
<tr>
<td><%= team.name %></td>
<td><%= user.name %></td>
<% (1..5).each do |counter| %>
<td><%= link_to(counter, admin_consultant_report_path(user.consultant_reports.select {|x| x.week.to_i == counter})) %></td>
<% end %>
</tr>
<% end %>
def self.perform(promotion_id)
promotion = Promotion.find(promotion_id)
promotion.mailings_sent.each do |mailing|
migrate_mailing(mailing)
end
promotion.refresh_stats
promotion.store(:stats_migration_end => Time.now)
end
def self.paginate(mailing, filter = :delivered, page = 1, per_page = 30)
page = page.to_i
page = 1 if page < 1
per_page = per_page.to_i
per_page = 30 if per_page < 1
total = mailing.count(filter)
continuation_manager = StatsContinuationManager.new(mailing.promotion, mailing,
{ :page => page,
<span style="display:inline-block;font-size:11px;" class="unsubscribe">
<!--[if gte mso 9]>
<v:roundrect href="[[opt_out]]" style="height:20px;v-text-anchor:middle;width:82px;" arcsize="50%" stroke="f" fillcolor="#c5c5cf">
<w:anchorlock/>
<v:textbox inset="0,0,0,0">
<center><a href="[[opt_out]]" style="height: 20px;font-family:Helvetica Neue, Helvetica, Arial, Verdana, sans-serif;font-size:11px;line-height: 170%;font-weight:normal;mso-text-raise:4px;background-color: #c5c5cf; text-align: left; direction: ltr;" title="Unsubscribe"><span style="color: #404055; background-color: #c5c5cf; font-size: 11px;">Unsubscribe</span></a>
</center>
</v:textbox>
</v:roundrect>
def self.new_count(mailing, stat_type)
case stat_type
when :total
Total.new(mailing, stat_type).count
when :ga
GoogleAnalyticsMailingStat.total_value(mailing)
when :total_viewed
PromotionAttemptEvent.count_by_state(mailing.id, stat_type) + archive_count(mailing, :viewed)
when :tweeted, :facebooked, :plusoned, :pinned, :forwarded, :shared,
:forward_total_viewed, :subscribed
mailings_to_refresh = []
click_thrus_to_delete = []
promotions_to_refresh = []
ClickThru.find_each(:select => 'click_thrus.id, mailing_links.mailing_id',
:joins => "INNER JOIN mailing_links ON click_thrus.mailing_link_id = mailing_links.id",
:conditions => {:promotion_attempt_id => 9223372036854775807}) do |click_thru|
click_thrus_to_delete << click_thru.id
mailings_to_refresh << click_thru.mailing_id unless mailings_to_refresh.include?(click_thru.mailing_id)
#
# There are a couple of drips that have not had their RLinkIndex created, since they are returning false for archived_mailing_links?
# This script attempts to fix this, by ensuring that the index is created, and archived_mailing_links? returns true
#
require 'logger'
Object.const_set(:RIAK_DISABLE_SECONDARY_INDEXES, false)
logger = Logger.new('log/fix_drip_clicks.log')
logger.info "====================== S T A R T ========================"
>> mc = MembershipCampaign.find 54834774412
=> #<MembershipCampaign id: 54834774412, drip_campaign_id: 2686, membership_id: 3530060049, completed: true, created_at: "2012-11-05 11:48:23", updated_at: "2013-04-16 03:34:28">
>> am = mc.audience_member
=> #<AudienceMember id: 3470006376, user_id: 88088, first_name: "Miri", last_name: nil, email: "[email protected]", created_at: "2012-11-05 11:48:23", updated_at: "2012-11-05 11:48:23", city: nil, created_by: "member", confirmed_at: nil, phone: nil, company: nil, title: nil, address: nil, state: nil, zip: nil, country: nil, aux_data: nil, ip: "85.130.200.159", suppressed: false, activation_code: nil, signup_id: 45146, confirmed: 1, rev_email: "", suppression_reason: nil, bounce_code: nil, soft: 0, deleted: 0, audience_import_id: nil>
>> RPromotionAttempt.find_all_keys_by_index(:audience_member_id, am.id)
=> ["267473035302864268", "370746214726985283"]
>> RPromotionAttempt.find_all_keys_by_index(:audience_member_id, am.id)
=> ["267473035302864268", "3707462
def async_save
json_v2_response_only do
json = JSON.parse(params[:promotion])
@promotion = current_user.promotions_find(json["id"])
validator = PromotionModuleValidator.new(@promotion, json)
if validator.valid?
@promotion.update_from_json(json, true)
# Update the mailing for the RSS Promotion when changing the promotion's name
@julesce
julesce / gist:9763295
Last active August 29, 2015 13:57
RSS promotion default migrations
# This migration will loop through all RssPromotions and ensure that the default values from the 'unsent'
# mailing are correctly migrated to the new defaults created for RssPromotions, specifically:
# - new fields on the rss_promotion
# - rss_promotion has_and_belongs_to_many :audience_lists
# - rss_promotion has_and_belongs_to_many :audience_members
migrated_count = 0
RssPromotion.find_each do |rss_promotion|
mailing = rss_promotion.mailing