Project

General

Profile

Feature #39111 » 0002-Remove-codes-that-is-no-longer-needed-as-a-result-of.patch

Takashi Kato, 2023-09-24 17:44

View differences:

app/controllers/admin_controller.rb
79 79
    @checklist = [
80 80
      [:text_default_administrator_account_changed, User.default_admin_account_changed?],
81 81
      [:text_file_repository_writable, File.writable?(Attachment.storage_path)],
82
      ["#{l :text_plugin_assets_writable} (./public/plugin_assets)",   File.writable?(Redmine::Plugin.public_directory)],
83 82
      [:text_all_migrations_have_been_run, !ActiveRecord::Base.connection.migration_context.needs_migration?],
84 83
      [:text_minimagick_available,     Object.const_defined?(:MiniMagick)],
85 84
      [:text_convert_available,        Redmine::Thumbnail.convert_available?],
lib/redmine/plugin_loader.rb
35 35
      @dir
36 36
    end
37 37

  
38
    def mirror_assets
39
      return unless has_assets_dir?
40

  
41
      destination = File.join(PluginLoader.public_directory, File.basename(@dir))
42

  
43
      source_files = Dir["#{assets_dir}/**/*"]
44
      source_dirs = source_files.select { |d| File.directory?(d)}
45
      source_files -= source_dirs
46
      unless source_files.empty?
47
        base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(assets_dir, ''))
48
        begin
49
          FileUtils.mkdir_p(base_target_dir)
50
        rescue => e
51
          raise "Could not create directory #{base_target_dir}: " + e.message
52
        end
53
      end
54

  
55
      source_dirs.each do |dir|
56
        # strip down these paths so we have simple, relative paths we can
57
        # add to the destination
58
        target_dir = File.join(destination, dir.gsub(assets_dir, ''))
59
        begin
60
          FileUtils.mkdir_p(target_dir)
61
        rescue => e
62
          raise "Could not create directory #{target_dir}: " + e.message
63
        end
64
      end
65
      source_files.each do |file|
66
        target = File.join(destination, file.gsub(assets_dir, ''))
67
        unless File.exist?(target) && FileUtils.identical?(file, target)
68
          FileUtils.cp(file, target)
69
        end
70
      rescue => e
71
        raise "Could not copy #{file} to #{target}: " + e.message
72
      end
73
    end
74

  
75 38
    def has_assets_dir?
76 39
      File.directory?(@assets_dir)
77 40
    end
......
90 53
    cattr_accessor :public_directory
91 54
    self.public_directory = Rails.public_path.join('plugin_assets')
92 55

  
93
    def self.create_assets_reloader
94
      plugin_assets_dirs = {}
95
      directories.each do |dir|
96
        plugin_assets_dirs[dir.assets_dir] = ['*']
97
      end
98
      ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
99
        mirror_assets
100
      end
101
    end
102

  
103 56
    def self.load
104 57
      setup
105 58
      add_autoload_paths
......
136 89
    def self.directories
137 90
      @plugin_directories
138 91
    end
139

  
140
    def self.mirror_assets(name=nil)
141
      if name.present?
142
        directories.find{|d| d.to_s == File.join(directory, name)}.mirror_assets
143
      else
144
        directories.each(&:mirror_assets)
145
      end
146
    end
147 92
  end
148 93
end
test/unit/lib/redmine/plugin_loader_test.rb
25 25

  
26 26
    @klass = Redmine::PluginLoader
27 27
    @klass.directory = Rails.root.join('test/fixtures/plugins')
28
    @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
29 28
    @klass.load
30 29
  end
31 30

  
......
33 32
    clear_public
34 33
  end
35 34

  
36
  def test_create_assets_reloader
37
    plugin_assets = @klass.create_assets_reloader
38
    plugin_assets.execute.inspect
39

  
40
    assert File.exist?("#{@klass.public_directory}/foo_plugin")
41
    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
42
  end
43

  
44
  def test_mirror_assets
45
    Redmine::PluginLoader.mirror_assets
46

  
47
    assert File.exist?("#{@klass.public_directory}/foo_plugin")
48
    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
49
  end
50

  
51
  def test_mirror_assets_with_plugin_name
52
    Redmine::PluginLoader.mirror_assets('foo_plugin')
53

  
54
    assert File.exist?("#{@klass.public_directory}/foo_plugin")
55
    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
56
  end
57

  
58 35
  def clear_public
59 36
    FileUtils.rm_rf 'tmp/public'
60 37
  end
(2-2/10)