announcement-test/temp_file/config/environment.rb

112 lines
3.4 KiB
Ruby

# Load the Rails application.
require File.expand_path('../application', __FILE__)
require File.expand_path('../../app/helpers/orbit_helper', __FILE__)
OrbitHelper.const_set("SharedMutex",Thread.current[:shared_mutex])
OrbitHelper.const_set("SharedHash",Thread.current[:shared_hash])
# Initialize the Rails application.
Orbit::Application.initialize!
Orbit::Application.config.secret_key_base = 'acc6ffc5a7d360c9cf2a7bdb4ddf9a897942ec6767413a5c0324a0fa8b86197a96298288a66bd46d8770d8b6edf509aad65716961c2c364ce006b475e6cfd418'
site = Site.first
default_locale = (site.default_locale rescue I18n.available_locales[0]) rescue nil
if !default_locale.nil?
I18n.default_locale = default_locale
I18n.locale = default_locale
end
[MemberProfile,Page,Role,RoleStatus,AttributeValue,AttributeField,MemberProfileField,MemberProfileFieldValue,MemberProfileDefaultField,MemberRelation].each do |m|
m.class_eval{include MemberCleanCache}
end
require File.expand_path('../../app/models/page_cache_model', __FILE__) rescue nil
if (site.enable_cache rescue false)
module MongoidObs
require 'active_support/concern'
extend ActiveSupport::Concern
included do
excluded_classes = [Asset,AssetTag,Email,EmailLog,Multithread,Site,Impression,ModuleApp,OrbitMemberModule,OrbitWidget,PageCacheModel,UserAction]
excluded_classes += OrbitApp::Module::Registration.avoid_page_cache
if excluded_classes.exclude?(self)
custom_flag = false
if self == Page
def delete_page_cache
if self.changed? || self.new_record?
drop_flag = false
if self.changed != ['view_count']
if (['access_level', 'always_show_on_menu'] & self.changed).count != 0
drop_flag = true
end
end
if drop_flag
PageCacheModel.delete_all
else
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self == SubPart
def delete_page_cache
if self.changed? || self.new_record?
page = self.page_part.page rescue nil
if page
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self == PagePart
def delete_page_cache
if self.changed? || self.new_record?
page = self.page rescue nil
if page
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self.instance_methods.include?(:delete_page_cache_custom)
custom_flag = true
else
def delete_page_cache
if self.changed? || self.new_record?
PageCacheModel.delete_all
end
true #return true to save ok
end
end
if custom_flag
self.after_save :delete_page_cache_custom
else
self.after_save :delete_page_cache
end
end
end
end
module MongoidObsWrap
def included(m)
super(m)
m.include(MongoidObs)
end
end
Mongoid::Document.extend(MongoidObsWrap)
preload_models = Mongoid.models
preload_models.each{|v| v.include(MongoidObs)}
end
if Rails.env != "production"
load_models = %w(app/models/attribute_value.rb app/models/member_profile_field_value.rb)
load_models.each do |load_model|
load(load_model)
end
end
$Orbit_Categorized = JSON.parse(File.read("orbit_categorized_tmp.txt")) rescue {}
if ENV['worker_num'] == '0'
if defined?(PageCacheModel)
PageCacheModel.collection.drop
PageCacheModel.create_indexes
end
require File.expand_path('../do_on_startup', __FILE__)
end