diff --git a/app/models/environment.rb b/app/models/environment.rb index 0f385a1..40af24f 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -275,19 +275,21 @@ class Environment < ActiveRecord::Base Person.find_by_id settings[:person_template_id] end - after_create do |env| - pre = env.name.to_slug + '_' - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => env, :public_profile => false).id - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => env, :public_profile => false).id + after_create :create_templates + + def create_templates + pre = self.name.to_slug + '_' + ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :public_profile => false).id + com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :public_profile => false).id pass = Digest::MD5.hexdigest rand.to_s - user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => env).person + user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person user.public_profile = false user.save! usr_id = user.id - env.settings[:enterprise_template_id] = ent_id - env.settings[:community_template_id] = com_id - env.settings[:person_template_id] = usr_id - env.save! + self.settings[:enterprise_template_id] = ent_id + self.settings[:community_template_id] = com_id + self.settings[:person_template_id] = usr_id + self.save! end end diff --git a/db/migrate/052_create_templates.rb b/db/migrate/052_create_templates.rb new file mode 100644 index 0000000..cd4209a --- /dev/null +++ b/db/migrate/052_create_templates.rb @@ -0,0 +1,13 @@ +class CreateTemplates < ActiveRecord::Migration + def self.up + Environment.find(:all).each do |env| + if env.person_template.nil? && env.community_template.nil? && env.enterprise_template.nil? + env.create_templates + end + end + end + + def self.down + # nothing + end +end -- libgit2 0.21.2