announcement-test/temp_file/config/set_global_variable.rb

111 lines
4.7 KiB
Ruby
Raw Normal View History

2022-05-29 04:59:54 +00:00
$:.push File.expand_path("../..", __FILE__)
require 'bundler'
require 'config/boot'
2022-09-08 12:01:09 +00:00
require 'rails'
built_in_ext_lines = File.readlines('built_in_extensions.rb').map{|s| s.split("#")[0].to_s} rescue []
downloaded_ext_lines = File.readlines('downloaded_extensions.rb').map{|s| s.split("#")[0].to_s} rescue []
extras_ext_lines = File.readlines('extra_gems.rb').map{|s| s.split("#")[0].to_s} rescue []
orbit_ext_lines = (built_in_ext_lines + downloaded_ext_lines + extras_ext_lines)
orbit_ext_gems = orbit_ext_lines.map{|l| l.match(/gem\s+['"](\w+)['"]/)[1] rescue nil}.select{|s| s.present?}.uniq
orbit_gem_specs = Gem::Specification.find_all.select{|g| orbit_ext_gems.include?(g.name) & (g.source.class != Bundler::Source::Rubygems)}
Thread.current[:dependency_gems] = orbit_gem_specs.flat_map{|spec| spec.dependent_specs.map{|s| s.name}}.uniq
orbit_gems_paths = orbit_gem_specs.map{|gem| gem.full_gem_path}
orbit_ext_gems_models_paths = orbit_gems_paths.map{|d| Dir.glob("#{d}/app/models/*")}
orbit_models_categorized = orbit_ext_gems_models_paths.map.with_index do |models_paths,i|
gem_name = orbit_gem_specs[i].name
categorized = models_paths.select{|fn| File.read(fn).include?("OrbitCategory::Categorizable") rescue false}.map{|fn| File.basename(fn).split(".")[0].classify}
[gem_name, categorized]
end.to_h
orbit_ext_gems_models = orbit_ext_gems_models_paths.flatten.map{|fn| File.basename(fn).split(".")[0].classify}
2022-05-29 04:59:54 +00:00
2022-09-08 12:01:09 +00:00
File.open("orbit_ext_gems_tmp.txt","w+"){|f| f.write(orbit_ext_gems.to_json)}
File.open("orbit_ext_gems_models_tmp.txt","w+"){|f| f.write(orbit_ext_gems_models.to_json)}
File.open("orbit_categorized_tmp.txt","w+"){|f| f.write(orbit_models_categorized.to_json)}
require "config/application"
2022-05-29 04:59:54 +00:00
require 'lib/orbit_category/categorizable'
require 'lib/orbit_tag/taggable'
require 'lib/orbit_model/impression'
require 'lib/orbit_model/status'
require "mongoid"
require "kaminari/mongoid"
require "mongoid/railtie"
require 'carrierwave/mongoid'
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require "bson"
require 'app/models/concerns/slug'
require 'app/uploaders/image_uploader'
require 'app/models/tag'
require 'app/models/category'
Mongoid.load!("config/mongoid.yml")
2023-09-05 14:56:46 +00:00
# require 'impressionist'
orm = 'mongoid'
2024-02-24 06:54:42 +00:00
require "impressionist/../../app/models/impressionist/impressionable.rb"
2023-09-05 14:56:46 +00:00
require "impressionist/models/#{orm}/impression.rb"
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
2022-05-29 04:59:54 +00:00
require 'app/models/site'
require 'app/models/page_set' #need for site save
if Site.count == 0
site = Site.new
extra_trans = {}
extra_langs = File.read('config/extra_lang.txt').scan(/.*extra_.*/).select{|v| v.exclude? '#'}[0].to_s.split(/extra_language.*:|,| /).select{|v| !v.empty?}.map{|v| v.to_sym} rescue []
extra_langs.each do |extra_lang|
extra_trans[extra_lang] = 'orbit'
end
site.title_translations = {:en=>"Orbit",:zh_tw=>"Orbit"}.merge(extra_trans)
site.valid_locales = [:en, :zh_tw] + extra_langs
site.in_use_locales = site.valid_locales
site.site_type = "orbit"
2022-08-30 03:29:55 +00:00
site.template = (Dir.glob("#{ENV['PWD']}/app/templates/*").collect{|temp| temp.split('/').last}-['mobile']).first
2024-02-24 06:54:42 +00:00
site.update_flag = false
2022-05-29 04:59:54 +00:00
site.save
end
begin
2023-09-05 14:56:46 +00:00
require 'config/process_share_wrapper'
2022-05-29 04:59:54 +00:00
@mutex = ProcessShared::Mutex.new
@shared_hash = {}
orbit_gem_specs.each do |v|
v.metadata['_require'].to_s.split(',').each{|m| require(m)}
tmp = v.metadata['global_hash']
tmp = tmp ? eval(tmp) : nil
gem_name = v.name
if tmp
2023-09-05 14:56:46 +00:00
@shared_hash[gem_name] = ProcessShareWrapper.new(tmp)
2022-05-29 04:59:54 +00:00
end
end
2022-08-03 04:51:25 +00:00
s = Site.first
2023-09-05 14:56:46 +00:00
@shared_hash['current_site'] = ProcessShareWrapper.new({"site"=> s})
@shared_hash['privileged_page_count'] = ProcessShareWrapper.new((s.privileged_page_count rescue 0))
2022-05-29 04:59:54 +00:00
Thread.current[:shared_hash] = @shared_hash
Thread.current[:shared_mutex] = @mutex
rescue LoadError => e
2023-09-05 14:56:46 +00:00
env_pwd = ENV['PWD']
begin
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
include BundlerHelper
rescue LoadError
def bundler_with_clean_env(&block)
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&block)
else
Bundler.with_clean_env(&block)
end
end
end
end
reset_paths = ["config/application.rb", "config/unicorn.rb", "config/set_global_variable.rb", "config/process_share_wrapper.rb", "lib/orbit_app", "lib/orbit_core_lib.rb"]
all_command = reset_paths.map do |reset_path|
"git clean -f -- #{reset_path} && git reset origin -- #{reset_path} && git checkout -- #{reset_path}"
end.join('&&')
bundler_with_clean_env do
system("cd #{env_pwd} && #{all_command}")
end
2022-05-29 04:59:54 +00:00
puts ['error in unicorn',e,e.backtrace]
end