From eb4d86b8193072c0cf3995f97ee44ce02cdc46ea Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 15 Mar 2018 12:13:06 +0100 Subject: [PATCH] Ruby prepend replaced with prepend from RedmineExtensions --- lib/redmine_dmsf/patches/attachable_patch.rb | 3 +- .../patches/custom_fields_helper_patch.rb | 3 +- .../easy_crm_cases_controller_patch.rb | 12 +++-- lib/redmine_dmsf/patches/project_patch.rb | 44 ++++++++++--------- .../patches/project_tabs_extended.rb | 3 +- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/redmine_dmsf/patches/attachable_patch.rb b/lib/redmine_dmsf/patches/attachable_patch.rb index 86d15ec1..94e6fed4 100644 --- a/lib/redmine_dmsf/patches/attachable_patch.rb +++ b/lib/redmine_dmsf/patches/attachable_patch.rb @@ -33,4 +33,5 @@ module RedmineDmsf end end -Redmine::Acts::Attachable::InstanceMethods.send(:prepend, RedmineDmsf::Patches::AttachablePatch) +RedmineExtensions::PatchManager.register_helper_patch 'Redmine::Acts::Attachable::InstanceMethods', + 'RedmineDmsf::Patches::AttachablePatch', prepend: true diff --git a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb index 41c6d46a..71825477 100644 --- a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb +++ b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb @@ -47,4 +47,5 @@ module RedmineDmsf end end -CustomFieldsHelper.send(:prepend, RedmineDmsf::Patches::CustomFieldsHelperPatch) +RedmineExtensions::PatchManager.register_helper_patch 'CustomFieldsHelper', + 'RedmineDmsf::Patches::CustomFieldsHelperPatch', prepend: true diff --git a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb b/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb index 3894b736..186e4cbe 100644 --- a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb +++ b/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb @@ -95,7 +95,11 @@ module RedmineDmsf ################################################################################################################## # New methods - EasyCrmCasesController::before_action :controller_easy_crm_cases_before_save, only: [:create, :update, :bulk_update] + def self.prepended(base) + base.class_eval do + before_action :controller_easy_crm_cases_before_save, only: [:create, :update, :bulk_update] + end + end def controller_easy_crm_cases_before_save easy_crm_cases = @easy_crm_cases @@ -112,6 +116,6 @@ module RedmineDmsf end end -if Redmine::Plugin.installed?(:easy_crm) - EasyCrmCasesController.send(:prepend, RedmineDmsf::Patches::EasyCrmCasesControllerPatch) -end \ No newline at end of file +RedmineExtensions::PatchManager.register_controller_patch 'EasyCrmCasesController', + 'RedmineDmsf::Patches::EasyCrmCasesControllerPatch', prepend: true, + if: proc { Redmine::Plugin.installed?(:easy_crm) } diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index d1c97f7d..e84ba442 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -42,29 +42,30 @@ module RedmineDmsf ################################################################################################################## # New methods + def self.prepended(base) + base.class_eval do + has_many :dmsf_files, -> { where(dmsf_folder_id: nil).order(:name) }, + :class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy + has_many :dmsf_folders, ->{ where(:dmsf_folder_id => nil).order(:title) }, + :class_name => 'DmsfFolder', :foreign_key => 'project_id', :dependent => :destroy + has_many :dmsf_workflows, :dependent => :destroy + has_many :folder_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFolder' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + has_many :file_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFile' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + has_many :dmsf_links, -> { where dmsf_folder_id: nil }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - Project.include Redmine::NestedSet::Traversing + before_save :set_default_dmsf_notification - Project.has_many :dmsf_files, -> { where(dmsf_folder_id: nil).order(:name) }, - :class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy - Project.has_many :dmsf_folders, ->{ where(:dmsf_folder_id => nil).order(:title) }, - :class_name => 'DmsfFolder', :foreign_key => 'project_id', :dependent => :destroy - Project.has_many :dmsf_workflows, :dependent => :destroy - Project.has_many :folder_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFolder' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - Project.has_many :file_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFile' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - Project.has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - Project.has_many :dmsf_links, -> { where dmsf_folder_id: nil }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + validates_length_of :dmsf_description, :maximum => 65535 - Project.before_save :set_default_dmsf_notification - - Project.validates_length_of :dmsf_description, :maximum => 65535 - - Project.const_set(:ATTACHABLE_DMS_AND_ATTACHMENTS, 1) - Project.const_set(:ATTACHABLE_ATTACHMENTS, 2) + const_set(:ATTACHABLE_DMS_AND_ATTACHMENTS, 1) + const_set(:ATTACHABLE_ATTACHMENTS, 2) + end + end def set_default_dmsf_notification if self.new_record? @@ -114,4 +115,5 @@ module RedmineDmsf end end -Project.send(:prepend, RedmineDmsf::Patches::ProjectPatch) +RedmineExtensions::PatchManager.register_model_patch 'Project', + 'RedmineDmsf::Patches::ProjectPatch', prepend: true diff --git a/lib/redmine_dmsf/patches/project_tabs_extended.rb b/lib/redmine_dmsf/patches/project_tabs_extended.rb index a2f4b391..b0c1ba80 100644 --- a/lib/redmine_dmsf/patches/project_tabs_extended.rb +++ b/lib/redmine_dmsf/patches/project_tabs_extended.rb @@ -41,4 +41,5 @@ module RedmineDmsf end end -ProjectsHelper.send(:prepend, RedmineDmsf::Patches::ProjectTabsExtended) +RedmineExtensions::PatchManager.register_helper_patch 'ProjectsHelper', + 'RedmineDmsf::Patches::ProjectTabsExtended', prepend: true