0001-Making-possible-to-change-plugins-loading-order.patch

Lucas Arnaud, 2017-01-27 20:00

Download (2.43 KB)

View differences:

config/additional_environment.rb.example
7 7
#   config.log_level = :debug
8 8
#   ...
9 9
#
10
# Determine plugins loading priorities, least priorities will be loaded sooner
11
# , undefined priorities will default to 0
12
# Loading priority relies that plugin directory name is equals to its id
13
#
14
# Ex:
15
#
16
# config.plugins_load_order = {
17
#     plugin_1: -2,
18
#     plugin_2: -1,
19
#     plugin_3: 1
20
# }
10 21

  
lib/redmine/plugin.rb
143 143
    end
144 144

  
145 145
    def self.load
146
      plugins_initializers = []
146 147
      Dir.glob(File.join(self.directory, '*')).sort.each do |directory|
147 148
        if File.directory?(directory)
148 149
          lib = File.join(directory, "lib")
......
152 153
          end
153 154
          initializer = File.join(directory, "init.rb")
154 155
          if File.file?(initializer)
155
            require initializer
156
            plugins_initializers << { id: File.basename(directory), initializer: initializer }
156 157
          end
157 158
        end
158 159
      end
160

  
161
      plugins_initializers.sort { |p1, p2| compare_with_load_order(p1[:id], p2[:id]) }.each do |plugin|
162
        require plugin[:initializer]
163
      end
159 164
    end
160 165

  
161 166
    def initialize(id)
......
175 180
    end
176 181

  
177 182
    def <=>(plugin)
178
      self.id.to_s <=> plugin.id.to_s
183
      self.class.compare_with_load_order(id, plugin.id)
184
    end
185

  
186
    def self.compare_with_load_order(plugin1_id, plugin2_id)
187
      p1 = Rails.application.config.plugins_load_order[plugin1_id.to_sym] || 0
188
      p2 = Rails.application.config.plugins_load_order[plugin2_id.to_sym] || 0
189

  
190
      if p1 == p2
191
        return plugin1_id <=> plugin2_id
192
      end
193

  
194
      p1 <=> p2
179 195
    end
180 196

  
181 197
    # Sets a requirement on Redmine version
182
-