Commit 08a13702e78704652eda61a4cef68c0936297b49
1 parent
da0185d8
Exists in
master
and in
22 other branches
Added migration to fix images paths on action trackers
(ActionItem1841)
Showing
2 changed files
with
37 additions
and
1 deletions
Show diff stats
db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb
0 → 100644
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +class RenameImagesPathOnTrackedActions < ActiveRecord::Migration | ||
2 | + | ||
3 | + def self.up | ||
4 | + select_all("SELECT id, verb, params FROM action_tracker WHERE verb IN ('new_friendship', 'join_community', 'leave_community')").each do |tracker| | ||
5 | + if tracker['verb'] == 'new_friendship' | ||
6 | + param_name = 'friend_profile_custom_icon' | ||
7 | + else | ||
8 | + param_name = 'resource_profile_custom_icon' | ||
9 | + end | ||
10 | + | ||
11 | + params = YAML.load(tracker['params']) | ||
12 | + paths = [] | ||
13 | + params[param_name].each do |image_path| | ||
14 | + paths << self.rename_path(image_path) unless image_path.nil? | ||
15 | + end | ||
16 | + params[param_name] = paths | ||
17 | + | ||
18 | + execute(ActiveRecord::Base.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']])) | ||
19 | + end | ||
20 | + end | ||
21 | + | ||
22 | + def self.down | ||
23 | + say('Nothing to undo') | ||
24 | + end | ||
25 | + | ||
26 | + class << self | ||
27 | + def rename_path(old_path) | ||
28 | + if old_path =~ /^\/images\/0/ | ||
29 | + old_path.gsub(/^\/images\//, "/image_uploads/") | ||
30 | + else | ||
31 | + old_path | ||
32 | + end | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 20110202141024) do | 12 | +ActiveRecord::Schema.define(:version => 20110203160153) do |
13 | 13 | ||
14 | create_table "action_tracker", :force => true do |t| | 14 | create_table "action_tracker", :force => true do |t| |
15 | t.integer "user_id" | 15 | t.integer "user_id" |