add tag correction support
This commit is contained in:
16
app/controllers/tag_corrections_controller.rb
Normal file
16
app/controllers/tag_corrections_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class TagCorrectionsController < ApplicationController
|
||||
before_filter :member_only
|
||||
|
||||
def new
|
||||
@tag = Tag.find(params[:tag_id])
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:commit] == "Fix"
|
||||
@tag = Tag.find(params[:tag_id])
|
||||
@tag.delay.fix_post_count
|
||||
end
|
||||
|
||||
redirect_to tags_path(:search => {:name_matches => @tag.name})
|
||||
end
|
||||
end
|
||||
@@ -587,6 +587,15 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module CountMethods
|
||||
def fix_post_counts
|
||||
post.set_tag_counts
|
||||
post.update_column(:tag_count, post.tag_count)
|
||||
post.update_column(:tag_count_general, post.tag_count_general)
|
||||
post.update_column(:tag_count_artist, post.tag_count_artist)
|
||||
post.update_column(:tag_count_copyright, post.tag_count_copyright)
|
||||
post.update_column(:tag_count_character, post.tag_count_character)
|
||||
end
|
||||
|
||||
def get_count_from_cache(tags)
|
||||
count = Cache.get(count_cache_key(tags))
|
||||
|
||||
|
||||
@@ -41,8 +41,12 @@ class Tag < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def real_post_count
|
||||
Post.raw_tag_match(name).count
|
||||
end
|
||||
|
||||
def fix_post_count
|
||||
update_column(:post_count, Post.raw_tag_match(name).count)
|
||||
update_column(:post_count, real_post_count)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
8
app/views/tag_corrections/new.html.erb
Normal file
8
app/views/tag_corrections/new.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<h1>Fix Tag</h1>
|
||||
|
||||
<p>You can fix the post count for this tag. It will update it from <%= @tag.post_count %> to <%= @tag.real_post_count %>.</p>
|
||||
|
||||
<%= form_tag(tag_correction_path(:tag_id => @tag.id)) do %>
|
||||
<%= submit_tag "Fix" %>
|
||||
<%= submit_tag "Cancel" %>
|
||||
<% end %>
|
||||
@@ -7,6 +7,7 @@
|
||||
<% if @tag %>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Edit", edit_tag_path(@tag) %></li>
|
||||
<li><%= link_to "Fix", new_tag_correction_path(:tag_id => @tag.id) %></li>
|
||||
<% end %>
|
||||
</menu>
|
||||
<% end %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<%= simple_form_for(@tag) do |f| %>
|
||||
<%= f.input :category, :collection => Danbooru.config.canonical_tag_category_mapping.to_a, :include_blank => false %>
|
||||
<%= f.button :submit %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
<%= link_to("?", wiki_pages_path(:title => tag.name)) %>
|
||||
<%= link_to(tag.name, posts_path(:tags => tag.name)) %>
|
||||
</td>
|
||||
<td><%= link_to "edit", edit_tag_path(tag) %></td>
|
||||
<td>
|
||||
<%= link_to "edit", edit_tag_path(tag) %>
|
||||
| <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -156,12 +156,13 @@ Danbooru::Application.routes.draw do
|
||||
end
|
||||
resource :source, :only => [:show]
|
||||
resources :tags do
|
||||
resource :correction, :only => [:new, :create], :controller => "TagCorrections"
|
||||
collection do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :tag_aliases do
|
||||
resource :correction, :only => [:new, :create, :show], :controller => "TagAliasCorrections"
|
||||
resource :correction, :only => [:create, :new, :show], :controller => "TagAliasCorrections"
|
||||
member do
|
||||
post :approve
|
||||
end
|
||||
@@ -169,7 +170,6 @@ Danbooru::Application.routes.draw do
|
||||
get :general_search
|
||||
end
|
||||
end
|
||||
resource :tag_alias_correction, :only => [:new, :create, :show]
|
||||
resource :tag_alias_request, :only => [:new, :create]
|
||||
resources :tag_implications do
|
||||
member do
|
||||
|
||||
Reference in New Issue
Block a user