Fix cloud storage migration task
This commit is contained in:
parent
35a48ad11c
commit
8e88e1489b
2 changed files with 15 additions and 6 deletions
1
config/initializers/openstack_version.rb
Normal file
1
config/initializers/openstack_version.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
OpenStack::VERSION = 2.0
|
|
@ -22,22 +22,30 @@ namespace :cloudstorage do
|
||||||
|
|
||||||
Rake::Task['cloudstorage:init'].invoke
|
Rake::Task['cloudstorage:init'].invoke
|
||||||
|
|
||||||
|
error_count = 0
|
||||||
[Cerfa, PieceJustificative, Procedure].each { |c|
|
[Cerfa, PieceJustificative, Procedure].each { |c|
|
||||||
c.all.each { |entry|
|
c.all.each { |entry|
|
||||||
content = entry.content
|
content = (c == Procedure)? entry.logo : entry.content
|
||||||
content = entry.logo if c == Procedure
|
|
||||||
unless content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded')
|
unless content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded')
|
||||||
secure_token = SecureRandom.uuid
|
secure_token = SecureRandom.uuid
|
||||||
filename = "#{entry.class.to_s.underscore}-#{secure_token}.pdf"
|
filename = "#{entry.class.to_s.underscore}-#{secure_token}.pdf"
|
||||||
puts "Uploading #{content.current_path}"
|
puts "Uploading #{content.current_path}"
|
||||||
@cont.create_object(filename, { content_type: "application/pdf"}, File.open(content.current_path))
|
begin
|
||||||
File.open(File.dirname(content.current_path) + '/uploaded', "w+"){ |f| f.write(File.basename(content.current_path)) }
|
@cont.create_object(filename, { content_type: "application/pdf"}, File.open(content.current_path))
|
||||||
entry.update_column(c == Procedure ? :logo : :content, filename)
|
File.open(File.dirname(content.current_path) + '/uploaded', "w+"){ |f| f.write(File.basename(content.current_path)) }
|
||||||
|
entry.update_column(c == Procedure ? :logo : :content, filename)
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
puts "ERROR: #{content.current_path} does not exist!"
|
||||||
|
File.open('upload_errors.report', "a+"){ |f| f.write(content.current_path) }
|
||||||
|
error_count += 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "Skipping #{content.current_path}"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details."
|
||||||
puts 'Enf of migration'
|
puts 'Enf of migration'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue