Skip to content

Commit

Permalink
Deprecate dcterms_valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Puchalski committed Feb 1, 2011
1 parent 40b15b2 commit 5e54859
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 24 deletions.
4 changes: 1 addition & 3 deletions app/models/action.rb
Expand Up @@ -42,7 +42,6 @@ class Action < ActiveRecord::Base
string :platform_email
string :organization_name
string :organization_email
string :dcterms_valid
string :ein, :using => :organization_ein
end

Expand Down Expand Up @@ -74,7 +73,7 @@ def set_defaults
end

named_scope :expired,
:conditions => "(disabled = 0 OR disabled IS NULL) AND dcterms_valid IS NULL AND NOW() > expires_at"
:conditions => "(disabled = 0 OR disabled IS NULL) AND NOW() > expires_at"

named_scope :long_disabled,
:conditions => "disabled = 1 AND TIMESTAMPDIFF(DAY, disabled_on, NOW()) > 30"
Expand Down Expand Up @@ -132,7 +131,6 @@ def self.json_options
:initiator_url,
:initiator_email,
:expires_at,
:dcterms_valid,
:platform_name,
:platform_url,
:platform_email,
Expand Down
1 change: 0 additions & 1 deletion app/views/actions/index.atom.builder
Expand Up @@ -35,7 +35,6 @@ xml.feed(:xmlns => 'http://www.w3.org/2005/Atom',
xml.oa :numberOfContributors, action.goal_number_of_contributors unless action.goal_number_of_contributors.blank?
end
end
xml.dcterms :valid, action.dcterms_valid unless action.dcterms_valid.blank?
xml.category :term => action.action_type.name, :scheme => 'http://socialactions.com/action_types'
action.tags.each do |tag|
xml.category :term => tag
Expand Down
1 change: 0 additions & 1 deletion app/views/actions/index.rss.builder
Expand Up @@ -30,7 +30,6 @@ xml.rss :version => "2.0", 'xmlns:atom' => 'http://www.w3.org/2005/Atom', 'xmlns
xml.oa :numberOfContributors, action.goal_number_of_contributors unless action.goal_number_of_contributors.blank?
end
end
xml.dcterms :valid, action.dcterms_valid unless action.dcterms_valid.blank?
xml.atom :category, :term => action.action_type.name, :scheme => 'http://socialactions.com/action_types'
action.tags.each do |tag|
xml.atom :category, :term => tag
Expand Down
1 change: 0 additions & 1 deletion app/views/actions/index.xml.builder
Expand Up @@ -17,7 +17,6 @@ xml.actions do
xml.initiator_url action.initiator_url
xml.initiator_email action.initiator_email
xml.expires_at action.expires_at
xml.dcterms_valid action.dcterms_valid
xml.platform_name action.platform_name
xml.platform_url action.platform_url
xml.platform_email action.platform_email
Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20101220112200_remove_dcterms_valid.rb
@@ -0,0 +1,23 @@
class RemoveDctermsValid < ActiveRecord::Migration
def self.up
# Remove bad dcterms_valid fields
Action.scoped(:conditions => "dcterms_valid = 'donate'").all.each do |a|
a.dcterms_valid = nil
a.save
end

Action.scoped(:conditions => 'dcterms_valid IS NOT NULL').all.each do |a|
dt = DateTime.parse(a.dcterms_valid.sub(/end=/, ''))
p "#{a.id} #{a.dcterms_valid} #{dt}"
a.expires_at = dt
a.dcterms_valid = nil
a.save
end; nil

remove_column :actions, :dcterms_valid
end

def self.down
add_column :actions, :dcterms_valid, :string
end
end
2 changes: 1 addition & 1 deletion lib/action_source_plugins/csv.rb
Expand Up @@ -53,7 +53,7 @@ def populate_action(entry)
# import text & number fields as-isfor each field listed here, we will import data from the CSV into the new record
['description', 'url', 'title', 'created_at', 'updated_at', 'latitude', 'longitude', 'location', 'short_url',
'image_url', 'subtitle', 'goal_completed', 'goal_amount', 'goal_type', 'goal_number_of_contributors',
'initiator_name', 'initiator_url', 'initiator_email', 'expires_at', 'dcterms_valid', 'platform_name',
'initiator_name', 'initiator_url', 'initiator_email', 'expires_at', 'platform_name',
'platform_url', 'platform_email', 'embed_widget', 'organization_name', 'organization_url',
'organization_email', 'organization_ein', 'tags', 'redirect_id', 'hit_count',
'location_city', 'location_country', 'location_state', 'location_postalcode', 'disabled'].each do |field|
Expand Down
1 change: 0 additions & 1 deletion lib/action_source_plugins/donors_choose_json.rb
Expand Up @@ -8,7 +8,6 @@ def parse
json['proposals'].each do |proposal|
action = actions.find_or_create_by_url(proposal['proposalURL'])
action.expires_at = proposal['expirationDate']
action.dcterms_valid = "end=" + proposal['expirationDate'].xmlschema
action.description = proposal['shortDescription']
action.title = proposal['title']
action.goal_amount = proposal['totalPrice']
Expand Down
1 change: 0 additions & 1 deletion lib/action_source_plugins/feed.rb
Expand Up @@ -42,7 +42,6 @@ def populate_action(entry)
action.goal_number_of_contributors = entry.oa_goal.oa_numberofcontributors
end

action.dcterms_valid = entry.dcterms_valid
if entry.dcterms_valid and entry.dcterms_valid.match(/(^|;)\s*end=([^;]+)/)
action.expires_at = $2
end
Expand Down
1 change: 0 additions & 1 deletion lib/action_source_plugins/wiser_earth_feed.rb
Expand Up @@ -102,7 +102,6 @@ def populate_action(entry)
#action.goal_number_of_contributors = entry.oa_goal.oa_numberofcontributors
#end

#action.dcterms_valid = entry.dcterms_valid
#if entry.dcterms_valid and entry.dcterms_valid.match(/(^|;)\s*end=([^;]+)/)
#action.expires_at = $2
#end
Expand Down
19 changes: 5 additions & 14 deletions lib/expire_actions.rb
Expand Up @@ -9,22 +9,13 @@ module ClassMethods
def expire_actions
# Note: dcterms expirations were implemented but never tested
#self.expire_actions_by_dcterms_valid
self.expire_actions_by_action_lifespan
self.delete_long_expired_actions
actions = self.expire_actions
p "Expired #{actions.count} actions"
actions = self.delete_long_expired_actions
p "Deleted #{actions.count} long-expired actions"
end

def expire_actions_by_dcterms_valid
actions = Action.scoped(:conditions => 'dcterms_valid IS NOT NULL')
actions.all.each do |action|
if !action.disabled && (action.dcterms_valid.to_date <= DateTime.now)
action.disabled = true
action.save!
end
end
actions
end

def expire_actions_by_action_lifespan
def expire_actions
# Disable an actions past their expiration date
actions = Action.expired.all
actions.each do |action|
Expand Down

0 comments on commit 5e54859

Please sign in to comment.