forked from saurabh/orbit4-5
147 lines
3.6 KiB
Ruby
147 lines
3.6 KiB
Ruby
class Admin::SitesController < OrbitAdminController
|
|
before_filter :get_site
|
|
layout "structure"
|
|
|
|
def mail_setting
|
|
end
|
|
|
|
def site_info
|
|
@pages = Page.where(:module=>"page_content")
|
|
end
|
|
|
|
def responsive_setting
|
|
@module = ModuleApp.find_by_key("announcement")
|
|
end
|
|
|
|
def search_engine
|
|
end
|
|
|
|
def sitemap
|
|
end
|
|
|
|
def change_design
|
|
@site.template = params[:design_key]
|
|
@site.save
|
|
restart_server
|
|
end
|
|
|
|
def system_info
|
|
@disk_free = `df -h /`.gsub("\n","<br/>").html_safe
|
|
@nginx_version = %x[/opt/nginx/sbin/nginx -v 2>&1].gsub("\n","<br/>").html_safe
|
|
@mongo_version = `mongod --version`.split("\n")[0].html_safe
|
|
@linux_version = `lsb_release -d`.split(":")[1].html_safe
|
|
|
|
@user_actions = UserAction.all.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
@mail_crons = Email.can_deliver.desc(:created_at)
|
|
|
|
@mail_cron_logs = EmailLog.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.js
|
|
end
|
|
end
|
|
|
|
def preference
|
|
end
|
|
|
|
def update_manager
|
|
end
|
|
|
|
def update_orbit
|
|
end
|
|
|
|
def update
|
|
@site.update_attributes(site_params)
|
|
|
|
if params[:site][:enable_language_detection].eql?("0")
|
|
Site.update_all({:enable_language_detection => false})
|
|
elsif params[:site][:enable_language_detection].eql?("1")
|
|
Site.update_all({:default_locale => nil})
|
|
end
|
|
|
|
redirect_to :back
|
|
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
|
|
if (@current_tag.eql?(@latest_tag) == false)
|
|
%x(git fetch origin)
|
|
end
|
|
@new_updates = %x(git log "#{@current_tag}"..."#{@latest_tag}" --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 #{@latest_tag})
|
|
%x(git stash pop) unless need_stash
|
|
|
|
if pull_result.include? "fatal: Not possible to fast-forward, aborting."
|
|
result = "failed"
|
|
else
|
|
result = "success"
|
|
Bundler.with_clean_env { `cd #{Rails.root} && bundle install` }
|
|
end
|
|
|
|
render :text => result
|
|
end
|
|
|
|
def restart_server
|
|
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
|
sleep 5
|
|
render :nothing => true
|
|
end
|
|
|
|
private
|
|
def get_site
|
|
@site = Site.first
|
|
end
|
|
|
|
def site_params
|
|
if params[:site][:default_bar_color]
|
|
params[:site][:mobile_bar_color] = []
|
|
end
|
|
# if params[:site][:enable_language_detection]
|
|
# Site.update_all({:default_locale => nil})
|
|
# end
|
|
|
|
unless params[:site][:in_use_locales].nil?
|
|
in_user_locales = []
|
|
I18n.available_locales.each do |locale|
|
|
in_user_locales << locale if params[:site][:in_use_locales][locale].eql?("1")
|
|
end
|
|
params[:site][:in_use_locales] = in_user_locales
|
|
end
|
|
|
|
if params[:site][:phone_number].nil?
|
|
params[:site][:phone_number] = []
|
|
# else
|
|
# params[:site][:phone_number] = params[:site][:phone_number]
|
|
end
|
|
params.require(:site).permit!
|
|
|
|
end
|
|
|
|
|
|
def git_branch
|
|
@branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","")
|
|
end
|
|
|
|
def git_tags
|
|
@current_tag = %x(git describe --tags).gsub("\n","").split("-").first
|
|
@latest_tag = `git ls-remote --tags origin | awk '{print $2}'`.split(/\n/).last.gsub("refs/tags/","") rescue nil
|
|
end
|
|
end
|