socialforge/lib/tasks/office.rake

23 lines
733 B
Ruby
Raw Normal View History

2015-06-03 17:52:59 +08:00
#coding=utf-8
2015-06-03 09:53:10 +08:00
namespace :office do
desc "conver any files to html"
task :conver => :environment do
2015-06-03 18:30:49 +08:00
all_count = Attachment.where(["container_type IN (?)", %w(Project Course)]).count
2015-06-03 10:54:40 +08:00
i = 0
2015-06-03 18:30:49 +08:00
Attachment.where(["container_type IN (?)", %w(Project Course)]).find_each do |a|
2015-06-03 10:54:40 +08:00
i += 1
puts "process [#{i}/#{all_count}] => id #{a.id}"
saved_path = File.join(Rails.root, "files", "convered_office")
unless Dir.exist?(saved_path)
Dir.mkdir(saved_path)
end
2015-06-03 17:43:42 +08:00
convered_file = File.join(saved_path, a.disk_filename + ".pdf")
2015-06-03 10:54:40 +08:00
office = Trustie::Utils::Office.new(a.diskfile)
if office.conver(convered_file)
puts "process ok: #{convered_file} "
2015-06-03 09:53:10 +08:00
end
end
end
end