diff --git a/app/services/foreman_templates/parse_result.rb b/app/services/foreman_templates/parse_result.rb index 3fd9d7ea..3312bfb8 100644 --- a/app/services/foreman_templates/parse_result.rb +++ b/app/services/foreman_templates/parse_result.rb @@ -15,7 +15,7 @@ def to_h(verbose = false) :imported => @imported, :additional_errors => @additional_errors, :additional_info => @additional_info, - :exception => @exception ? @exception.message : nil, + :exception => @exception&.message, :validation_errors => errors.to_h, :file => @template_file, :type => @template.present? ? @template.class.name.underscore : nil @@ -27,7 +27,7 @@ def to_h(verbose = false) end def errors - @template ? @template.errors : nil + @template&.errors end def corrupted_metadata diff --git a/app/services/foreman_templates/template_importer.rb b/app/services/foreman_templates/template_importer.rb index 3f026b38..8a2477d5 100644 --- a/app/services/foreman_templates/template_importer.rb +++ b/app/services/foreman_templates/template_importer.rb @@ -164,7 +164,7 @@ def auto_prefix(name) def purge! clause = "name #{@negate ? 'NOT ' : ''}LIKE ?" - ProvisioningTemplate.where(clause, "#{@prefix}%").each do |template| + ProvisioningTemplate.where(clause, "#{@prefix}%").find_each do |template| puts template if @verbose template.destroy end