@@ -21,23 +21,19 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
21
21
alias CMS.Delegate.SeedsConfig
22
22
alias CMS.Delegate.Seeds
23
23
24
- # threads
25
- @ lang_threads Seeds.Threads . get ( :lang )
26
-
27
24
@ pl_communities Seeds.Communities . get ( :pl )
28
25
@ framework_communities Seeds.Communities . get ( :framework )
29
26
@ editor_communities Seeds.Communities . get ( :editor )
30
27
@ database_communities Seeds.Communities . get ( :database )
31
28
@ devops_communities Seeds.Communities . get ( :devops )
32
- @ city_communities Seeds.Communities . get ( :city )
33
29
# categories
34
30
@ default_categories Seeds.Categories . get ( :default )
35
31
36
32
@ doc """
37
33
seed communities pragraming languages
38
34
"""
39
35
def seed_communities ( :pl ) do
40
- with { :ok , threads } <- seed_threads ( :lang ) ,
36
+ with { :ok , threads } <- seed_threads ( :pl ) ,
41
37
{ :ok , bot } <- seed_bot ( ) ,
42
38
{ :ok , categories } <- seed_categories ( bot , :default ) ,
43
39
{ :ok , communities } <- seed_for_communities ( bot , :pl ) do
@@ -51,7 +47,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
51
47
seed communities for frameworks
52
48
"""
53
49
def seed_communities ( :framework ) do
54
- with { :ok , threads } <- seed_threads ( :lang ) ,
50
+ with { :ok , threads } <- seed_threads ( :framework ) ,
55
51
{ :ok , bot } <- seed_bot ( ) ,
56
52
{ :ok , _categories } <- seed_categories ( bot , :default ) ,
57
53
{ :ok , communities } <- seed_for_communities ( bot , :framework ) do
@@ -66,7 +62,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
66
62
seed communities for editors
67
63
"""
68
64
def seed_communities ( :editor ) do
69
- with { :ok , threads } <- seed_threads ( :lang ) ,
65
+ with { :ok , threads } <- seed_threads ( :editor ) ,
70
66
{ :ok , bot } <- seed_bot ( ) ,
71
67
{ :ok , categories } <- seed_categories ( bot , :default ) ,
72
68
{ :ok , communities } <- seed_for_communities ( bot , :editor ) do
@@ -81,7 +77,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
81
77
seed communities for database
82
78
"""
83
79
def seed_communities ( :database ) do
84
- with { :ok , threads } <- seed_threads ( :lang ) ,
80
+ with { :ok , threads } <- seed_threads ( :database ) ,
85
81
{ :ok , bot } <- seed_bot ( ) ,
86
82
{ :ok , _categories } <- seed_categories ( bot , :default ) ,
87
83
{ :ok , communities } <- seed_for_communities ( bot , :database ) do
@@ -96,7 +92,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
96
92
seed communities for database
97
93
"""
98
94
def seed_communities ( :devops ) do
99
- with { :ok , threads } <- seed_threads ( :lang ) ,
95
+ with { :ok , threads } <- seed_threads ( :devops ) ,
100
96
{ :ok , bot } <- seed_bot ( ) ,
101
97
{ :ok , categories } <- seed_categories ( bot , :default ) ,
102
98
{ :ok , communities } <- seed_for_communities ( bot , :devops ) do
@@ -111,10 +107,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
111
107
seed communities for cities
112
108
"""
113
109
def seed_communities ( :city ) do
114
- Seeds.Communities . get ( :city )
115
- |> Enum . each ( & seed_community ( & 1 , :city ) )
116
-
117
- { :ok , :pass }
110
+ Seeds.Communities . get ( :city ) |> Enum . each ( & seed_community ( & 1 , :city ) ) |> done
118
111
end
119
112
120
113
@ doc """
@@ -155,36 +148,17 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
155
148
end
156
149
end
157
150
158
- @ doc """
159
- seed default threads like: post, user, wiki, cheetsheet, job ..
160
- """
161
- def seed_threads ( :default ) do
162
- case ORM . find_by ( Thread , % { raw: "post" } ) do
163
- { :ok , _ } ->
164
- { :ok , :pass }
165
-
166
- { :error , _ } ->
167
- @ lang_threads
168
- |> Enum . each ( fn thread ->
169
- { :ok , _thread } = CMS . create_thread ( thread )
170
- end )
171
- end
172
-
173
- thread_titles =
174
- @ lang_threads
175
- |> Enum . reduce ( [ ] , fn x , acc -> acc ++ [ x . title ] end )
176
-
177
- Thread
178
- |> where ( [ t ] , t . raw in ^ thread_titles )
179
- |> ORM . paginator ( page: 1 , size: 30 )
180
- |> done ( )
181
- end
182
-
183
151
def seed_threads ( :city ) , do: do_seed_threads ( :city )
184
152
def seed_threads ( :home ) , do: do_seed_threads ( :home )
185
153
186
- defp do_seed_threads ( community ) do
187
- threads = Seeds.Threads . get ( community )
154
+ # def seed_threads(:feedback), do: do_seed_threads(:home)
155
+ # def seed_threads(:adwall), do: do_seed_threads(:home)
156
+ # def seed_threads(:blackhole), do: do_seed_threads(:home)
157
+
158
+ def seed_threads ( _ ) , do: do_seed_threads ( :lang )
159
+
160
+ defp do_seed_threads ( type ) do
161
+ threads = Seeds.Threads . get ( type )
188
162
threads_list = threads |> Enum . map ( & & 1 . raw )
189
163
190
164
with { :error , _ } <- ORM . find_by ( Thread , % { raw: "post" } ) do
@@ -263,17 +237,11 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
263
237
end
264
238
265
239
defp seed_for_communities ( bot , :devops ) do
266
- with { :error , _ } <- ORM . find_by ( Community , % { raw: "cps-support " } ) do
240
+ with { :error , _ } <- ORM . find_by ( Community , % { raw: "shell " } ) do
267
241
{ :ok , _communities } = insert_multi_communities ( bot , @ devops_communities , :devops )
268
242
end
269
243
end
270
244
271
- defp seed_for_communities ( bot , :city ) do
272
- with { :error , _ } <- ORM . find_by ( Community , % { raw: "chengdu" } ) do
273
- { :ok , _communities } = insert_multi_communities ( bot , @ city_communities , :city )
274
- end
275
- end
276
-
277
245
defp insert_multi_communities ( bot , communities , type ) do
278
246
type = Atom . to_string ( type )
279
247
@@ -319,14 +287,22 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
319
287
end
320
288
321
289
defp tagfy_threads ( communities , _threads , bot , :city ) when is_list ( communities ) do
290
+ Enum . each ( communities , fn community ->
291
+ # IO.inspect(community.title, label: "create tags for")
292
+ # IO.inspect(community.id, label: "id")
293
+ create_tags ( community , :post , bot , :city )
294
+ end )
295
+ end
296
+
297
+ defp tagfy_threads ( communities , _threads , bot , :pl ) when is_list ( communities ) do
298
+ # TODO: tags for all threads
322
299
Enum . each ( communities , fn community ->
323
300
create_tags ( community , :post , bot , :city )
324
301
end )
325
302
end
326
303
327
304
defp tagfy_threads ( community , threads , bot , :home ) do
328
- threads
329
- |> Enum . each ( & create_tags ( community , & 1 , bot , :home ) )
305
+ threads |> Enum . each ( & create_tags ( community , & 1 , bot , :home ) )
330
306
end
331
307
332
308
defp tagfy_threads ( communities , threads , bot ) when is_list ( communities ) do
@@ -345,9 +321,15 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
345
321
end )
346
322
end
347
323
348
- defp create_tags ( % Community { } = community , :post , bot , :city ) do
349
- Enum . each ( Seeds.Tags . get ( community , :post , :city ) , fn attr ->
350
- CMS . create_article_tag ( community , :post , attr , bot )
324
+ defp create_tags ( % Community { } = community , thread , bot , :pl ) do
325
+ Enum . each ( Seeds.Tags . get ( community , thread , :pl ) , fn attr ->
326
+ CMS . create_article_tag ( community , thread , attr , bot )
327
+ end )
328
+ end
329
+
330
+ defp create_tags ( % Community { } = community , thread , bot , :city ) do
331
+ Enum . each ( Seeds.Tags . get ( community , thread , :city ) , fn attr ->
332
+ CMS . create_article_tag ( community , thread , attr , bot )
351
333
end )
352
334
end
353
335