smarter logic for dups
This commit is contained in:
@@ -23,11 +23,14 @@ class Upload < ActiveRecord::Base
|
|||||||
# Because uploads are processed serially, there's no race condition here.
|
# Because uploads are processed serially, there's no race condition here.
|
||||||
def validate_md5_uniqueness
|
def validate_md5_uniqueness
|
||||||
md5_post = Post.find_by_md5(md5)
|
md5_post = Post.find_by_md5(md5)
|
||||||
merge_tags(md5_post) if md5_post
|
if md5_post
|
||||||
|
merge_tags(md5_post)
|
||||||
|
update_attribute(:status, "duplicate: #{post.id}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_file_exists
|
def validate_file_exists
|
||||||
unless File.exists?(file_path)
|
unless file_path && File.exists?(file_path)
|
||||||
raise "file does not exist"
|
raise "file does not exist"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -106,7 +109,6 @@ class Upload < ActiveRecord::Base
|
|||||||
def merge_tags(post)
|
def merge_tags(post)
|
||||||
post.tag_string += " #{tag_string}"
|
post.tag_string += " #{tag_string}"
|
||||||
post.save
|
post.save
|
||||||
update_attribute(:status, "duplicate: #{post.id}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -293,6 +295,14 @@ class Upload < ActiveRecord::Base
|
|||||||
def is_completed?
|
def is_completed?
|
||||||
status == "completed"
|
status == "completed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_duplicate?
|
||||||
|
status =~ /duplicate/
|
||||||
|
end
|
||||||
|
|
||||||
|
def duplicate_post_id
|
||||||
|
@duplicate_post_id ||= status[/duplicate: (\d+)/, 1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module UploaderMethods
|
module UploaderMethods
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
<p>This upload is waiting to be processed. Please wait a few seconds.</p>
|
<p>This upload is waiting to be processed. Please wait a few seconds.</p>
|
||||||
<% elsif @upload.is_processing? %>
|
<% elsif @upload.is_processing? %>
|
||||||
<p>This upload is being processed. Please wait a few seconds.</p>
|
<p>This upload is being processed. Please wait a few seconds.</p>
|
||||||
|
<% elsif @upload.is_duplicate? %>
|
||||||
|
<p>This upload is a duplicate: post #<%= link_to @upload.duplicate_post_id, post_path(@upload.duplicate_post_id) %></p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>An error occurred: <%= @upload.status %></p>
|
<p>An error occurred: <%= @upload.status %></p>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user