Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Find out when the user was deleted
- User::Archive.find(user_id).deleted_at
- # Using their archive_user_id (which shows up on the Deleted Users page next to the username, find their user_id
- User::Archive.find(user_id).attributes['id']
- # Find the customer id of the destroyed user, usually from the Deleted Users tab in BASS
- User::Archive.find_by_email('<domain_owner_email>').customer_id
- customer_id = ###;
- # Set up
- archived_customer = Customer::Archive.where(:id => customer_id).first;
- archived_user = User::Archive.where(:customer_id => archived_customer.id).first;
- archived_subscription = Subscription::Archive.where(:customer_id => customer_id).first;
- archived_account = Office365::Account::Archive.where(:customer_id => customer_id).first;
- archived_active_directory = Office365::ActiveDirectory::Archive.where(:account_id => archived_account.id).first;
- archived_members = Office365::Member::Archive.where(:customer_id => customer_id);
- archived_seats = Office365::Seat::Archive.where(:customer_id => customer_id);
- archived_services = Service::Archive.where(:customer_id => customer_id);
- archived_line_items = LineItem::Archive.where(:subscription_id => archived_subscription.id);
- # Restore the Customer
- Customer.copy_from_archive("archived_customers.id" => archived_customer.attributes["id"])
- # Restore the User
- User.copy_from_archive("archived_users.id" => archived_user.attributes["id"])
- # Restore the Subscription
- Subscription.copy_from_archive("archived_subscriptions.id" => archived_subscription.attributes["id"])
- # Restore the Account
- Office365::Account.copy_from_archive("archived_accounts.id" => archived_account.attributes["id"])
- # Restore the Active Directory
- Office365::ActiveDirectory.copy_from_archive("archived_active_directories.id" => archived_active_directory.attributes["id"])
- # Restore the Seats
- archived_seats.each do |aseat|
- id = aseat.attributes["id"]
- Office365::Seat.copy_from_archive("archived_seats.id" => id)
- puts "Successfully Restored #{id}:#{aseat.type} service for #{aseat.principal_name}."
- end;
- # Restore the Members
- archived_members.each do |amem|
- id = amem.attributes["id"]
- Office365::Member.copy_from_archive("archived_members.id" => id)
- puts "Successfully Restored #{id}: #{amem.principal_name}."
- end;
- # Restore the Services
- archived_services.each do |as|
- id = as.attributes["id"]
- Service::copy_from_archive("archived_services.id" => id)
- puts "Successfully Restored #{id}:#{as.type} service for #{as.account_name}."
- end;
- # Restore the Line Items
- archived_line_items.each do |ali|
- id = ali.attributes["id"]
- LineItem.copy_from_archive("archived_line_items.id" => id)
- puts "Successfully Restored #{id}"
- end;
- # Relink services to seats
- seats = Office365::Seat.where(:customer_id => customer_id);
- services = Service.where(:customer_id => customer_id);
- seats.each do |seat|
- services_to_link = services.where(:account_name => seat.principal_name)
- services_to_link.each{|s| s.seat = seat; s.save!; puts s.account_name}
- end;
- # Generate backup slots
- services.each { |s| BackupSlot.generate_schedule_for_service(s); puts "Generated for #{s.id}"};
- # Recreate SSO entry
- u.user_sso_id = nil
- u.insert_user_sso
- u.save!
- # If the reinstated user already has an sso id:
- u.user_sso_id = ""
- => ""
- u.insert_user_sso
- u.save!
- u.reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement