when publishing a content view if you get:
Validation failed: Puppet environment can't be blank
or
ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
Run the following to recover:
# foreman-rake console
User.current = User.anonymous_api_admin
location = ::Location.find_by_title(::Setting[:default_location_puppet_content])
Katello::ContentViewPuppetEnvironment.where(:puppet_environment_id => nil).where("environment_id is not null").each do |cvpe|
ename = Environment.construct_name(cvpe.organization,
cvpe.environment,
cvpe.content_view)
env = Environment.where(:name => ename).first
if env.nil?
env = Environment.create(:name => ename, :locations => [location], :organizations => [cvpe.content_view.organization])
end
env.organizations << cvpe.content_view.organization unless env.organizations.include?(cvpe.content_view.organization)
location = ::Location.find_by_title(::Setting[:default_location_puppet_content])
env.locations << location unless env.locations.include?(location)
cvpe.puppet_environment = env
cvpe.save!
end
Is this still applicable?