Add warning when plugins changed by `tmp` was not removed

This commit is contained in:
Robin Ward 2017-09-08 13:38:46 -04:00
parent 7eb79ea31d
commit 717ed75fc4
1 changed files with 16 additions and 0 deletions

View File

@ -3,6 +3,7 @@ require 'open3'
require_dependency 'plugin/instance' require_dependency 'plugin/instance'
require_dependency 'auth/default_current_user_provider' require_dependency 'auth/default_current_user_provider'
require_dependency 'version' require_dependency 'version'
require 'digest/sha1'
# Prevents errors with reloading dev with conditional includes # Prevents errors with reloading dev with conditional includes
if Rails.env.development? if Rails.env.development?
@ -120,6 +121,21 @@ module Discourse
def self.activate_plugins! def self.activate_plugins!
all_plugins = Plugin::Instance.find_all("#{Rails.root}/plugins") all_plugins = Plugin::Instance.find_all("#{Rails.root}/plugins")
if Rails.env.development?
plugin_hash = Digest::SHA1.hexdigest(all_plugins.map { |p| p.path }.sort.join('|'))
hash_file = "#{Rails.root}/tmp/plugin-hash"
old_hash = File.read(hash_file) rescue nil
if old_hash && old_hash != plugin_hash
puts "WARNING: It looks like your discourse plugins have recently changed."
puts "It is highly recommended to remove your `tmp` directory, otherwise"
puts "plugins might not work."
puts
else
File.write(hash_file, plugin_hash)
end
end
@plugins = [] @plugins = []
all_plugins.each do |p| all_plugins.each do |p|
v = p.metadata.required_version || Discourse::VERSION::STRING v = p.metadata.required_version || Discourse::VERSION::STRING