diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 3adc9e02..e4119661 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -3,6 +3,7 @@ class Admin::SitesController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? before_filter :get_site + before_filter :git_branch # def index # @site = Site.first @@ -107,6 +108,43 @@ class Admin::SitesController < OrbitBackendController render :nothing => true end + def update_manager + end + + def get_update_history + @update_log = %x{git log --pretty=format:"%ad','%s" --date=short}.split("\n").map{|log| log.gsub("'","").split(",")}.to_json + render :json => @update_log + end + + def check_updates + %x(git fetch origin) + @new_updates = %x(git log #{@branch}..origin/#{@branch} --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json + render :json => @new_updates + end + + def update_orbit + result = "" + need_stash = %x(git diff).blank? + %x(git stash) unless need_stash + %x(git fetch origin) + pull_result = %x(git pull -r --ff-only 2>&1 origin #{@branch}) + + if pull_result.include? "fatal: Not possible to fast-forward, aborting." + result = "failed" + else + result = "success" + %x{bundle install} + %x{touch tmp/restart.txt} + end + %x(git stash pop) unless need_stash + + render :text => result + end + + def restart_server + render :text => "success" + end + protected def update_design(design) @@ -124,5 +162,9 @@ class Admin::SitesController < OrbitBackendController def get_site @site ||= Site.first end + + def git_branch + @branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","") + end end diff --git a/app/views/admin/items/_site_bar.html.erb b/app/views/admin/items/_site_bar.html.erb index af9639fe..a83af59a 100644 --- a/app/views/admin/items/_site_bar.html.erb +++ b/app/views/admin/items/_site_bar.html.erb @@ -20,6 +20,8 @@
  • <%= link_to admin_site_preference_path(@site), :class => active_for_action('sites', 'preference') do %><%end%>
  • +
  • <%= link_to admin_site_update_manager_path(@site), :class => active_for_action('sites', 'update_manager') do %><%end%>
  • + diff --git a/app/views/admin/sites/_side_bar.html.erb b/app/views/admin/sites/_side_bar.html.erb index af9639fe..a83af59a 100644 --- a/app/views/admin/sites/_side_bar.html.erb +++ b/app/views/admin/sites/_side_bar.html.erb @@ -20,6 +20,8 @@
  • <%= link_to admin_site_preference_path(@site), :class => active_for_action('sites', 'preference') do %><%end%>
  • +
  • <%= link_to admin_site_update_manager_path(@site), :class => active_for_action('sites', 'update_manager') do %><%end%>
  • + diff --git a/app/views/admin/sites/update_manager.erb b/app/views/admin/sites/update_manager.erb new file mode 100644 index 00000000..abd95d11 --- /dev/null +++ b/app/views/admin/sites/update_manager.erb @@ -0,0 +1,245 @@ +<% content_for :side_bar do %> + <%= render :partial => 'layouts/side_bar', :locals => {:link_name => t('site.settings'), :link_url => admin_site_site_info_path(@site), :icon => 'icons-cog', :side_bar_content => 'admin/sites/side_bar'} %> +<% end %> + +
    +
    +
    +
    +
    +
    + + + <%= t("update_manager_.available_updates") %> + +
    +
    + + + + +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + <%= t("update_manager_.update_status") %> +
    +
    +
    +     <%= t("update_manager_.update_done") %> +
    +
    +     <%= t("update_manager_.update_faild") %> +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + <%= t("update_manager_.update_history") %> + +
    +
    + + + + +
    +
    +
    +
    +
    +
    + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 187d6df4..0d64cb63 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -532,6 +532,18 @@ en: success_: Successfully updated update_: Update update_at: Update at + update_manager: Update Manager + update_manager_: + available_updates: Available Updates + check_update: Check Update + checking_update: Checking for Updates + system_update: Install Updates + update_done: System is update to date + update_faild: Update failed. Merge is require in the update. Please login to server and update manually. + update_history: Update Histroy + update_status: Update Status + updating_orbit: Updating Orbit. Please wait. + restart_server: Restarting Server. Please wait. upload: Upload url: URL use_status: Use Statue diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index f9c0f8f4..864778e9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -535,6 +535,18 @@ zh_tw: success_: 使用者已更新成功 update_: 更新 update_at: 最後更新時間 + update_manager: 更新管理員 + update_manager_: + available_updates: 有可用更新 + check_update: 檢查更新 + checking_update: 檢查更新中 + system_update: 安裝更新 + update_done: 系統已是最新版本 + update_faild: 更新失敗. 更新需要合併程式碼. 請登入伺服器手動進行更新. + update_history: 更新紀錄 + update_status: 更新狀態 + updating_orbit: 安裝更新中,請稍候. + restart_server: 重啟伺服器中,請稍候. upload: 上傳 url: 網址 use_status: 使用狀態 diff --git a/config/routes.rb b/config/routes.rb index 0707d85e..d3d4ebaa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,6 +212,11 @@ Orbit::Application.routes.draw do get 'change_design' get 'reset_default_locale' get 'preference' + get 'update_manager' + get 'get_update_history' + get 'check_updates' + get 'update_orbit' + get 'restart_server' end resources :tags do