diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 7ac7d786d..1e477ed04 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -72,7 +72,7 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") before_save :files_to_final_location - after_create :be_user_score ,:act_as_forge_activity# user_score + after_create :office_conver, :be_user_score ,:act_as_forge_activity# user_score after_update :be_user_score after_destroy :delete_from_disk,:down_user_score @@ -258,6 +258,15 @@ class Attachment < ActiveRecord::Base filename end + def office_conver + saved_path = File.join(Rails.root, "files", "convered_office") + unless Dir.exist?(saved_path) + Dir.mkdir(saved_path) + end + convered_file = File.join(saved_path, self.disk_filename + ".html") + OfficeConverTask.new.conver(self.diskfile, convered_file) + end + # Copies the temporary file to its final location # and computes its MD5 hash def files_to_final_location diff --git a/app/tasks/office_conver_task.rb b/app/tasks/office_conver_task.rb new file mode 100644 index 000000000..da950bf2e --- /dev/null +++ b/app/tasks/office_conver_task.rb @@ -0,0 +1,12 @@ +#coding=utf-8 +# +class OfficeConverTask + def conver(source_file, saved_file) + office = Trustie::Utils::Office.new(source_file) + if office.conver(saved_file) + Rails.logger.info "process ok: #{saved_file} " + end + end + handle_asynchronously :conver,:queue => 'office_conver' +end +