Commit ce19d6fd402c8a58fa798c89bd421712602ea08c
1 parent
91dd1533
Exists in
master
and in
22 other branches
ActionItem629: migrating user data
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2431 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
24 additions
and
9 deletions
Show diff stats
app/models/environment.rb
| ... | ... | @@ -275,19 +275,21 @@ class Environment < ActiveRecord::Base |
| 275 | 275 | Person.find_by_id settings[:person_template_id] |
| 276 | 276 | end |
| 277 | 277 | |
| 278 | - after_create do |env| | |
| 279 | - pre = env.name.to_slug + '_' | |
| 280 | - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => env, :public_profile => false).id | |
| 281 | - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => env, :public_profile => false).id | |
| 278 | + after_create :create_templates | |
| 279 | + | |
| 280 | + def create_templates | |
| 281 | + pre = self.name.to_slug + '_' | |
| 282 | + ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :public_profile => false).id | |
| 283 | + com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :public_profile => false).id | |
| 282 | 284 | pass = Digest::MD5.hexdigest rand.to_s |
| 283 | - user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => env).person | |
| 285 | + user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person | |
| 284 | 286 | user.public_profile = false |
| 285 | 287 | user.save! |
| 286 | 288 | usr_id = user.id |
| 287 | - env.settings[:enterprise_template_id] = ent_id | |
| 288 | - env.settings[:community_template_id] = com_id | |
| 289 | - env.settings[:person_template_id] = usr_id | |
| 290 | - env.save! | |
| 289 | + self.settings[:enterprise_template_id] = ent_id | |
| 290 | + self.settings[:community_template_id] = com_id | |
| 291 | + self.settings[:person_template_id] = usr_id | |
| 292 | + self.save! | |
| 291 | 293 | end |
| 292 | 294 | |
| 293 | 295 | end | ... | ... |
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +class CreateTemplates < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + Environment.find(:all).each do |env| | |
| 4 | + if env.person_template.nil? && env.community_template.nil? && env.enterprise_template.nil? | |
| 5 | + env.create_templates | |
| 6 | + end | |
| 7 | + end | |
| 8 | + end | |
| 9 | + | |
| 10 | + def self.down | |
| 11 | + # nothing | |
| 12 | + end | |
| 13 | +end | ... | ... |