[80570] branches/gsoc11-statistics/stats-server/app/controllers/ submissions_controller.rb
derek at macports.org
derek at macports.org
Thu Jul 14 23:35:23 PDT 2011
Revision: 80570
http://trac.macports.org/changeset/80570
Author: derek at macports.org
Date: 2011-07-14 23:35:23 -0700 (Thu, 14 Jul 2011)
Log Message:
-----------
Added some basic port information verification, small refactor of port saving
- Ensure that a submitted port exists in the MacPorts repository (port table) before saving
- Renamed add_port_data to add_installed_ports
- Moved port saving code from inside a loop to add_port helper method
Modified Paths:
--------------
branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb
Modified: branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb 2011-07-15 06:13:50 UTC (rev 80569)
+++ branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb 2011-07-15 06:35:23 UTC (rev 80570)
@@ -35,7 +35,7 @@
gcc_version = os['gcc_version']
xcode_version = os['xcode_version']
- # Try and find an existing entry
+ # Try to find an existing entry
os_stats = OsStatistic.find_by_user_id(user.id)
if os_stats.nil?
@@ -58,10 +58,26 @@
end
end
- def add_port_data(uuid, ports)
- logger.debug "In add_port_data"
+ def add_port(uuid, macports_port, installed_port, month, year)
+ logger.debug {"Adding installed port #{installed_port['name']}"}
+
+ portEntry = InstalledPort.new(:uuid => uuid,
+ :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}"
+ end
+ end
+
+ def add_installed_ports(uuid, installed_ports)
+ logger.debug "In add_installed_ports"
- if ports.nil?
+ if installed_ports.nil?
return
end
@@ -69,20 +85,17 @@
month = current_time.month
year = current_time.year
- ports.each do |port|
- logger.debug {"Adding port #{port}"}
- port_id = 5
- portEntry = InstalledPort.new(:uuid => uuid,
- :port_id => port_id,
- :version => port['version'],
- :variants => 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}"
- end
+ installed_ports.each do |installed_port|
+ # Find the reported port in the MacPorts repository
+ macports_port = Port.find_by_name(installed_port['name'])
+
+ if macports_port.nil?
+ logger.debug {"Skipping unknown port #{installed_port['name']} - Not in MacPorts repository"}
+ next
+ end
+
+ # Update installed port information
+ add_port(uuid, macports_port, installed_port, month, year)
end
end
@@ -96,7 +109,7 @@
user = User.find_or_create_by_uuid(json['id'])
add_os_data(user, os)
- add_port_data(json['id'], active_ports)
+ add_installed_ports(json['id'], active_ports)
respond_to do |format|
format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110714/6309fd1c/attachment-0001.html>
More information about the macports-changes
mailing list