DEV: Add options to theme install rake task - more options (#9394)

This commit is contained in:
Mark VanLandingham
2020-04-14 09:17:00 -05:00
committed by GitHub
parent 2aaf5cb2b8
commit f07c4a781c
3 changed files with 171 additions and 87 deletions

View File

@@ -1,18 +1,17 @@
# frozen_string_literal: true
class ThemesInstallTask
def self.install(yml)
counts = { installed: 0, updated: 0, skipped: 0, errors: 0 }
def self.install(themes)
counts = { installed: 0, updated: 0, errors: 0 }
log = []
themes = YAML::load(yml)
themes.each do |theme|
name = theme[0]
val = theme[1]
themes.each do |name, val|
installer = new(val)
next if installer.url.nil?
if installer.theme_exists?
log << "#{name}: is already installed"
counts[:skipped] += 1
installer.update
log << "#{name}: is already installed. Updating from remote."
counts[:updated] += 1
else
begin
installer.install
@@ -32,7 +31,8 @@ class ThemesInstallTask
def initialize(url_or_options = nil)
if url_or_options.is_a?(Hash)
@url = url_or_options.fetch("url")
url_or_options.deep_symbolize_keys!
@url = url_or_options.fetch(:url, nil)
@options = url_or_options
else
@url = url_or_options
@@ -41,14 +41,28 @@ class ThemesInstallTask
end
def theme_exists?
RemoteTheme
.where(remote_url: url)
.where(branch: options.fetch("branch", nil))
.exists?
@remote_theme = RemoteTheme.find_by(remote_url: @url, branch: @options.fetch(:branch, nil))
@theme = @remote_theme&.theme
@theme.present?
end
def install
theme = RemoteTheme.import_theme(url, Discourse.system_user, private_key: options["private_key"], branch: options["branch"])
theme.set_default! if options.fetch("default", false)
@theme = RemoteTheme.import_theme(@url, Discourse.system_user, private_key: @options[:private_key], branch: @options[:branch])
@theme.set_default! if @options.fetch(:default, false)
add_component_to_all_themes
end
def update
@remote_theme.update_from_remote
add_component_to_all_themes
end
def add_component_to_all_themes
return if (!@options.fetch(:add_to_all_themes, false) || !@theme.component)
Theme.where(component: false).each do |parent_theme|
next if ChildTheme.where(parent_theme_id: parent_theme.id, child_theme_id: @theme.id).exists?
parent_theme.add_relative_theme!(:child, @theme)
end
end
end