Skip to content

Commit

Permalink
Merge branch 'master' of github.com:infinityoneframework/infinity_one
Browse files Browse the repository at this point in the history
  • Loading branch information
smpallen99 committed Apr 14, 2018
2 parents de2a039 + c7760ec commit b58cea6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
31 changes: 31 additions & 0 deletions lib/infinity_one/release_tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defmodule InfinityOne.ReleaseTasks do
alias InfinityOne.Repo
alias InfinityOne.Accounts
alias OneChat.Channel
alias OneChat.Settings.Layout
alias OneChat.Direct

require Logger

Expand Down Expand Up @@ -176,6 +178,35 @@ defmodule InfinityOne.ReleaseTasks do
end
end)
end
end

@doc """
Reset the admin layout content_home_body setting back to its default.
Run this command after upgrading a system to get the default content page which
includes the link to download the desktop clients.
"""
def reset_content_home_body do
default = Layout.schema().__struct__
Layout.update(Layout.get, %{content_home_body: default.content_home_body})
end

@doc """
Run database migration functions, if required.
Run this command after upgrading system to execute database migration functions.
"""
def migrate_dm_friends do
if Enum.any?(Direct.list(), & is_nil(&1.friend_id)) do
IO.puts "Migration required! Running now"
result = Direct.migrate_db()
if result != [] do
IO.puts "Some errors were found. Please check the output below!"
end
result
else
IO.puts "Migration not needed!"
end
end

end
14 changes: 8 additions & 6 deletions plugins/one_chat/lib/one_chat/models/direct.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ defmodule OneChat.Direct do

def migrate_db() do
__MODULE__.list()
|> Enum.reduce([], fn direct, acc ->
user = InfinityOne.Accounts.get_by_username(direct.users)
case __MODULE__.update(direct, %{friend_id: user.id}) do
{:ok, _} -> acc
{:error, changeset} -> [changeset | acc]
end
|> Enum.reduce([], fn
%{friend_id: nil} = direct, acc ->
friend = InfinityOne.Accounts.get_by_username(direct.users)
case __MODULE__.update(direct, %{friend_id: friend.id}) do
{:ok, _} -> acc
{:error, changeset} -> [changeset | acc]
end
_, acc -> acc
end)
end

Expand Down

0 comments on commit b58cea6

Please sign in to comment.