lib/fiona7/engine.rb in infopark_fiona7-0.30.0.2 vs lib/fiona7/engine.rb in infopark_fiona7-0.70.0.1
- old
+ new
@@ -13,33 +13,60 @@
#require "rails_connector/fiona_engine"
require "infopark_reactor"
require "fiona7/mode_switch"
require "fiona7/scrivito_patches/attribute_content"
+require "fiona7/scrivito_patches/attribute_serializer"
require "fiona7/scrivito_patches/basic_obj"
require "fiona7/scrivito_patches/basic_widget"
require "fiona7/scrivito_patches/binary"
-require "fiona7/scrivito_patches/client_config"
+require "fiona7/scrivito_patches/cms_backend"
+require "fiona7/scrivito_patches/cms_field_tag"
require "fiona7/scrivito_patches/controller_actions"
-require "fiona7/scrivito_patches/cms_dispatch_controller"
+# different load order !!
+#require "fiona7/scrivito_patches/cms_dispatch_controller"
require "fiona7/scrivito_patches/cms_rest_api"
require "fiona7/scrivito_patches/cms_routing"
require "fiona7/scrivito_patches/link_parser"
-require "fiona7/scrivito_patches/obj_class"
require "fiona7/scrivito_patches/migrator"
require "fiona7/scrivito_patches/type_computer"
require "fiona7/scrivito_patches/workspace"
+require "fiona7/middleware/table_switching_middleware"
+require "fiona7/middleware/server_detection_middleware"
+module Scrivito
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ def backend_request(event)
+ self.class.runtime += event.duration
+ return unless logger.debug?
+
+ duration = '(%.1fms)' % [event.duration]
+
+ param = event.payload[:params]
+ param_text = " #{param}" if param
+
+ verb_text = event.payload[:verb].upcase
+ path_text = event.payload[:path]
+
+ debug " Fiona7 #{verb_text} #{path_text}#{param_text} #{duration}"
+ end
+ end
+end
+
+
require "fiona7/routers/content_service"
require "fiona7/routers/rest_api"
require 'fiona7/scrivito_user'
+require 'fiona7/type_synchronizer'
+
module Fiona7
mattr_accessor :mode
mattr_accessor :login
+ mattr_accessor :root
class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode)
end
def self.configure(&block)
@@ -52,10 +79,12 @@
id: 'f7',
username: config.username,
secret: config.secret
}
+ Fiona7.root = config.username
+
Fiona7.mode = config.mode
if Fiona7.login = !config.root_mode
Scrivito.configure do |config|
config.editing_auth do |env|
request = ActionDispatch::Request.new(env)
@@ -82,10 +111,17 @@
end
end
class Engine < ::Rails::Engine
+ config.to_prepare do
+ # TODO: do some smart optimizations
+ require "fiona7/initializer"
+ initializer = Fiona7::Initializer.new
+ initializer.initialize_system
+ end
+
initializer "fiona7.mode_switch" do |app|
mode = nil
if Fiona7.mode == :standalone
mode = :standalone
@@ -93,10 +129,14 @@
mode = :legacy
else
raise "Invalid mode: #{Fiona7.mode}. Valid modes are :legacy and :standalone. Please refer to the documentation for more information"
end
+ # delayed init, patching sooner breaks AR
+ # later and it breaks Obj
+ require "fiona7/fiona_connector_patches/basic_obj"
+
ModeSwitch::Composite.new(app).public_send(mode)
end
initializer "fiona7.remove_scrivito_deprecations" do |app|
{
@@ -113,26 +153,37 @@
ScrivitoHelper.send(:remove_method, old_method_name) if ScrivitoHelper.method_defined?(old_method_name)
end
end
initializer "fiona7.authorize_reactor" do |app|
+
ActionController::Base.__send__(:define_method, :rsession_auth) do
if !Fiona7.login
- rsession.user_name = 'root' unless rsession.user_name == 'root'
+ rsession.user_name = Fiona7.root unless rsession.user_name == Fiona7.root
end
end
end
initializer "fiona7.patch_assets" do |app|
- app.config.assets.precompile += %w(fiona7.css fiona7.js fiona7-login.css)
+ app.config.assets.precompile += %w(fiona7_ui.css fiona7_ui.js fiona7.css fiona7.js fiona7-login.css)
end
initializer "fiona7.runtime_patches" do |app|
- # delayed init, patching sooner breaks AR
- require "fiona7/fiona_connector_patches/basic_obj"
+ require "fiona7/scrivito_patches/cms_dispatch_controller"
+ require "fiona7/scrivito_patches/webservice_controller"
+ require "fiona7/scrivito_patches/objs_controller"
end
+ 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
# 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"
end
end