[Git][noosfero/noosfero][master] 2 commits: restore:remove_emails: removes actual emails from database
Antonio Terceiro
gitlab at gitlab.com
Wed Oct 7 10:51:18 BRT 2015
Antonio Terceiro pushed to branch master at Noosfero / noosfero
Commits:
83d52192 by Antonio Terceiro at 2015-10-05T14:12:53Z
restore:remove_emails: removes actual emails from database
This is useful when you are loading a database dump from a production
database for local tests, and you don't want people's emails there in
order to avoid accidental outgoing email.
- - - - -
b5af2224 by Antonio Terceiro at 2015-10-07T13:50:22Z
Merge branch 'remove-emails' into 'master'
restore:remove_emails: removes actual emails from database
This is useful when you are loading a database dump from a production
database for local tests, and you don't want people's emails there in
order to avoid accidental outgoing email.
See merge request !692
- - - - -
1 changed file:
- lib/tasks/backup.rake
Changes:
=====================================
lib/tasks/backup.rake
=====================================
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -111,3 +111,32 @@ task :restore => :check_backup_support do
puts "Backup restored!"
puts "****************************************************"
end
+
+desc 'Removes emails from database'
+task 'restore:remove_emails' => :environment do
+ connection = ActiveRecord::Base.connection
+ [
+ "UPDATE users SET email = concat('user', id, '@localhost.localdomain')",
+ "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')",
+ ].each do |update|
+ puts update
+ connection.execute(update)
+ end
+
+ profiles = connection.execute("select id, data from profiles")
+ profiles.each do |profile|
+ if profile['data']
+ data = YAML.load(profile['data'])
+ if data[:contact_email] && data[:contact_email] !~ /@localhost.localdomain$/
+ data[:contact_email] = ['profile', profile['id'], '@localhost.localdomain'].join
+ sql = Environment.send(:sanitize_sql, [
+ "UPDATE profiles SET data = ? WHERE id = ?",
+ YAML.dump(data),
+ profile['id'],
+ ])
+ puts sql
+ connection.execute(sql)
+ end
+ end
+ end
+end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/d570e770d71bf7e97e33f897e38a157c694347a8...b5af2224b0bc5e1a404165c45a1b316e53851daa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151007/26472a89/attachment.html>
More information about the Noosfero-dev
mailing list