<commit_before>require_dependency 'setting'

module RedmineGitHosting
  module Patches
    module SettingPatch

      def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
          unloadable

          before_save  :save_git_hosting_values
          after_commit :restore_git_hosting_values
        end
      end

      module InstanceMethods

        private

        @@old_valuehash     = ((Setting.plugin_redmine_git_hosting).clone rescue {})
        @@resync_projects   = false
        @@resync_ssh_keys   = false
        @@flush_cache       = false
        @@delete_trash_repo = []


        def save_git_hosting_values
          # Only validate settings for our plugin
          if self.name == 'plugin_redmine_git_hosting'
            valuehash = self.value

            ## This a force update
            @@resync_projects = true if valuehash[:gitolite_resync_all_projects] == 'true'
            @@resync_ssh_keys = true if valuehash[:gitolite_resync_all_ssh_keys] == 'true'

            ## Flush Gitolite Cache
            @@flush_cache = true if valuehash[:gitolite_flush_cache] == 'true'

            ## Empty Recycle Bin
            @@delete_trash_repo = valuehash[:gitolite_purge_repos] if valuehash.has_key?(:gitolite_purge_repos) && !valuehash[:gitolite_purge_repos].empty?

            # Call ValidateSettings and save back results (this return a modified valuehash)
            self.value = ValidateSettings.new(@@old_valuehash, valuehash).call
          end
        end


        def restore_git_hosting_values
          # Only perform after-actions on settings for our plugin
          if self.name == 'plugin_redmine_git_hosting'
            valuehash = self.value

            # Settings cache doesn't seem to invalidate symbolic versions of Settings immediately,
            # so, any use of Setting.plugin_redmine_git_hosting[] by things called during this
            # callback will be outdated.... True for at least some versions of redmine plugin...
            #
            # <NAME> 12/21/2011
            # Clear out all cached settings.
            Setting.check_cache if Setting.respond_to?(:check_cache)
            FlushSettingsCache.new().call

            # Build options to pass to RestoreSettings object
            opts = {
              resync_projects:   @@resync_projects,
              resync_ssh_keys:   @@resync_ssh_keys,
              delete_trash_repo: @@delete_trash_repo,
              flush_cache:       @@flush_cache
            }

            # Call RestoreSettings
            ApplySettings.new(@@old_valuehash, valuehash, opts).call

            # Restore default class settings
            @@resync_projects   = false
            @@resync_ssh_keys   = false
            @@flush_cache       = false
            @@delete_trash_repo = []

            @@old_valuehash = valuehash.clone
          end
        end

      end

    end
  end
end

unless Setting.included_modules.include?(RedmineGitHosting::Patches::SettingPatch)
  Setting.send(:include, RedmineGitHosting::Patches::SettingPatch)
end
<commit_msg>Useless to flush settings cache twice<commit_after>require_dependency 'setting'

module RedmineGitHosting
  module Patches
    module SettingPatch

      def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
          unloadable

          before_save  :save_git_hosting_values
          after_commit :restore_git_hosting_values
        end
      end

      module InstanceMethods

        private

        @@old_valuehash     = ((Setting.plugin_redmine_git_hosting).clone rescue {})
        @@resync_projects   = false
        @@resync_ssh_keys   = false
        @@flush_cache       = false
        @@delete_trash_repo = []


        def save_git_hosting_values
          # Only validate settings for our plugin
          if self.name == 'plugin_redmine_git_hosting'
            valuehash = self.value

            ## This a force update
            @@resync_projects = true if valuehash[:gitolite_resync_all_projects] == 'true'
            @@resync_ssh_keys = true if valuehash[:gitolite_resync_all_ssh_keys] == 'true'

            ## Flush Gitolite Cache
            @@flush_cache = true if valuehash[:gitolite_flush_cache] == 'true'

            ## Empty Recycle Bin
            @@delete_trash_repo = valuehash[:gitolite_purge_repos] if valuehash.has_key?(:gitolite_purge_repos) && !valuehash[:gitolite_purge_repos].empty?

            # Call ValidateSettings and save back results (this return a modified valuehash)
            self.value = ValidateSettings.new(@@old_valuehash, valuehash).call
          end
        end


        def restore_git_hosting_values
          # Only perform after-actions on settings for our plugin
          if self.name == 'plugin_redmine_git_hosting'
            valuehash = self.value

            # Settings cache doesn't seem to invalidate symbolic versions of Settings immediately,
            # so, any use of Setting.plugin_redmine_git_hosting[] by things called during this
            # callback will be outdated.... True for at least some versions of redmine plugin...
            #
            # <NAME> 12/21/2011
            # Clear out all cached settings.
            FlushSettingsCache.new().call

            # Build options to pass to RestoreSettings object
            opts = {
              resync_projects:   @@resync_projects,
              resync_ssh_keys:   @@resync_ssh_keys,
              delete_trash_repo: @@delete_trash_repo,
              flush_cache:       @@flush_cache
            }

            # Call RestoreSettings
            ApplySettings.new(@@old_valuehash, valuehash, opts).call

            # Restore default class settings
            @@resync_projects   = false
            @@resync_ssh_keys   = false
            @@flush_cache       = false
            @@delete_trash_repo = []

            @@old_valuehash = valuehash.clone
          end
        end

      end

    end
  end
end

unless Setting.included_modules.include?(RedmineGitHosting::Patches::SettingPatch)
  Setting.send(:include, RedmineGitHosting::Patches::SettingPatch)
end

{'fraction_non_alphanumeric': 0.07171831900048678, 'fraction_numerical': 0.0025961382443615124, 'mean_word_length': 2.152941176470588, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4035746', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1634, 'n_words': 398}