Class: ThemesInstallTask
- Inherits:
-
Object
- Object
- ThemesInstallTask
- Defined in:
- app/services/themes_install_task.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_component_to_all_themes ⇒ Object
-
#initialize(url_or_options = nil) ⇒ ThemesInstallTask
constructor
A new instance of ThemesInstallTask.
- #install ⇒ Object
- #repo_name ⇒ Object
- #theme_exists? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize(url_or_options = nil) ⇒ ThemesInstallTask
Returns a new instance of ThemesInstallTask.
39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/themes_install_task.rb', line 39 def initialize( = nil) if .is_a?(Hash) .deep_symbolize_keys! @url = .fetch(:url, nil) @options = else @url = @options = {} end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
37 38 39 |
# File 'app/services/themes_install_task.rb', line 37 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
37 38 39 |
# File 'app/services/themes_install_task.rb', line 37 def url @url end |
Class Method Details
.install(themes) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/themes_install_task.rb', line 4 def self.install(themes) counts = { installed: 0, updated: 0, errors: 0, skipped: 0 } log = [] themes.each do |name, val| installer = new(val) next if installer.url.nil? if installer.theme_exists? if installer..fetch(:skip_update, nil) log << "#{name}: is already installed. Skipping update." counts[:skipped] += 1 elsif installer.update log << "#{name}: is already installed. Updating from remote." counts[:updated] += 1 else log << "#{name}: is already installed, but there was an error updating from remote." counts[:errors] += 1 end else begin installer.install log << "#{name}: installed from #{installer.url}" counts[:installed] += 1 rescue RemoteTheme::ImportError, Discourse::InvalidParameters => err log << "#{name}: #{err.}" counts[:errors] += 1 end end end [log, counts] end |
Instance Method Details
#add_component_to_all_themes ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/services/themes_install_task.rb', line 82 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| if ChildTheme.where(parent_theme_id: parent_theme.id, child_theme_id: @theme.id).exists? next end parent_theme.add_relative_theme!(:child, @theme) end end |
#install ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/themes_install_task.rb', line 64 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) add_component_to_all_themes end |
#repo_name ⇒ Object
50 51 52 |
# File 'app/services/themes_install_task.rb', line 50 def repo_name @url.gsub(Regexp.union("[email protected]:", "https://github.com/", ".git"), "") end |
#theme_exists? ⇒ Boolean
54 55 56 57 58 59 60 61 62 |
# File 'app/services/themes_install_task.rb', line 54 def theme_exists? @remote_theme = RemoteTheme .where("remote_url like ?", "%#{repo_name}%") .where(branch: @options.fetch(:branch, nil)) .first @theme = @remote_theme&.theme @theme.present? end |
#update ⇒ Object
76 77 78 79 80 |
# File 'app/services/themes_install_task.rb', line 76 def update @remote_theme.update_from_remote(raise_if_theme_save_fails: false) add_component_to_all_themes @remote_theme.last_error_text.nil? end |