summaryrefslogtreecommitdiffstats
path: root/app/models/import.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/import.rb')
-rw-r--r--app/models/import.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 22b90b6ac..b3aa914af 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -138,6 +138,24 @@ class Import < ActiveRecord::Base
settings['mapping'] || {}
end
+ # Adds a callback that will be called after the item at given position is imported
+ def add_callback(position, name, *args)
+ settings['callbacks'] ||= {}
+ settings['callbacks'][position.to_i] ||= []
+ settings['callbacks'][position.to_i] << [name, args]
+ save!
+ end
+
+ # Executes the callbacks for the given object
+ def do_callbacks(position, object)
+ if callbacks = (settings['callbacks'] || {}).delete(position)
+ callbacks.each do |name, args|
+ send "#{name}_callback", object, *args
+ end
+ save!
+ end
+ end
+
# Imports items and returns the position of the last processed item
def run(options={})
max_items = options[:max_items]
@@ -157,7 +175,7 @@ class Import < ActiveRecord::Base
item = items.build
item.position = position
- if object = build_object(row)
+ if object = build_object(row, item)
if object.save
item.obj_id = object.id
else
@@ -167,6 +185,8 @@ class Import < ActiveRecord::Base
item.save!
imported += 1
+
+ do_callbacks(item.position, object)
end
current = position
end