1
+ #TODO DELETE ME
2
+ class TeamMigratorJob
3
+ include Sidekiq ::Worker
4
+
5
+ sidekiq_options backtrace : true
6
+
7
+ def perform ( id )
8
+ team = Team . find ( id )
9
+ if pgteam = find_or_initialize_team ( id , team )
10
+ extract_account ( pgteam , team )
11
+
12
+ extract_locations ( pgteam , team )
13
+ extract_links ( pgteam , team )
14
+ add_members ( pgteam )
15
+ add_jobs ( pgteam )
16
+ convert_followers ( pgteam )
17
+ add_pending_requests ( pgteam , team )
18
+ end
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def find_or_initialize_team ( id , team )
25
+ begin
26
+ PgTeam . find_or_initialize_by_mongo_id ( id ) do |pgteam |
27
+ pgteam . name = team . name
28
+ pgteam . slug = team . slug
29
+ pgteam . created_at = team . created_at
30
+ pgteam . updated_at = team . updated_at
31
+ pgteam . website = team . website
32
+ pgteam . about = team . about
33
+ pgteam . total = team . total
34
+ pgteam . size = team . size
35
+ pgteam . mean = team . mean
36
+ pgteam . median = team . median
37
+ pgteam . score = team . score
38
+ pgteam . twitter = team . twitter
39
+ pgteam . facebook = team . facebook
40
+ pgteam . premium = team . premium
41
+ pgteam . analytics = team . analytics
42
+ pgteam . valid_jobs = team . valid_jobs
43
+ pgteam . hide_from_featured = team . hide_from_featured
44
+ pgteam . preview_code = team . preview_code
45
+ pgteam . youtube_url = team . youtube_url
46
+ pgteam . github = team . github
47
+ pgteam . highlight_tags = team . highlight_tags
48
+ pgteam . branding = team . branding
49
+ pgteam . headline = team . headline
50
+ pgteam . big_quote = team . big_quote
51
+ pgteam . big_image = team . big_image
52
+ pgteam . featured_banner_image = team . featured_banner_image
53
+ pgteam . benefit_name_1 = team . benefit_name_1
54
+ pgteam . benefit_description_1 = team . benefit_description_1
55
+ pgteam . benefit_name_2 = team . benefit_name_2
56
+ pgteam . benefit_description_2 = team . benefit_description_2
57
+ pgteam . benefit_name_3 = team . benefit_name_3
58
+ pgteam . benefit_description_3 = team . benefit_description_3
59
+ pgteam . reason_name_1 = team . reason_name_1
60
+ pgteam . reason_description_1 = team . reason_description_1
61
+ pgteam . reason_name_2 = team . reason_name_2
62
+ pgteam . reason_description_2 = team . reason_description_2
63
+ pgteam . reason_name_3 = team . reason_name_3
64
+ pgteam . reason_description_3 = team . reason_description_3
65
+ pgteam . why_work_image = team . why_work_image
66
+ pgteam . organization_way = team . organization_way
67
+ pgteam . organization_way_name = team . organization_way_name
68
+ pgteam . organization_way_photo = team . organization_way_photo
69
+ pgteam . office_photos = team . office_photos
70
+ pgteam . upcoming_events = team . upcoming_events
71
+ pgteam . featured_links_title = team . featured_links_title
72
+ pgteam . blog_feed = team . blog_feed
73
+ pgteam . our_challenge = team . our_challenge
74
+ pgteam . your_impact = team . your_impact
75
+ pgteam . interview_steps = team . interview_steps
76
+ pgteam . hiring_tagline = team . hiring_tagline
77
+ pgteam . link_to_careers_page = team . link_to_careers_page
78
+ # pgteam.avatar = team.avatar
79
+ pgteam . achievement_count = team . achievement_count
80
+ pgteam . endorsement_count = team . endorsement_count
81
+ pgteam . invited_emails = team . invited_emails
82
+ pgteam . pending_join_requests = team . pending_join_requests
83
+ pgteam . upgraded_at = team . upgraded_at
84
+ pgteam . paid_job_posts = team . paid_job_posts
85
+ pgteam . monthly_subscription = team . monthly_subscription
86
+ pgteam . stack_list = team . stack_list
87
+ pgteam . number_of_jobs_to_show = team . number_of_jobs_to_show
88
+ pgteam . location = team . location
89
+ pgteam . country_id = team . country_id
90
+ pgteam . github_organization_name = team . github_organization_name
91
+ pgteam . save!
92
+
93
+ end
94
+ rescue ActiveRecord ::RecordInvalid
95
+ false
96
+ end
97
+ end
98
+
99
+ def extract_account ( pgteam , team )
100
+ return unless account = team . account
101
+ return if pgteam . account
102
+ begin
103
+ pgaccount = pgteam . build_account (
104
+ stripe_card_token : account . stripe_card_token ,
105
+ stripe_customer_token : account . stripe_customer_token ,
106
+ admin_id : account . admin_id
107
+ )
108
+ pgaccount . plans << Plan . where ( id : account . plan_ids )
109
+ pgaccount . save!
110
+ rescue ActiveRecord ::RecordInvalid => e
111
+ # @just3ws, uncomment the following line and get all ID of the corrupted accounts
112
+ # raise e
113
+ false
114
+ end
115
+
116
+ end
117
+
118
+ def extract_locations ( pgteam , team )
119
+ locations = team . team_locations
120
+ return unless locations . any?
121
+ return if pgteam . locations . any?
122
+ locations . each do |location |
123
+ pgteam . locations . create! name : location . name ,
124
+ description : location . description ,
125
+ address : location . address ,
126
+ city : location . city ,
127
+ state_code : location . state_code ,
128
+ country : location . country
129
+
130
+ end
131
+ end
132
+
133
+ def extract_links ( pgteam , team )
134
+ links = team . featured_links
135
+ return if links . empty?
136
+ return if pgteam . links . any?
137
+ links . each do |link |
138
+ pgteam . links . create! name : link . name ,
139
+ url : link . url
140
+ end
141
+ end
142
+
143
+ def add_members ( pgteam )
144
+ users = User . where ( team_document_id : pgteam . mongo_id )
145
+ users . each do |user |
146
+ pgteam . members . create! user : user , state : 'active'
147
+ end
148
+ users . update_all ( team_id : pgteam . id )
149
+ end
150
+
151
+ def add_jobs ( pgteam )
152
+ Opportunity . where ( team_document_id : pgteam . mongo_id ) . update_all ( team_id : pgteam . id )
153
+ end
154
+
155
+ def convert_followers ( pgteam )
156
+ FollowedTeam . where ( team_document_id : pgteam . mongo_id ) . update_all ( team_id : pgteam . id )
157
+ end
158
+
159
+ def add_pending_requests ( pgteam , team )
160
+ pending_team_members = team . pending_team_members
161
+ return if pending_team_members . empty?
162
+ pending_team_members . each do |pending_team_member |
163
+ user = User . find pending_team_member . user_id
164
+ pgteam . members . create user : user ,
165
+ created_at : pending_team_member . created_at ,
166
+ updated_at : pending_team_member . updated_at
167
+ end
168
+ end
169
+ end
0 commit comments