From 22c5d7601284e25d7ae76ff89ce64d0f008d3f1b Mon Sep 17 00:00:00 2001
From: tohosaku <tohosaku@users.osdn.me>
Date: Thu, 22 Dec 2022 02:13:16 +0000
Subject: [PATCH 2/3] Remove codes that is no longer needed as a result of
 asset pipeline implementation

---
 app/controllers/admin_controller.rb         |  1 -
 lib/redmine/plugin_loader.rb                | 55 ---------------------
 test/unit/lib/redmine/plugin_loader_test.rb | 23 ---------
 3 files changed, 79 deletions(-)

diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 40a04dcf7..d787a3183 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -79,7 +79,6 @@ class AdminController < ApplicationController
     @checklist = [
       [:text_default_administrator_account_changed, User.default_admin_account_changed?],
       [:text_file_repository_writable, File.writable?(Attachment.storage_path)],
-      ["#{l :text_plugin_assets_writable} (./public/plugin_assets)",   File.writable?(Redmine::Plugin.public_directory)],
       [:text_all_migrations_have_been_run, !ActiveRecord::Base.connection.migration_context.needs_migration?],
       [:text_minimagick_available,     Object.const_defined?(:MiniMagick)],
       [:text_convert_available,        Redmine::Thumbnail.convert_available?],
diff --git a/lib/redmine/plugin_loader.rb b/lib/redmine/plugin_loader.rb
index 2151e949b..684403bca 100644
--- a/lib/redmine/plugin_loader.rb
+++ b/lib/redmine/plugin_loader.rb
@@ -35,43 +35,6 @@ module Redmine
       @dir
     end
 
-    def mirror_assets
-      return unless has_assets_dir?
-
-      destination = File.join(PluginLoader.public_directory, File.basename(@dir))
-
-      source_files = Dir["#{assets_dir}/**/*"]
-      source_dirs = source_files.select { |d| File.directory?(d)}
-      source_files -= source_dirs
-      unless source_files.empty?
-        base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(assets_dir, ''))
-        begin
-          FileUtils.mkdir_p(base_target_dir)
-        rescue => e
-          raise "Could not create directory #{base_target_dir}: " + e.message
-        end
-      end
-
-      source_dirs.each do |dir|
-        # strip down these paths so we have simple, relative paths we can
-        # add to the destination
-        target_dir = File.join(destination, dir.gsub(assets_dir, ''))
-        begin
-          FileUtils.mkdir_p(target_dir)
-        rescue => e
-          raise "Could not create directory #{target_dir}: " + e.message
-        end
-      end
-      source_files.each do |file|
-        target = File.join(destination, file.gsub(assets_dir, ''))
-        unless File.exist?(target) && FileUtils.identical?(file, target)
-          FileUtils.cp(file, target)
-        end
-      rescue => e
-        raise "Could not copy #{file} to #{target}: " + e.message
-      end
-    end
-
     def has_assets_dir?
       File.directory?(@assets_dir)
     end
@@ -90,16 +53,6 @@ module Redmine
     cattr_accessor :public_directory
     self.public_directory = Rails.public_path.join('plugin_assets')
 
-    def self.create_assets_reloader
-      plugin_assets_dirs = {}
-      directories.each do |dir|
-        plugin_assets_dirs[dir.assets_dir] = ['*']
-      end
-      ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
-        mirror_assets
-      end
-    end
-
     def self.load
       setup
       add_autoload_paths
@@ -136,13 +89,5 @@ module Redmine
     def self.directories
       @plugin_directories
     end
-
-    def self.mirror_assets(name=nil)
-      if name.present?
-        directories.find{|d| d.to_s == File.join(directory, name)}.mirror_assets
-      else
-        directories.each(&:mirror_assets)
-      end
-    end
   end
 end
diff --git a/test/unit/lib/redmine/plugin_loader_test.rb b/test/unit/lib/redmine/plugin_loader_test.rb
index ed5943346..26a0f4b2a 100644
--- a/test/unit/lib/redmine/plugin_loader_test.rb
+++ b/test/unit/lib/redmine/plugin_loader_test.rb
@@ -25,7 +25,6 @@ class Redmine::PluginLoaderTest < ActiveSupport::TestCase
 
     @klass = Redmine::PluginLoader
     @klass.directory = Rails.root.join('test/fixtures/plugins')
-    @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
     @klass.load
   end
 
@@ -33,28 +32,6 @@ class Redmine::PluginLoaderTest < ActiveSupport::TestCase
     clear_public
   end
 
-  def test_create_assets_reloader
-    plugin_assets = @klass.create_assets_reloader
-    plugin_assets.execute.inspect
-
-    assert File.exist?("#{@klass.public_directory}/foo_plugin")
-    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
-  end
-
-  def test_mirror_assets
-    Redmine::PluginLoader.mirror_assets
-
-    assert File.exist?("#{@klass.public_directory}/foo_plugin")
-    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
-  end
-
-  def test_mirror_assets_with_plugin_name
-    Redmine::PluginLoader.mirror_assets('foo_plugin')
-
-    assert File.exist?("#{@klass.public_directory}/foo_plugin")
-    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
-  end
-
   def clear_public
     FileUtils.rm_rf 'tmp/public'
   end
-- 
2.39.2

