diff --git a/announcement.gemspec b/announcement.gemspec
index 0d06542..339df7e 100644
--- a/announcement.gemspec
+++ b/announcement.gemspec
@@ -11,9 +11,8 @@ old_gemfile_text = File.read(ENV['PWD']+'/Gemfile')
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n\n @media (min-width: $screen-sm) {\n width: 100%;\n }\n\n @media (min-width: $screen-md) {\n width: 970px;\n }\n\n @media (min-width: $screen-lg) {\n width: 1100px;\n }\n}\n"]
git_url = %x[cd '#{ENV['PWD']}' && git config --get remote.origin.url].sub("\n",'')
git_remote = %x[cd '#{ENV['PWD']}' && git remote].sub("\n",'')
-puts ['git_url',git_url]
-puts ['git_remote',git_remote]
if git_url != 'https://ruling.digital/git'
+ puts 'changing remote url'
system("cd #{ENV['PWD']} && git remote set-url #{git_remote} https://ruling.digital/git")
end
all_template.each do |folder|
@@ -39,9 +38,8 @@ end
if old_gemfile_text != new_gemfile_text
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
puts 'updating gemfile'
- File.open(ENV['PWD']+'/Gemfile', 'w') do |file|
- file.write new_gemfile_text
- end
+ %x[cp -f '#{ENV['PWD']}'/Gemfile '#{ENV['PWD']}'/Gemfile.bak123]
+ %x[cp -f '#{app_path}'/temp_file/Gemfile '#{ENV['PWD']}'/Gemfile]
old_playground = File.read (ENV['PWD']+'/app/controllers/admin/playground_controller.rb') rescue ''
new_playground = File.read (app_path+'/temp_file/playground_controller.rb') rescue ''
command2 = ''
@@ -62,6 +60,7 @@ if old_gemfile_text != new_gemfile_text
# file.write new_multithread
#end
end
+ command4 = "cp -rf #{app_path}/temp_file/app #{ENV['PWD']}/app"
log_development = File.mtime(ENV['PWD']+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
log_production = File.mtime(ENV['PWD']+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
if log_development > log_production
@@ -70,13 +69,25 @@ if old_gemfile_text != new_gemfile_text
mode = 'production'
end
files = Dir[ENV['PWD']+'/Gemfile.lock']
+ %x["screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill"]
if files.count ==0
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && bundle update"
else
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && mv -f Gemfile.lock Gemfile.lock.bak123 && bundle update"
end
dir_name = ENV['PWD'].split('/')[-1]
- all_command = "#{command1} && cd #{ENV['PWD']} && screen -d -m -S auto_reopen_#{dir_name} watch -n 30 bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now ; #{command2} ; #{command3} ; kill -s TERM `cat tmp/pids/unicorn.pid` ; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now"
+ Bundler.with_clean_env{system("screen -d -m -S auto_reopen_#{dir_name} watch -n 30 bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now")}
+ filedata = File.read(ENV['PWD']+"/built_in_extensions.rb")
+ exist_str = "gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'"
+ if filedata.include? exist_str
+ puts "patchfile exist"
+ else
+ @file = ENV['PWD']+"/built_in_extensions.rb"
+ open(@file, 'a') { |f|
+ f.puts exist_str
+ }
+ end
+ all_command = "#{command1} && cd #{ENV['PWD']} && #{command2} ; #{command3} ; kill -s TERM `cat tmp/pids/unicorn.pid` ; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now"
a = Thread.start do
Bundler.with_clean_env do
puts ENV['PWD']
@@ -86,7 +97,7 @@ if old_gemfile_text != new_gemfile_text
end
now_priority = Thread.current.priority.to_i
system('sleep 2')
- a.priority = now_priority + 2
+ a.priority = now_priority + 2
a.run
#Thread.exit
end
diff --git a/temp_file/Gemfile b/temp_file/Gemfile
index 7c6f1ea..bc1ed2d 100644
--- a/temp_file/Gemfile
+++ b/temp_file/Gemfile
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
-#test!!!!!!!!
+#test1!!!!!!!!
#social gems
gem "omniauth-google-oauth2"
diff --git a/temp_file/app/controllers/admin/sites_controller.rb b/temp_file/app/controllers/admin/sites_controller.rb
new file mode 100644
index 0000000..a876c45
--- /dev/null
+++ b/temp_file/app/controllers/admin/sites_controller.rb
@@ -0,0 +1,223 @@
+class Admin::SitesController < OrbitAdminController
+ before_filter :get_site
+ before_filter :set_git_branch, :only=>[:check_updates, :update_orbit]
+ before_action :create_page_set
+ def create_page_set
+ @site = @current_site.nil? ? Site.first : @current_site
+ if( @site.page_sets.count==0 rescue false)
+ @site.page_sets.create()
+ elsif @site.page_sets.count>1
+ @site.page_sets.each_with_index do |i,v|
+ if i!=0
+ v.delete
+ end
+ end
+ end
+ end
+ layout "structure"
+ def send_email
+ params_to_send = {'store_token' => current_site.store_token}
+ uri = URI.parse(OrbitStore::URL)
+ http = Net::HTTP.new(uri.host,uri.port)
+ request = Net::HTTP::Get.new("/site/send_email")
+ request.body = params_to_send.to_query
+ response = http.request(request)
+ data = JSON.parse(response.body)
+ %x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
+ sleep 5
+ end
+ def index
+ @first_run = dashboard_is_first_run?
+ @registered = !@site.store_token.nil?
+ @store_permissions = check_store_permissions
+ if @store_permissions["error"] == "SITE_NOT_REGISTERED"
+ if @registered
+ @registered = false
+ @site.store_token = nil
+ @site.save
+ end
+ end
+ if @registered
+ network = ONetwork.new(OrbitStore::URL,"get")
+ response = network.request("/xhr/ticket/types",{"store_token" => @site.store_token})
+ data = JSON.parse(response.body) rescue {}
+ @types = []
+ locale = I18n.locale.to_s
+ if data["success"] == true
+ data["ticket_types"].each do |tt|
+ @types << [tt["title_translations"][locale],tt["id"]]
+ end
+ end
+ send_email if !@store_permissions["permission_granted"] rescue nil #Resend confirmation email if not confirmed
+ end
+ user_name = current_user.user_name rescue ''
+ network = ONetwork.new(OrbitStore::URL,"post")
+ response = network.request("/xhr/site/re_register_url",{"store_token" => current_site.store_token, 'site_domain' => request.host_with_port,'user' => user_name})
+ @data = JSON.parse(response.body) rescue {}
+ end
+
+
+ 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","
").html_safe
+ @nginx_version = %x[/usr/sbin/nginx -v 2>&1].gsub("\n","
").html_safe
+ @mongo_version = `mongod --version`.split("\n")[0].html_safe
+ @linux_version = `lsb_release -d`.split(":")[1].html_safe rescue "Not Applicable"
+
+ @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[:mail_log_page]).per(10)
+
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ end
+
+ def delete_mail_log
+ if params[:ids]
+ EmailLog.any_in(:_id => params[:ids]).destroy
+ end
+ render :nothing => true
+ end
+
+ def preference
+ 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
+ if !@site.in_use_locales.include?I18n.locale
+ I18n.locale = @site.in_use_locales.first
+ redirect_to admin_site_preference_path(current_site)
+ else
+ redirect_to :back
+ end
+ %x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
+ sleep 5
+ end
+
+ def update_manager
+ @store_permissions = check_store_permissions
+ 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
+ store_permissions = check_store_permissions
+ if store_permissions["permission_granted"]
+ 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})
+ %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 update` }
+ end
+
+ render :text => result
+ else
+ render :json => store_permissions.to_json
+ end
+ end
+
+ def bundle_install
+ Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=built_in_extensions.rb bundle update && bundle` }
+ Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=downloaded_extensions.rb bundle update && bundle` }
+ %x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
+ sleep 5
+ render :nothing => true
+ end
+
+ def restart_server
+ %x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
+ sleep 5
+ render :nothing => true
+ end
+
+ private
+ def get_site
+ @site = @current_site.nil? ? Site.first : @current_site
+ end
+
+ def dashboard_is_first_run?
+ !current_user.is_tour_completed?("tickets")
+ 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[:site][:sign_up_roles] = [] if !params[:site][:sign_up_roles].present?
+ params.require(:site).permit!
+
+ end
+
+
+ def set_git_branch
+ @branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","")
+ end
+end
diff --git a/temp_file/app/models/page_set.rb b/temp_file/app/models/page_set.rb
new file mode 100644
index 0000000..4b3de87
--- /dev/null
+++ b/temp_file/app/models/page_set.rb
@@ -0,0 +1,6 @@
+class PageSet
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ belongs_to :site
+ field :auto_convert_flag, type: Boolean, :default => false
+end
\ No newline at end of file
diff --git a/temp_file/app/models/site.rb b/temp_file/app/models/site.rb
new file mode 100644
index 0000000..a842953
--- /dev/null
+++ b/temp_file/app/models/site.rb
@@ -0,0 +1,108 @@
+class Site
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Slug
+
+ DEBUG = false
+ has_many :page_sets, :autosave => true, :dependent => :destroy
+ accepts_nested_attributes_for :page_sets, :allow_destroy => true
+ field :title, as: :slug_title, type: String, localize: true
+ field :school, type: String
+ field :department, type: String
+ field :address, type: String
+ field :footer, localize: true
+ field :social_share, type: String
+ field :sub_menu, localize: true
+ field :site_type
+ field :site_map_link, type: String, :default => "/sitemap"
+ field :terms_of_use_link, type: String
+ field :google_analytics, type: String
+ field :in_use_locales, :type => Array
+ field :valid_locales, :type => Array
+ field :site_active, :type => Boolean
+ field :frontend_open, :type => Boolean, :default => true
+ field :backend_openness_on, :type => Boolean, :default => false
+ field :mobile_api_openness_on, :type => Boolean, :default => false
+ field :desktop_closed, :type => Boolean, :default => false
+ field :enable_language_detection, :type => Boolean, :default => false
+ field :enable_redirect_index, :type => Boolean, :default => true
+ field :enable_zh_cn, :type => Boolean, :default => true
+ field :enable_language_options, :type => Boolean, :default => true
+ field :default_locale, :default => "zh_tw"
+ field :mobile_on, :type => Boolean, :default => false
+ field :announcement_category, :type => Array, :default=>[]
+ field :mobile_bar_color, :type => Array, :default=>[]
+ field :phone_number, :type => Array,:default=>[]
+ field :title_always_on, :type => Boolean, :default => false
+ field :display_title_in_frontend, :type => Boolean, :default => true
+ field :sitemap_menu_in_header, :type => Boolean, :default => false
+ field :enable_terms_of_use, :type => Boolean, :default => false
+ field :search,:type => Hash
+ field :site_settings
+ field :template, type: String
+ field :store_token
+ field :enable_last_update, type: Boolean, :default => false
+ field :personal_plugins_sort, type: Array, :default => []
+ field :sign_up_roles, type: Array, :default => []
+
+ field :mobile_orbit_bar_title, localize: true
+ field :google_oauth_enabled, :type => Boolean, :default => false
+ field :google_client_id
+ field :google_client_secret
+ field :meta_tags
+ field :every_page_sharer, type: Array, :default => ["facebook","twitter","google","printer"]
+
+ field :sync_enabled, type: Boolean, :default => false
+ field :sync_rake_task
+
+ field :month_traffic_cache
+ field :home_link, :type => String, :default=>"/"
+ field :home_link_1, :type => String, :default=>"/"
+ field :site_title, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"}
+ field :site_title_1, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"}
+ field :is_hidden_orbit_bar , type: Boolean, :default => false
+ field :orbit_bar_background_color , type: String, :default => ""
+ field :orbit_bar_text_color , type: String, :default => ""
+ field :orbit_bar_submenu_background_color , type: String, :default => ""
+ field :orbit_bar_submenu_text_color , type: String, :default => ""
+ field :orbit_bar_animation_time , type: String, :default => "0.3s"
+ mount_uploader :default_image, ImageUploader
+ mount_uploader :site_logo, ImageUploader
+ mount_uploader :site_logo_1, ImageUploader
+ mount_uploader :favicon, ImageUploader
+ mount_uploader :mobile_icon, ImageUploader
+ after_initialize do
+ if !self.new_record?
+ if self.is_hidden_orbit_bar.nil?
+ self.is_hidden_orbit_bar = false
+ self.save
+ end
+ if self.orbit_bar_background_color.nil?
+ self.orbit_bar_background_color = ""
+ self.save
+ end
+ if self.orbit_bar_text_color.nil?
+ self.orbit_bar_text_color = ""
+ self.save
+ end
+ if self.orbit_bar_submenu_background_color.nil?
+ self.orbit_bar_submenu_background_color = ""
+ self.save
+ end
+ if self.orbit_bar_submenu_text_color.nil?
+ self.orbit_bar_submenu_text_color = ""
+ self.save
+ end
+ if self.orbit_bar_animation_time.nil?
+ self.orbit_bar_animation_time = "0.3s"
+ self.save
+ end
+ end
+ end
+ def register_site(url,university,department,email,country)
+ api_key = STORE_CONFIG[:store_settings]["api_key"]
+ self.generate_site_token
+ store = Store.new(self.id.to_s,self.site_token,api_key)
+ store.post_client(self.id.to_s,self.site_token,self.title,url,university,department,email,country)
+ end
+end
diff --git a/temp_file/app/views/admin/sites/_notifications.html.erb b/temp_file/app/views/admin/sites/_notifications.html.erb
new file mode 100644
index 0000000..1a904c9
--- /dev/null
+++ b/temp_file/app/views/admin/sites/_notifications.html.erb
@@ -0,0 +1,54 @@
+
+
+
+
+<% @data['site_anncs'].each_with_index do |v,i| %>
+
<%= v['title'][I18n.locale.to_s].to_s.html_safe %> | +