From 7427833de6fd1b39bc032de5d2a80f0531a26c7d Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 18 Sep 2013 17:59:38 -0700 Subject: [PATCH] fixes #1987 --- script/fixes/017_fix_md5.rb | 21 +++++++++++++++++++++ script/fixes/018_fix_md5.rb | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 script/fixes/017_fix_md5.rb create mode 100644 script/fixes/018_fix_md5.rb diff --git a/script/fixes/017_fix_md5.rb b/script/fixes/017_fix_md5.rb new file mode 100644 index 000000000..afb861cc7 --- /dev/null +++ b/script/fixes/017_fix_md5.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") + +# This should be run on both servers to rename the file locally +Post.where("id in (?)", Pool.find(203).post_id_array).find_each do |post| + correct_md5 = Digest::MD5.file(post.file_path).hexdigest + + if post.is_image? + if post.has_large? + FileUtils.mv(post.large_path, post.large_path.sub(post.md5, correct_md5)) + end + + FileUtils.mv(post.real_preview_file_path, post.real_preview_file_path.sub(post.md5, correct_md5)) + FileUtils.mv(post.ssd_preview_file_path, post.ssd_preview_file_path.sub(post.md5, correct_md5)) + end + + FileUtils.mv(post.file_path, post.file_path.sub(post.md5, correct_md5)) +end diff --git a/script/fixes/018_fix_md5.rb b/script/fixes/018_fix_md5.rb new file mode 100644 index 000000000..1d1a99189 --- /dev/null +++ b/script/fixes/018_fix_md5.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") + +Post.where("id in (?)", Pool.find(203).post_id_array).find_each do |post| + correct_md5 = Digest::MD5.file(post.file_path).hexdigest + post.update_attribute(:md5, correct_md5) +end