From d6103681e70aa8657421024318d5a673a72d7a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 17 Dec 2024 13:24:42 +0100 Subject: [PATCH] Zeitwerk --- after_init.rb | 26 ++-- app/controllers/dmsf_controller.rb | 4 +- app/helpers/dmsf_helper.rb | 2 +- app/views/dmsf/_main.html.erb | 2 +- app/views/dmsf/trash.html.erb | 2 +- config/routes.rb | 2 +- {app/models => lib}/easy_page_module.rb | 0 lib/redmine_dmsf.rb | 112 ++++++++++-------- .../access_control_patch.rb | 8 +- .../patches => patches}/attachable_patch.rb | 2 +- .../patches => patches}/custom_field_patch.rb | 2 +- .../easy_crm_case_patch.rb | 0 .../easy_crm_cases_controller_patch.rb | 1 + .../formatting_helper_patch.rb | 0 .../patches => patches}/issue_patch.rb | 2 +- .../patches => patches}/notifiable_patch.rb | 6 +- .../notifiable_ru_patch.rb | 4 +- .../patches => patches}/pdf_patch.rb | 2 +- .../patches => patches}/project_patch.rb | 2 +- .../projects_helper_patch.rb | 4 +- .../queries_controller_patch.rb | 2 +- .../patches => patches}/role_patch.rb | 2 +- .../patches => patches}/search_patch.rb | 6 +- .../patches => patches}/user_patch.rb | 2 +- .../user_preference_patch.rb | 2 +- 25 files changed, 105 insertions(+), 92 deletions(-) rename {app/models => lib}/easy_page_module.rb (100%) rename {lib/redmine_dmsf/patches => patches}/access_control_patch.rb (92%) rename {lib/redmine_dmsf/patches => patches}/attachable_patch.rb (96%) rename {lib/redmine_dmsf/patches => patches}/custom_field_patch.rb (96%) rename {lib/redmine_dmsf/patches => patches}/easy_crm_case_patch.rb (100%) rename {lib/redmine_dmsf/patches => patches}/easy_crm_cases_controller_patch.rb (99%) rename {lib/redmine_dmsf/patches => patches}/formatting_helper_patch.rb (100%) rename {lib/redmine_dmsf/patches => patches}/issue_patch.rb (99%) rename {lib/redmine_dmsf/patches => patches}/notifiable_patch.rb (91%) rename {lib/redmine_dmsf/patches => patches}/notifiable_ru_patch.rb (90%) rename {lib/redmine_dmsf/patches => patches}/pdf_patch.rb (97%) rename {lib/redmine_dmsf/patches => patches}/project_patch.rb (99%) rename {lib/redmine_dmsf/patches => patches}/projects_helper_patch.rb (93%) rename {lib/redmine_dmsf/patches => patches}/queries_controller_patch.rb (97%) rename {lib/redmine_dmsf/patches => patches}/role_patch.rb (97%) rename {lib/redmine_dmsf/patches => patches}/search_patch.rb (93%) rename {lib/redmine_dmsf/patches => patches}/user_patch.rb (98%) rename {lib/redmine_dmsf/patches => patches}/user_preference_patch.rb (97%) diff --git a/after_init.rb b/after_init.rb index 5535ed1a..88d6a3b9 100644 --- a/after_init.rb +++ b/after_init.rb @@ -39,7 +39,7 @@ def dmsf_init param: :id, html: { class: 'icon icon-dmsf' } # New menu extension - next if Redmine::Plugin.installed?('easy_extensions') + next if defined?(EasyExtensions) menu.push :dmsf_file, { controller: 'dmsf_upload', action: 'multi_upload' }, caption: :label_dmsf_new_top_level_document, parent: :new_object @@ -112,7 +112,7 @@ def dmsf_init Token.add_action :dmsf_webdav_digest, max_instances: 1, validity_time: nil end -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyExtensions) Rails.application.config.after_initialize do dmsf_init @@ -130,20 +130,26 @@ Rails.application.configure do Zip.unicode_names = true # DMS custom fields - CustomFieldsHelper::CUSTOM_FIELDS_TABS << { name: 'DmsfFileRevisionCustomField', partial: 'custom_fields/index', - label: :dmsf } + after_easy_init do + CustomFieldsHelper::CUSTOM_FIELDS_TABS << { name: 'DmsfFileRevisionCustomField', partial: 'custom_fields/index', + label: :dmsf } + end # Searchable modules - Redmine::Search.map do |search| - search.register :dmsf_files - search.register :dmsf_folders + after_easy_init do + Redmine::Search.map do |search| + search.register :dmsf_files + search.register :dmsf_folders + end end # Activities - Redmine::Activity.register :dmsf_file_revision_accesses, default: false - Redmine::Activity.register :dmsf_file_revisions + after_easy_init do + Redmine::Activity.register :dmsf_file_revision_accesses, default: false + Redmine::Activity.register :dmsf_file_revisions + end - if Redmine::Plugin.installed?('easy_extensions') + if defined?(EasyExtensions) require "#{File.dirname(__FILE__)}/lib/redmine_dmsf/webdav/custom_middleware" config.middleware.insert_before ActionDispatch::Cookies, RedmineDmsf::Webdav::CustomMiddleware end diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 9dabb3a3..f6b74980 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -18,6 +18,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require "#{File.dirname(__FILE__)}/../../lib/redmine_dmsf/dmsf_zip" + # DMSF controller class DmsfController < ApplicationController include RedmineDmsf::DmsfZip @@ -751,7 +753,7 @@ class DmsfController < ApplicationController def query retrieve_default_query true - @query = if Redmine::Plugin.installed?('easy_extensions') + @query = if defined?(EasyExtensions) retrieve_query_without_easy_extensions DmsfQuery, true else retrieve_query DmsfQuery, true diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index 68196e59..603911e7 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -25,7 +25,7 @@ require 'csv' module DmsfHelper include Redmine::I18n - unless Redmine::Plugin.installed?('easy_extensions') + unless defined?(EasyExtensions) def late_javascript_tag(content_or_options_with_block = nil, html_options = {}, &block) javascript_tag content_or_options_with_block, html_options, &block diff --git a/app/views/dmsf/_main.html.erb b/app/views/dmsf/_main.html.erb index ebc8030c..fe2742d0 100644 --- a/app/views/dmsf/_main.html.erb +++ b/app/views/dmsf/_main.html.erb @@ -104,7 +104,7 @@ <% end %> <% end %> -<% if Redmine::Plugin.installed?('easy_extensions') %> +<% if defined?(EasyExtensions) %> <%= late_javascript_tag do %> $(function() { $("p.buttons").addClass("filter-buttons form-actions"); diff --git a/app/views/dmsf/trash.html.erb b/app/views/dmsf/trash.html.erb index fd051282..5b523762 100644 --- a/app/views/dmsf/trash.html.erb +++ b/app/views/dmsf/trash.html.erb @@ -42,7 +42,7 @@ <%= render partial: 'dmsf/sidebar' %> <% end %> -<% if Redmine::Plugin.installed?('easy_extensions') %> +<% if defined?(EasyExtensions) %> <%= late_javascript_tag do %> $(function() { $("p.buttons").addClass("filter-buttons form-actions"); diff --git a/config/routes.rb b/config/routes.rb index 11795207..2b1870f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,7 +169,7 @@ if Redmine::Plugin.installed? 'redmine_dmsf' end # WebDAV workaround for clients checking WebDAV availability in the root - unless Redmine::Plugin.installed?('easy_extensions') + unless defined?(EasyExtensions) match '/', to: ->(env) { [405, {}, ["#{env['REQUEST_METHOD']} method is not allowed"]] }, via: %i[propfind options] diff --git a/app/models/easy_page_module.rb b/lib/easy_page_module.rb similarity index 100% rename from app/models/easy_page_module.rb rename to lib/easy_page_module.rb diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 4b98ef65..bfa2c113 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -199,63 +199,69 @@ end # DMSF libraries -# Validators -require "#{File.dirname(__FILE__)}/../app/validators/dmsf_file_name_validator" -require "#{File.dirname(__FILE__)}/../app/validators/dmsf_max_file_size_validator" -require "#{File.dirname(__FILE__)}/../app/validators/dmsf_workflow_name_validator" -require "#{File.dirname(__FILE__)}/../app/validators/dmsf_url_validator" -require "#{File.dirname(__FILE__)}/../app/validators/dmsf_folder_parent_validator" - -# Plugin's patches -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/formatting_helper_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/projects_helper_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/project_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/user_preference_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/user_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/issue_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/role_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/queries_controller_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/pdf_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/access_control_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/search_patch" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/custom_field_patch" - -# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins -def require_notifiable - if defined?(EasyExtensions) || RedmineDmsf::Plugin.an_obsolete_plugin_present? - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/notifiable_ru_patch" +def after_easy_init(&block) + if defined?(EasyExtensions) + Rails.application.config.after_initialize(&block) else - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/notifiable_patch" + yield end end -if defined?(EasyExtensions) - Rails.application.config.to_prepare { require_notifiable } -else - require_notifiable +# Validators +after_easy_init do + require "#{File.dirname(__FILE__)}/../app/validators/dmsf_file_name_validator" + require "#{File.dirname(__FILE__)}/../app/validators/dmsf_max_file_size_validator" + require "#{File.dirname(__FILE__)}/../app/validators/dmsf_workflow_name_validator" + require "#{File.dirname(__FILE__)}/../app/validators/dmsf_url_validator" + require "#{File.dirname(__FILE__)}/../app/validators/dmsf_folder_parent_validator" end -if defined?(EasyExtensions) - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/easy_crm_case_patch" - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/attachable_patch" - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb" +# Patches +unless defined?(EasyPatchManager) + require "#{File.dirname(__FILE__)}/../patches/formatting_helper_patch" + require "#{File.dirname(__FILE__)}/../patches/projects_helper_patch" + require "#{File.dirname(__FILE__)}/../patches/project_patch" + require "#{File.dirname(__FILE__)}/../patches/user_preference_patch" + require "#{File.dirname(__FILE__)}/../patches/user_patch" + require "#{File.dirname(__FILE__)}/../patches/issue_patch" + require "#{File.dirname(__FILE__)}/../patches/role_patch" + require "#{File.dirname(__FILE__)}/../patches/queries_controller_patch" + require "#{File.dirname(__FILE__)}/../patches/pdf_patch" + require "#{File.dirname(__FILE__)}/../patches/access_control_patch" + require "#{File.dirname(__FILE__)}/../patches/search_patch" + require "#{File.dirname(__FILE__)}/../patches/custom_field_patch" + # A workaround for obsolete 'alias_method' usage in RedmineUp's plugins + if RedmineDmsf::Plugin.an_obsolete_plugin_present? + require "#{File.dirname(__FILE__)}/../patches/notifiable_ru_patch" + else + require "#{File.dirname(__FILE__)}/../patches/notifiable_patch" + end +end + +# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins +after_easy_init do + require "#{File.dirname(__FILE__)}/redmine_dmsf/plugin" end # Load up classes that make up our WebDAV solution ontop of Dav4rack -require "#{File.dirname(__FILE__)}/dav4rack" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/custom_middleware" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/base_resource" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/dmsf_resource" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/index_resource" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/project_resource" -require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/resource_proxy" +after_easy_init do + require "#{File.dirname(__FILE__)}/dav4rack" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/custom_middleware" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/base_resource" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/dmsf_resource" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/index_resource" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/project_resource" + require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/resource_proxy" +end # Errors -require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_access_error" -require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_email_max_file_size_error" -require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_file_not_found_error" -require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_lock_error" -require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_zip_max_files_error" +after_easy_init do + require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_access_error" + require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_email_max_file_size_error" + require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_file_not_found_error" + require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_lock_error" + require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_zip_max_files_error" +end # Hooks def require_hooks @@ -274,14 +280,18 @@ def require_hooks require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/project_helper_hooks" end -if defined?(EasyExtensions) - Rails.application.config.to_prepare { require_hooks } -else +after_easy_init do require_hooks end # Macros -require "#{File.dirname(__FILE__)}/redmine_dmsf/macros" +after_easy_init do + require "#{File.dirname(__FILE__)}/redmine_dmsf/macros" +end # Field formats -require "#{File.dirname(__FILE__)}/redmine_dmsf/field_formats/dmsf_file_revision_format" +after_easy_init do + require "#{File.dirname(__FILE__)}/redmine_dmsf/field_formats/dmsf_file_revision_format" +end + +require "#{File.dirname(__FILE__)}/easy_page_module" unless defined?(EasyExtensions) diff --git a/lib/redmine_dmsf/patches/access_control_patch.rb b/patches/access_control_patch.rb similarity index 92% rename from lib/redmine_dmsf/patches/access_control_patch.rb rename to patches/access_control_patch.rb index 5eb019bb..c9c5fa64 100644 --- a/lib/redmine_dmsf/patches/access_control_patch.rb +++ b/patches/access_control_patch.rb @@ -20,14 +20,12 @@ module RedmineDmsf module Patches - # AccessControll patch + # AccessControl patch module AccessControlPatch ################################################################################################################## # Overridden methods def self.prepended(base) - class << base - prepend ClassMethods - end + base.singleton_class.prepend(ClassMethods) end # Class methods @@ -46,7 +44,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_patch_to_be_first 'Redmine::Acts::Attachable::InstanceMethods', 'RedmineDmsf::Patches::AccessControlPatch', prepend: true, first: true else diff --git a/lib/redmine_dmsf/patches/attachable_patch.rb b/patches/attachable_patch.rb similarity index 96% rename from lib/redmine_dmsf/patches/attachable_patch.rb rename to patches/attachable_patch.rb index bf0b5cb7..2c7a2bd7 100644 --- a/lib/redmine_dmsf/patches/attachable_patch.rb +++ b/patches/attachable_patch.rb @@ -33,7 +33,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_patch_to_be_first 'Redmine::Acts::Attachable::InstanceMethods', 'RedmineDmsf::Patches::AttachablePatch', prepend: true, first: true else diff --git a/lib/redmine_dmsf/patches/custom_field_patch.rb b/patches/custom_field_patch.rb similarity index 96% rename from lib/redmine_dmsf/patches/custom_field_patch.rb rename to patches/custom_field_patch.rb index 7db19969..d4a5d423 100644 --- a/lib/redmine_dmsf/patches/custom_field_patch.rb +++ b/patches/custom_field_patch.rb @@ -32,7 +32,7 @@ module RedmineDmsf end # Apply patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'CustomField', 'RedmineDmsf::Patches::CustomFieldPatch' else CustomField.include RedmineDmsf::Patches::CustomFieldPatch diff --git a/lib/redmine_dmsf/patches/easy_crm_case_patch.rb b/patches/easy_crm_case_patch.rb similarity index 100% rename from lib/redmine_dmsf/patches/easy_crm_case_patch.rb rename to patches/easy_crm_case_patch.rb diff --git a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb b/patches/easy_crm_cases_controller_patch.rb similarity index 99% rename from lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb rename to patches/easy_crm_cases_controller_patch.rb index fb14ff2f..8179582d 100644 --- a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb +++ b/patches/easy_crm_cases_controller_patch.rb @@ -32,6 +32,7 @@ module RedmineDmsf easy_crm_cases.each do |easy_crm_case| # Attach DMS documents uploaded_files = params[:dmsf_attachments] + details = params[:committed_files] if uploaded_files system_folder = easy_crm_case.system_folder(create: true) uploaded_files.each do |key, uploaded_file| diff --git a/lib/redmine_dmsf/patches/formatting_helper_patch.rb b/patches/formatting_helper_patch.rb similarity index 100% rename from lib/redmine_dmsf/patches/formatting_helper_patch.rb rename to patches/formatting_helper_patch.rb diff --git a/lib/redmine_dmsf/patches/issue_patch.rb b/patches/issue_patch.rb similarity index 99% rename from lib/redmine_dmsf/patches/issue_patch.rb rename to patches/issue_patch.rb index b8997b8c..89967aaf 100644 --- a/lib/redmine_dmsf/patches/issue_patch.rb +++ b/patches/issue_patch.rb @@ -163,7 +163,7 @@ module RedmineDmsf end # Apply patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'Issue', 'RedmineDmsf::Patches::IssuePatch' else Issue.prepend RedmineDmsf::Patches::IssuePatch diff --git a/lib/redmine_dmsf/patches/notifiable_patch.rb b/patches/notifiable_patch.rb similarity index 91% rename from lib/redmine_dmsf/patches/notifiable_patch.rb rename to patches/notifiable_patch.rb index 42e6d6ec..fbc7fa96 100644 --- a/lib/redmine_dmsf/patches/notifiable_patch.rb +++ b/patches/notifiable_patch.rb @@ -23,9 +23,7 @@ module RedmineDmsf # Notifiable module NotifiablePatch def self.prepended(base) - class << base - prepend ClassMethods - end + base.singleton_class.prepend(ClassMethods) end # Class methods @@ -45,6 +43,6 @@ module RedmineDmsf end # Apply the patch -unless defined?(EasyExtensions) || RedmineDmsf::Plugin.an_obsolete_plugin_present? +unless defined?(EasyPatchManager) || RedmineDmsf::Plugin.an_obsolete_plugin_present? Redmine::Notifiable.prepend RedmineDmsf::Patches::NotifiablePatch end diff --git a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb b/patches/notifiable_ru_patch.rb similarity index 90% rename from lib/redmine_dmsf/patches/notifiable_ru_patch.rb rename to patches/notifiable_ru_patch.rb index 9d3f011f..48d65c89 100644 --- a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb +++ b/patches/notifiable_ru_patch.rb @@ -48,6 +48,8 @@ module RedmineDmsf end # Apply the patch -if defined?(EasyExtensions) || RedmineDmsf::Plugin.an_obsolete_plugin_present? +if defined?(EasyPatchManager) + EasyPatchManager.register_other_patch 'Redmine::Notifiable', 'RedmineDmsf::Patches::NotifiableRuPatch' +elsif RedmineDmsf::Plugin.an_obsolete_plugin_present? Redmine::Notifiable.include RedmineDmsf::Patches::NotifiableRuPatch end diff --git a/lib/redmine_dmsf/patches/pdf_patch.rb b/patches/pdf_patch.rb similarity index 97% rename from lib/redmine_dmsf/patches/pdf_patch.rb rename to patches/pdf_patch.rb index 98c5b3ad..5c2ed141 100644 --- a/lib/redmine_dmsf/patches/pdf_patch.rb +++ b/patches/pdf_patch.rb @@ -42,7 +42,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_patch_to_be_first 'Redmine::Export::PDF::ITCPDF', 'RedmineDmsf::Patches::PdfPatch', prepend: true, first: true else diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/patches/project_patch.rb similarity index 99% rename from lib/redmine_dmsf/patches/project_patch.rb rename to patches/project_patch.rb index 9d04a7fe..d4022c7d 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/patches/project_patch.rb @@ -133,7 +133,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'Project', 'RedmineDmsf::Patches::ProjectPatch', prepend: true else Project.prepend RedmineDmsf::Patches::ProjectPatch diff --git a/lib/redmine_dmsf/patches/projects_helper_patch.rb b/patches/projects_helper_patch.rb similarity index 93% rename from lib/redmine_dmsf/patches/projects_helper_patch.rb rename to patches/projects_helper_patch.rb index 37e9b781..7549aa2f 100644 --- a/lib/redmine_dmsf/patches/projects_helper_patch.rb +++ b/patches/projects_helper_patch.rb @@ -50,6 +50,4 @@ module RedmineDmsf end # Apply the patch -unless Redmine::Plugin.installed?('easy_extensions') - ProjectsController.send :helper, RedmineDmsf::Patches::ProjectsHelperPatch -end +ProjectsController.send(:helper, RedmineDmsf::Patches::ProjectsHelperPatch) unless defined?(EasyPatchManager) diff --git a/lib/redmine_dmsf/patches/queries_controller_patch.rb b/patches/queries_controller_patch.rb similarity index 97% rename from lib/redmine_dmsf/patches/queries_controller_patch.rb rename to patches/queries_controller_patch.rb index 0663d079..e7905bd5 100644 --- a/lib/redmine_dmsf/patches/queries_controller_patch.rb +++ b/patches/queries_controller_patch.rb @@ -39,7 +39,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_controller_patch 'QueriesController', 'RedmineDmsf::Patches::QueriesControllerPatch', prepend: true else diff --git a/lib/redmine_dmsf/patches/role_patch.rb b/patches/role_patch.rb similarity index 97% rename from lib/redmine_dmsf/patches/role_patch.rb rename to patches/role_patch.rb index 264e22d6..e7575746 100644 --- a/lib/redmine_dmsf/patches/role_patch.rb +++ b/patches/role_patch.rb @@ -42,7 +42,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'Role', 'RedmineDmsf::Patches::RolePatch', prepend: true else Role.prepend RedmineDmsf::Patches::RolePatch diff --git a/lib/redmine_dmsf/patches/search_patch.rb b/patches/search_patch.rb similarity index 93% rename from lib/redmine_dmsf/patches/search_patch.rb rename to patches/search_patch.rb index 7ed0daa7..d9593da0 100644 --- a/lib/redmine_dmsf/patches/search_patch.rb +++ b/patches/search_patch.rb @@ -25,9 +25,7 @@ module RedmineDmsf ################################################################################################################## # Overridden methods def self.prepended(base) - class << base - prepend ClassMethods - end + base.singleton_class.prepend(ClassMethods) end # Class methods @@ -46,7 +44,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_patch_to_be_first 'Redmine::Acts::Attachable::InstanceMethods', 'RedmineDmsf::Patches::SearchPatch', prepend: true, first: true else diff --git a/lib/redmine_dmsf/patches/user_patch.rb b/patches/user_patch.rb similarity index 98% rename from lib/redmine_dmsf/patches/user_patch.rb rename to patches/user_patch.rb index 466b9ad7..d8108535 100644 --- a/lib/redmine_dmsf/patches/user_patch.rb +++ b/patches/user_patch.rb @@ -63,7 +63,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'User', 'RedmineDmsf::Patches::UserPatch' else User.prepend RedmineDmsf::Patches::UserPatch diff --git a/lib/redmine_dmsf/patches/user_preference_patch.rb b/patches/user_preference_patch.rb similarity index 97% rename from lib/redmine_dmsf/patches/user_preference_patch.rb rename to patches/user_preference_patch.rb index 76915375..0da8924c 100644 --- a/lib/redmine_dmsf/patches/user_preference_patch.rb +++ b/patches/user_preference_patch.rb @@ -59,7 +59,7 @@ module RedmineDmsf end # Apply the patch -if Redmine::Plugin.installed?('easy_extensions') +if defined?(EasyPatchManager) EasyPatchManager.register_model_patch 'UserPreference', 'RedmineDmsf::Patches::UserPreferencePatch' else UserPreference.prepend RedmineDmsf::Patches::UserPreferencePatch