lib/fiona7/engine.rb in infopark_fiona7-1.1.0.0.10 vs lib/fiona7/engine.rb in infopark_fiona7-1.2.0.0.0

- old
+ new

@@ -53,20 +53,52 @@ require 'fiona7/scrivito_user' require 'fiona7/type_synchronizer' + +require 'fiona7/naive_search_engine' +require 'fiona7/verity_search_engine' + module Fiona7 mattr_accessor :mode mattr_accessor :login mattr_accessor :root - class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode) + mattr_accessor :callbacks + self.callbacks = { + :create_obj => [], + :update_obj => [], + :release_obj => [] + } + + mattr_accessor :search_engine + self.search_engine = Fiona7::VeritySearchEngine + + def self.run_callbacks(callback, *params) + (self.callbacks[callback] || []).each do |callback_proc| + begin + callback_proc.call(*params) + rescue => e + Rails.logger.error("An error occured when running a callback: #{callback} with #{params.inspect}") + Rails.logger.error("#{e.class}: #{e.message}") + Rails.logger.error(e.backtrace[0,30].join("\n")) + end + end end + def self.workflows_enabled? + true + end + + class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode, :dont_yell_at_me_for_abusing_attributes) + end + + mattr_accessor :config + def self.configure(&block) - Config.new.tap do |config| + self.config = Config.new.tap do |config| yield config Reactor::Configuration.xml_access = { host: config.host, port: config.port, @@ -114,10 +146,15 @@ # TODO: do some smart optimizations initializer = Fiona7::Initializer.new initializer.initialize_system end + initializer "fiona7.add_cms_routing_paths", :after => "scrivito.add_cms_routing_paths" do |app| + precedence_route = File.expand_path("precedence_routes.rb", paths['config'].to_a.first) + app.routes_reloader.paths.unshift(precedence_route) + end + initializer "fiona7.mode_switch" do |app| mode = nil if Fiona7.mode == :standalone mode = :standalone @@ -152,10 +189,20 @@ initializer "fiona7.authorize_reactor" do |app| ActionController::Base.__send__(:define_method, :rsession_auth) do if !Fiona7.login rsession.user_name = Fiona7.root unless rsession.user_name == Fiona7.root + else + # This is interessting! We check for an existing rsession + # and if we don't find any, we destroy rsession. Why? + # Calling rsession.destroy first constructs the session + # for the current user (root most likely), which is not + # really a thing that we want - being root by default + # should only happen in the root mode + if !session[:rsession] + rsession.destroy + end end end end initializer "fiona7.patch_assets" do |app| @@ -168,11 +215,18 @@ initializer "fiona7.preload_cms_type_defs" do |app| type_register = Fiona7::TypeRegister.instance RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |_, obj_class| type_register.read_mangled(obj_class.name) end + end + + # Installs delayed, low-priority scrivito routes (primarily: permalink route) + initializer "fiona7.add_cms_routing_paths", :after => :add_routing_paths do |app| + cms_route = File.expand_path("delayed_routes.rb", paths['config'].to_a.first) + app.routes_reloader.paths.push(cms_route) end + # This ensures that reactor is loaded in the app config.after_initialize { Fiona7::WriteObj } config.app_middleware.use "Fiona7::Middleware::TableSwitchingMiddleware" config.app_middleware.use "Fiona7::Middleware::ServerDetectionMiddleware"