diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6a19f00d9..2a2eb0574 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -61,6 +61,12 @@ class UsersController < ApplicationController @user.update_cache render :nothing => true end + + def restore_uploaded_tags + @user = User.find(params[:id]) + importer = UploadedTagsImporter.new(@user) + importer.import! + end private def check_privilege(user) diff --git a/app/logical/uploaded_tags_importer.rb b/app/logical/uploaded_tags_importer.rb new file mode 100644 index 000000000..349d72db9 --- /dev/null +++ b/app/logical/uploaded_tags_importer.rb @@ -0,0 +1,20 @@ +class UploadedTagsImporter + attr_reader :user + + def initialize(user) + @user = user + end + + def import! + row = connection.exec("SELECT uploaded_tags FROM users WHERE id = #{user.id}").first + if row + user.update_attribute(:favorite_tags, row["uploaded_tags"]) + end + connection.close + rescue Exception + end + + def connection + @connection ||= PGconn.connect(:dbname => "danbooru", :host => "dbserver", :user => "albert") + end +end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 542c43342..0af874c8a 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -12,7 +12,13 @@ <%= f.input :default_image_size, :hint => "Large is #{Danbooru.config.large_image_width} pixels wide, and original is whatever the original image is", :collection => %w(large original), :include_blank => false %> <%= f.input :enable_post_navigation, :as => :select, :include_blank => false, :label => "Enable keyboard shortcuts" %> <%= f.input :new_post_navigation_layout, :as => :select, :label => "Pool links", :include_blank => false, :collection => [["Bottom", "true"], ["Top", "false"]], :hint => "When browsing pools, where do you want the navigation links to be placed?" %> - <%= f.input :favorite_tags, :hint => "A list of whitespace delimited tags that show up in your profile", :input_html => {:size => "40x5"} %> + +
+ + + A list of whitespace delimited tags that show up in your profile. <%= link_to "Restore from old database", restore_uploaded_tags_user_path(@user), :method => :post, :remote => true %> +
+ <%= f.input :blacklisted_tags, :hint => "A list of newline delimited tags that you never want to see", :input_html => {:size => "40x5"} %> diff --git a/app/views/users/restore_uploaded_tags.js.erb b/app/views/users/restore_uploaded_tags.js.erb new file mode 100644 index 000000000..cc3d6d145 --- /dev/null +++ b/app/views/users/restore_uploaded_tags.js.erb @@ -0,0 +1 @@ +$("#favorite_tags").val(<%= raw @user.favorite_tags.to_json %>); diff --git a/config/routes.rb b/config/routes.rb index 58e5784e7..6d125ea72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -187,6 +187,7 @@ Danbooru::Application.routes.draw do member do delete :cache post :upgrade + post :restore_uploaded_tags end end resources :user_feedbacks