mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
fix forums not being seeded
This commit is contained in:
parent
2ad2a4347f
commit
08b4889b31
2 changed files with 49 additions and 47 deletions
|
@ -100,43 +100,41 @@ for comment_body <- resources["comments"] do
|
||||||
end
|
end
|
||||||
|
|
||||||
IO.puts "---- Generating forum posts"
|
IO.puts "---- Generating forum posts"
|
||||||
for resource <- resources["forum_posts"] do
|
for %{"forum" => forum_name, "topics" => topics} <- resources["forum_posts"] do
|
||||||
for {forum_name, topics} <- resource do
|
forum = Repo.get_by!(Forum, short_name: forum_name)
|
||||||
forum = Repo.get_by!(Forum, short_name: forum_name)
|
|
||||||
|
|
||||||
for {topic_name, [first_post | posts]} <- topics do
|
for %{"title" => topic_name, "posts" => [first_post | posts]} <- topics do
|
||||||
Topics.create_topic(
|
Topics.create_topic(
|
||||||
forum,
|
forum,
|
||||||
request_attributes,
|
request_attributes,
|
||||||
%{
|
%{
|
||||||
"title" => topic_name,
|
"title" => topic_name,
|
||||||
"posts" => %{
|
"posts" => %{
|
||||||
"0" => %{
|
"0" => %{
|
||||||
"body" => first_post,
|
"body" => first_post,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|> case do
|
)
|
||||||
{:ok, %{topic: topic}} ->
|
|> case do
|
||||||
for post <- posts do
|
{:ok, %{topic: topic}} ->
|
||||||
Posts.create_post(
|
for post <- posts do
|
||||||
topic,
|
Posts.create_post(
|
||||||
request_attributes,
|
topic,
|
||||||
%{"body" => post}
|
request_attributes,
|
||||||
)
|
%{"body" => post}
|
||||||
|> case do
|
)
|
||||||
{:ok, %{post: post}} ->
|
|> case do
|
||||||
Posts.reindex_post(post)
|
{:ok, %{post: post}} ->
|
||||||
|
Posts.reindex_post(post)
|
||||||
|
|
||||||
{:error, :post, changeset, _so_far} ->
|
{:error, :post, changeset, _so_far} ->
|
||||||
IO.inspect changeset.errors
|
IO.inspect changeset.errors
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
{:error, :topic, changeset, _so_far} ->
|
{:error, :topic, changeset, _so_far} ->
|
||||||
IO.inspect changeset.errors
|
IO.inspect changeset.errors
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,23 +57,27 @@
|
||||||
"spoilers inside of a table\n\nHello | World\n--- | ---:\n`||cool beans!||` | ||cool beans!||"
|
"spoilers inside of a table\n\nHello | World\n--- | ---:\n`||cool beans!||` | ||cool beans!||"
|
||||||
],
|
],
|
||||||
"forum_posts": [{
|
"forum_posts": [{
|
||||||
"dis": [{
|
"forum": "dis",
|
||||||
"Example topic": [
|
"topics": [{
|
||||||
"example post",
|
"title": "Example Topic",
|
||||||
"yet another example post"
|
"posts": [
|
||||||
]
|
"example post",
|
||||||
},
|
"yet another example post"
|
||||||
{
|
]
|
||||||
"Second example topic": [
|
},
|
||||||
"post",
|
{
|
||||||
"post 2"
|
"title": "Second Example Topic",
|
||||||
]
|
"posts": [
|
||||||
}
|
"post",
|
||||||
]
|
"post 2"
|
||||||
},
|
]
|
||||||
|
}
|
||||||
|
]},
|
||||||
{
|
{
|
||||||
"art": [{
|
"forum": "art",
|
||||||
"Embedded images": [
|
"topics": [{
|
||||||
|
"title": "Embedded Images",
|
||||||
|
"posts": [
|
||||||
">>1t >>1s >>1p",
|
">>1t >>1s >>1p",
|
||||||
">>1",
|
">>1",
|
||||||
"non-existent: >>1000t >>1000s >>1000p >>1000"
|
"non-existent: >>1000t >>1000s >>1000p >>1000"
|
||||||
|
|
Loading…
Reference in a new issue