Skip to content

Commit

Permalink
Didn't quite work as I'd hoped as the plugin model doesn't expose the…
Browse files Browse the repository at this point in the history
… created_at/updated_at fields that a model usually would. Will have to think a little more outside the box
  • Loading branch information
AJ Christensen committed Jun 24, 2008
1 parent 3c9c6c8 commit f56431f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions app/models/plugin.rb
Expand Up @@ -52,26 +52,22 @@ def download
##
# This loads and installs the plugin
def install
if created_on == Date.today and touched_on == Date.today and new_record? == false and updated_on == nil
# Ensure we don't have any errors while saving already
if self.errors.empty?
begin
# Load the plugin
self.load
# Also, if there is an "install.rb" script present, run that to setup anything the plugin needs (database tables etc)
Merb.logger.debug!("Trying to autoload install.rb of plugin (#{File.join(self.path, "install.rb")})")
require File.join(self.path, "install.rb") if File.exists?(File.join(self.path, "install.rb"))
rescue Exception => err
# If we have an issue installing, lets destroy the plugin to rollback, and put an error on the object so it displays on the form
self.destroy
self.errors.add "Error installing plugin: #{err.message}"
end
else
# If we do, destroy the plugin to rollback, and then the form will display the errors
# Ensure we don't have any errors while saving already
if self.errors.empty?
begin
# Load the plugin
self.load
# Also, if there is an "install.rb" script present, run that to setup anything the plugin needs (database tables etc)
Merb.logger.debug!("Trying to autoload install.rb of plugin (#{File.join(self.path, "install.rb")})")
require File.join(self.path, "install.rb") if File.exists?(File.join(self.path, "install.rb"))
rescue Exception => err
# If we have an issue installing, lets destroy the plugin to rollback, and put an error on the object so it displays on the form
self.destroy
self.errors.add "Error installing plugin: #{err.message}"
end
else
Merb.logger.debug!("Not reinstalling already installed plugin")
# If we do, destroy the plugin to rollback, and then the form will display the errors
self.destroy
end
end

Expand Down

0 comments on commit f56431f

Please sign in to comment.