Remove carrierwave

This commit is contained in:
Paul Chavard 2019-11-12 15:26:18 +01:00
parent 4bc0006ca0
commit fe84e8e0f7
6 changed files with 0 additions and 182 deletions

View file

@ -13,12 +13,9 @@ gem 'bcrypt'
gem 'bootstrap-sass', '>= 3.4.1' gem 'bootstrap-sass', '>= 3.4.1'
gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8' gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8'
gem 'browser' gem 'browser'
gem 'carrierwave'
gem 'carrierwave-i18n'
gem 'chartkick' gem 'chartkick'
gem 'chunky_png' gem 'chunky_png'
gem 'clamav-client', require: 'clamav/client' gem 'clamav-client', require: 'clamav/client'
gem 'copy_carrierwave_file'
gem 'daemons' gem 'daemons'
gem 'deep_cloneable' # Enable deep clone of active record models gem 'deep_cloneable' # Enable deep clone of active record models
gem 'delayed_cron_job' # Cron jobs gem 'delayed_cron_job' # Cron jobs

View file

@ -136,11 +136,6 @@ GEM
capybara-selenium (0.0.6) capybara-selenium (0.0.6)
capybara capybara
selenium-webdriver selenium-webdriver
carrierwave (1.3.1)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
carrierwave-i18n (0.2.0)
case_transform (0.2) case_transform (0.2)
activesupport activesupport
chartkick (3.2.0) chartkick (3.2.0)
@ -158,8 +153,6 @@ GEM
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.1.5) concurrent-ruby (1.1.5)
connection_pool (2.2.2) connection_pool (2.2.2)
copy_carrierwave_file (1.3.0)
carrierwave (>= 0.9)
crack (0.4.3) crack (0.4.3)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
crass (1.0.5) crass (1.0.5)
@ -730,12 +723,9 @@ DEPENDENCIES
capybara-email capybara-email
capybara-screenshot capybara-screenshot
capybara-selenium capybara-selenium
carrierwave
carrierwave-i18n
chartkick chartkick
chunky_png chunky_png
clamav-client clamav-client
copy_carrierwave_file
daemons daemons
database_cleaner database_cleaner
deep_cloneable deep_cloneable

View file

@ -23,7 +23,6 @@ FOG_OPENSTACK_IDENTITY_API_VERSION=""
FOG_OPENSTACK_REGION="" FOG_OPENSTACK_REGION=""
FOG_DIRECTORY="" FOG_DIRECTORY=""
FOG_ENABLED="" FOG_ENABLED=""
CARRIERWAVE_CACHE_DIR="/tmp/tps-local-cache"
DS_PROXY_URL="" DS_PROXY_URL=""
FC_PARTICULIER_ID="" FC_PARTICULIER_ID=""

View file

@ -42,8 +42,6 @@ defaults: &defaults
openstack_identity_api_version: "<%= ENV['FOG_OPENSTACK_IDENTITY_API_VERSION'] %>" openstack_identity_api_version: "<%= ENV['FOG_OPENSTACK_IDENTITY_API_VERSION'] %>"
openstack_region: <%= ENV['FOG_OPENSTACK_REGION'] %> openstack_region: <%= ENV['FOG_OPENSTACK_REGION'] %>
directory: <%= ENV['FOG_DIRECTORY'] %> directory: <%= ENV['FOG_DIRECTORY'] %>
carrierwave:
cache_dir: <%= ENV['CARRIERWAVE_CACHE_DIR'] %>
mailtrap: mailtrap:
username: <%= ENV['MAILTRAP_USERNAME'] %> username: <%= ENV['MAILTRAP_USERNAME'] %>
password: <%= ENV['MAILTRAP_PASSWORD'] %> password: <%= ENV['MAILTRAP_PASSWORD'] %>
@ -84,8 +82,6 @@ test:
key: api_entreprise_test_key key: api_entreprise_test_key
fog: fog:
directory: tps_dev directory: tps_dev
carrierwave:
cache_dir: /tmp/tps-test-cache
pipedrive: pipedrive:
key: pipedrive_test_key key: pipedrive_test_key
france_connect_particulier: france_connect_particulier:

View file

@ -1,51 +0,0 @@
require Rails.root.join("lib", "tasks", "task_helper")
namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do
task set: :environment do
commentaires_to_process = Commentaire.where(file: nil).where.not(piece_justificative_id: nil).reorder(id: :desc)
rake_puts "#{commentaires_to_process.count} commentaires to process..."
commentaires_to_process.each do |c|
process_commentaire(c)
end
end
task fix: :environment do
commentaires_to_fix = Commentaire.where.not(file: nil).where.not(piece_justificative_id: nil).reorder(id: :desc)
rake_puts "#{commentaires_to_fix.count} commentaires to fix..."
commentaires_to_fix.each do |c|
process_commentaire(c)
end
end
def sanitize_name(name) # from https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/sanitized_file.rb#L323
name = name.gsub(/[^[:word:]\.\-\+]/, "_")
name = "_#{name}" if name.match?(/\A\.+\z/)
name = "unnamed" if name.empty?
return name.mb_chars.to_s
end
def process_commentaire(commentaire)
rake_puts "Processing commentaire #{commentaire.id}"
if commentaire.piece_justificative.present?
# https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location
commentaire.remote_file_url = commentaire.piece_justificative.content_url
if commentaire.piece_justificative.original_filename.present?
commentaire.file.define_singleton_method(:filename) { sanitize_name(commentaire.piece_justificative.original_filename) }
end
if commentaire.body.blank?
commentaire.body = commentaire.piece_justificative.original_filename || "."
end
commentaire.save
if commentaire.file.blank?
rake_puts "Failed to save file for commentaire #{commentaire.id}"
end
end
end
end

View file

@ -1,113 +0,0 @@
require Rails.root.join("lib", "tasks", "task_helper")
namespace :cloudstorage do
task init: :environment do
os_config = (YAML.load_file(Fog.credentials_path))['default']
@os = OpenStack::Connection.create(
{
username: os_config['openstack_username'],
api_key: os_config['openstack_api_key'],
auth_method: "password",
auth_url: "https://auth.cloud.ovh.net/v2.0/",
authtenant_name: os_config['openstack_tenant'],
service_type: "object-store",
region: os_config['openstack_region']
}
)
@cont = @os.container(CarrierWave::Uploader::Base.fog_directory)
end
desc 'Move local attestations on cloud storage'
task migrate: :environment do
puts 'Starting migration'
Rake::Task['cloudstorage:init'].invoke
error_count = 0
[Cerfa, PieceJustificative, Procedure].each do |c|
c.all.each do |entry|
content = (c == Procedure) ? entry.logo : entry.content
if !(content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded'))
secure_token = SecureRandom.uuid
filename = "#{entry.class.to_s.underscore}-#{secure_token}#{File.extname(content.current_path)}"
rake_puts "Uploading #{content.current_path}"
begin
@cont.create_object(filename, {}, File.open(content.current_path))
File.open(File.dirname(content.current_path) + '/uploaded', "w+") { |f| f.write(File.basename(content.current_path)) }
File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "w+") { |f| f.write(filename) }
File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "w+") { |f| f.write(secure_token) }
entry.update_column(c == Procedure ? :logo : :content, filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
rescue Errno::ENOENT
rake_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
if content.current_path.present? && File.exist?(File.dirname(content.current_path) + '/uploaded')
filename = File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read
secure_token = File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "r").read
entry.update_column(c == Procedure ? :logo : :content, filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
rake_puts "RESTORE IN DATABASE: #{filename} "
elsif content.current_path.present?
rake_puts "Skipping #{content.current_path}"
end
end
end
end
rake_puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details."
puts 'Enf of migration'
end
desc 'Clear documents in tenant and revert file entries in database'
task :revert do
Rake::Task['cloudstorage:init'].invoke
[Cerfa, PieceJustificative, Procedure].each do |c|
c.all.each do |entry|
content = (c == Procedure) ? entry.logo : entry.content
if content.current_path.present?
if File.exist?(File.dirname(content.current_path) + '/uploaded')
previous_filename = File.read(File.dirname(content.current_path) + '/uploaded')
entry.update_column(c == Procedure ? :logo : :content, previous_filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, nil)
rake_puts "restoring #{content.current_path} db data to #{previous_filename}"
@cont.delete_object(File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read)
FileUtils.rm(File.dirname(content.current_path) + '/uploaded')
FileUtils.rm(File.dirname(content.current_path) + '/filename_cloudstorage')
FileUtils.rm(File.dirname(content.current_path) + '/secure_token_cloudstorage')
end
end
end
end
end
desc 'Clear old documents in tenant'
task :clear do
Rake::Task['cloudstorage:init'].invoke
@cont.objects.each do |object|
rake_puts "Removing #{object}"
@cont.delete_object(object)
end
end
task :clear_old_objects do
Rake::Task['cloudstorage:init'].invoke
@cont.objects_detail.each do |object, details|
last_modified = Time.zone.parse(details[:last_modified])
@cont.delete_object(object) if last_modified.utc <= (Time.zone.now - 2.years).utc
end
end
end