[80746] branches/gsoc11-statistics/stats-server/app/models/submission.rb
derek at macports.org
derek at macports.org
Sat Jul 16 12:36:19 PDT 2011
Revision: 80746
http://trac.macports.org/changeset/80746
Author: derek at macports.org
Date: 2011-07-16 12:36:18 -0700 (Sat, 16 Jul 2011)
Log Message:
-----------
Update existing installed_port submissions for a given user if they re-submit during the same month
Modified Paths:
--------------
branches/gsoc11-statistics/stats-server/app/models/submission.rb
Modified: branches/gsoc11-statistics/stats-server/app/models/submission.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/submission.rb 2011-07-16 19:19:16 UTC (rev 80745)
+++ branches/gsoc11-statistics/stats-server/app/models/submission.rb 2011-07-16 19:36:18 UTC (rev 80746)
@@ -41,17 +41,28 @@
def add_port(user, macports_port, installed_port, month, year)
logger.debug {"Adding installed port #{installed_port['name']}"}
+
+ # Update any ports found for this user is they have already been submitted this month
+ port_entry = InstalledPort.find_by_port_id_and_user_id_and_month_and_year(macports_port.id,
+ user.id,
+ month,
+ year)
+
+ # New port entry
+ if port_entry.nil?
+ port_entry = InstalledPort.new
+ end
- portEntry = InstalledPort.new(:user_id => user.id,
- :port_id => macports_port.id,
- :version => installed_port['version'],
- :variants => installed_port['variants'],
- :month => month,
- :year => year)
-
- if not portEntry.save
- logger.debug "Unable to save port #{port['name']}"
- logger.debug "Error message: #{portEntry.errors.full_messages}"
+ port_entry[:user_id] = user.id
+ port_entry[:port_id] = macports_port.id
+ port_entry[:version] = installed_port['version']
+ port_entry[:variants] = installed_port['variants']
+ port_entry[:month] = month
+ port_entry[:year] = year
+
+ if not port_entry.save
+ logger.debug "Unable to save port #{installed_port['name']}"
+ logger.debug "Reason: #{port_entry.errors.full_messages}"
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110716/228c1928/attachment.html>
More information about the macports-changes
mailing list