@@ -150,43 +150,46 @@ namespace :db do
150
150
Badge . reset_pk_sequence
151
151
end
152
152
153
+ def port_data_since
154
+ [ "created_at > ? OR updated_at > ?" , 2 . day . ago , 2 . day . ago ]
155
+ end
156
+
153
157
task :users => :connect do
154
158
User . reset_pk_sequence
155
- Legacy [ :users ] . each do |row |
159
+ Legacy [ :users ] . where ( port_since ) . each do |row |
156
160
begin
157
161
user = User . find_or_initialize_by_id ( row [ :id ] )
158
- if user . new_record?
159
- user . attributes . keys . each do |key |
160
- user [ key ] = row [ key . to_sym ]
161
- end
162
-
163
- social_links = [ ]
164
- social_links << "[LinkedIn](#{ row [ :linkedin_public_url ] } )" unless row [ :linkedin_public_url ] . blank?
165
- social_links << "[Blog](#{ row [ :blog ] } )" unless row [ :blog ] . blank?
166
- social_links << "[Bitbucket](https://bitbucket.org/#{ row [ :bitbucket ] } )" unless row [ :bitbucket ] . blank?
167
- social_links << "[Codeplex](http://www.codeplex.com/site/users/view/#{ row [ :codeplex ] } )" unless row [ :codeplex ] . blank?
168
- social_links << "[Dribbble](http://dribbble.com/#{ row [ :dribbble ] } )" unless row [ :dribbble ] . blank?
169
- social_links << "[StackOverflow](http://stackoverflow.com/users/#{ row [ :stackoverflow ] } )" unless row [ :stackoverflow ] . blank?
170
- social_links << "[Speakerdeck](http://speakerdeck.com/u/#{ row [ :speakerdeck ] } )" unless row [ :speakerdeck ] . blank?
171
- social_links << "[Slideshare](http://www.slideshare.net/#{ row [ :slideshare ] } )" unless row [ :slideshare ] . blank?
172
- if !social_links . empty?
173
- user . about = '' if user . about . nil?
174
- user . about << "\n \n \n #{ social_links . join ( ' ' ) } \n \n "
175
- end
176
- user . karma = ( Legacy [ :endorsements ] . where ( endorsed_user_id : row [ :id ] ) . count + 1 )
177
- user . password = SecureRandom . hex
178
- user . skills = Legacy [ :skills ] . select ( :name , :tokenized ) . where (
179
- deleted : false ,
180
- user_id : row [ :id ] ) . collect { |row | row [ :name ] }
181
-
182
- if team = Legacy [ :teams ] . where ( id : row [ :team_id ] ) . collect . first
183
- user . company = team [ :name ]
184
- end
185
-
186
-
187
- Rails . logger . info "#{ row [ :username ] } => #{ row [ :email ] } "
188
- user . save!
162
+ user . attributes . keys . each do |key |
163
+ user [ key ] = row [ key . to_sym ]
164
+ end
165
+
166
+ social_links = [ ]
167
+ social_links << "[LinkedIn](#{ row [ :linkedin_public_url ] } )" unless row [ :linkedin_public_url ] . blank?
168
+ social_links << "[Blog](#{ row [ :blog ] } )" unless row [ :blog ] . blank?
169
+ social_links << "[Bitbucket](https://bitbucket.org/#{ row [ :bitbucket ] } )" unless row [ :bitbucket ] . blank?
170
+ social_links << "[Codeplex](http://www.codeplex.com/site/users/view/#{ row [ :codeplex ] } )" unless row [ :codeplex ] . blank?
171
+ social_links << "[Dribbble](http://dribbble.com/#{ row [ :dribbble ] } )" unless row [ :dribbble ] . blank?
172
+ social_links << "[StackOverflow](http://stackoverflow.com/users/#{ row [ :stackoverflow ] } )" unless row [ :stackoverflow ] . blank?
173
+ social_links << "[Speakerdeck](http://speakerdeck.com/u/#{ row [ :speakerdeck ] } )" unless row [ :speakerdeck ] . blank?
174
+ social_links << "[Slideshare](http://www.slideshare.net/#{ row [ :slideshare ] } )" unless row [ :slideshare ] . blank?
175
+ if !social_links . empty?
176
+ user . about = '' if user . about . nil?
177
+ user . about << "\n \n \n #{ social_links . join ( ' ' ) } \n \n "
178
+ end
179
+ user . karma = ( Legacy [ :endorsements ] . where ( endorsed_user_id : row [ :id ] ) . count + 1 )
180
+ user . password = SecureRandom . hex
181
+ user . skills = Legacy [ :skills ] . select ( :name , :tokenized ) . where (
182
+ deleted : false ,
183
+ user_id : row [ :id ] ) . collect { |row | row [ :name ] }
184
+
185
+ if team = Legacy [ :teams ] . where ( id : row [ :team_id ] ) . collect . first
186
+ user . company = team [ :name ]
189
187
end
188
+
189
+
190
+ Rails . logger . info "#{ row [ :username ] } => #{ row [ :email ] } "
191
+ user . save!
192
+
190
193
end
191
194
end
192
195
User . reset_pk_sequence
@@ -216,7 +219,6 @@ namespace :db do
216
219
end
217
220
Protip . reset_pk_sequence
218
221
end
219
-
220
222
end
221
223
222
224
# rails r 'puts Badges.all.each{|b| puts "\"#{b.name}\" => [\"#{b.display_name}\", \"#{b.image_path.gsub("badges/", "")}\", \"#{b.description}\", \"#{b.for}\"]," }'
0 commit comments