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 @@