Skip to content

Commit

Permalink
Unify the profile and userdata parsing code so that we can gracefully
Browse files Browse the repository at this point in the history
handle profiles where the runkeeper user has not set a real name.
  • Loading branch information
nugget committed Mar 16, 2013
1 parent 772efdd commit f127ba3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions packages/ergkeeper/runkeeper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,28 @@ proc runkeeper_import_new_activities {user_id log} {
return [list $workouts_loaded $workouts_in_file]
}

proc runkeeper_profile_to_array {hashdata} {
array set buf $hashdata
if {[info exists buf(profile)] && ![info exists buf(name)]} {
if {[regexp {([^\/]+)$} $buf(profile) _ uid]} {
if {[ctype digit $uid]} {
set buf(name) "User $uid"
} else {
set buf(name) "$uid"
}
}
}
foreach mandatory {name} {
if {![info exists buf($mandatory)] || $buf($mandatory) eq ""} {
set buf($mandatory) Unknown
}
}
return [array get buf]
}

proc runkeeper_userinfo_to_array {hashdata} {
array set buf $hashdata
return [array get buf]
}

package provide ergkeeper 1.0
4 changes: 2 additions & 2 deletions packages/ergkeeper/web.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ namespace eval ::ergkeeper {
set retbuf ""

pg_select $::db "SELECT * FROM users WHERE id = $user_id" buf {
array set profile $buf(runkeeper_profile)
array set userinfo $buf(runkeeper_userinfo)
array set profile [runkeeper_profile_to_array $buf(runkeeper_profile)]
array set userinfo [runkeeper_userinfo_to_array $buf(runkeeper_userinfo)]

if {[string is true -strict $::user(admin)]} {
append retbuf "<a href=\"/admin/view/users/$buf(id)\">"
Expand Down
4 changes: 2 additions & 2 deletions webroot/admin/users.rvt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
(SELECT count(*) FROM activities a WHERE a.user_id = u.id AND posted IS NOT NULL) as uploads
FROM users u ORDER BY added DESC" buf {
unset -nocomplain profile userinfo
array set profile $buf(runkeeper_profile)
array set userinfo $buf(runkeeper_userinfo)
array set profile [runkeeper_profile_to_array $buf(runkeeper_profile)]
array set userinfo [runkeeper_userinfo_to_array $buf(runkeeper_userinfo)]

puts "<tr [rowclass row]>"
puts "<td>"
Expand Down

0 comments on commit f127ba3

Please sign in to comment.