Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Site < ActiveRecord::Base
- validates_presence_of :name, :user
- belongs_to :user
- has_many :site_aliases, :class_name => "SiteAlias"
- accepts_nested_attributes_for :site_aliases, :reject_if => proc { |attributes| attributes['name'].blank? }, :allow_destroy => true
- before_save :create_database_name
- before_save :create_database_username
- before_save :create_database_password
- after_save :queue_configuration_update
- after_destroy :queue_configuration_destroy
- # Get a proxy object for apache operations
- # related to current site
- #
- def proxy_for_apache
- return ApacheProxy.new(self)
- end
- # Get a proxy object for MySQL database operations
- # related to current site
- #
- def proxy_for_database
- return DatabaseProxy.new(self)
- end
- # Get a proxy object for awstats operations
- # related to current site
- #
- def proxy_for_awstats
- return AwstatsProxy.new(self)
- end
- # Generate database name from site name
- #
- def create_database_name
- self.database = "#{name.parameterize.underscore}" unless database.present?
- end
- # Generate random database password for site
- #
- def create_database_password
- self.database_password = ActiveSupport::SecureRandom.base64(6) unless database_password.present?
- end
- # Generate database name
- #
- def create_database_username
- self.database_username = name.parameterize.underscore unless database_username.present?
- end
- # Make sure to write a new apache configuration
- #
- def queue_configuration_update
- ApacheJob.new.apply_configuration self
- DatabaseJob.new.ensure_user self
- end
- # Make sure to delete configuration files
- #
- def queue_configuration_destroy
- ApacheJob.new.delete_configuration self
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement