Fixed issue #1395 - Ticket chaos after updating to from Zammad 1.5 to 2.1 (develop branch) - Macros and Taskbar are damaged.
This commit is contained in:
parent
553dcef3db
commit
6273a7213e
5 changed files with 125 additions and 0 deletions
|
@ -47,6 +47,7 @@ class Taskbar < ApplicationModel
|
|||
|
||||
def set_user
|
||||
return true if local_update
|
||||
return true if !UserInfo.current_user_id
|
||||
self.user_id = UserInfo.current_user_id
|
||||
end
|
||||
|
||||
|
|
17
db/migrate/20170910000001_fixed_store_upgrade_45.rb
Normal file
17
db/migrate/20170910000001_fixed_store_upgrade_45.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class FixedStoreUpgrade45 < ActiveRecord::Migration[5.0]
|
||||
def up
|
||||
|
||||
# return if it's a new setup
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
Cache.clear
|
||||
[Macro, Taskbar, Calendar, Trigger, Channel, Job, PostmasterFilter, Report::Profile, Setting, Sla, Template].each do |class_name|
|
||||
class_name.all.each do |record|
|
||||
begin
|
||||
record.save!
|
||||
rescue => e
|
||||
Rails.logger.error "Unable to save/update #{class_name}.find(#{record.id}): #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/core_ext/active_record/store/indifferent_coder.rb
Normal file
24
lib/core_ext/active_record/store/indifferent_coder.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Rails 5.0 has changed to only store and read ActiveSupport::HashWithIndifferentAccess from stores
|
||||
# we extended lib/core_ext/active_record/store/indifferent_coder.rb to read also ActionController::Parameters
|
||||
# and convert them to ActiveSupport::HashWithIndifferentAccess for migration in db/migrate/20170910000001_fixed_store_upgrade_45.rb.
|
||||
require 'active_record/store'
|
||||
module ActiveRecord
|
||||
module Store
|
||||
class IndifferentCoder
|
||||
def self.as_indifferent_hash(obj)
|
||||
case obj
|
||||
# re-enable using ActionController::Parameters in stores
|
||||
when ActionController::Parameters
|
||||
obj.permit!.to_h
|
||||
# /re-enable using ActionController::Parameters in stores
|
||||
when ActiveSupport::HashWithIndifferentAccess
|
||||
obj
|
||||
when Hash
|
||||
obj.with_indifferent_access
|
||||
else
|
||||
ActiveSupport::HashWithIndifferentAccess.new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -61,6 +61,7 @@ class ActiveSupport::TestCase
|
|||
ActivityStream.destroy_all
|
||||
PostmasterFilter.destroy_all
|
||||
Ticket.destroy_all
|
||||
Taskbar.destroy_all
|
||||
|
||||
# reset settings
|
||||
Setting.all.pluck(:name).each { |name|
|
||||
|
|
82
test/unit/migration_ror_42_to50_store_test.rb
Normal file
82
test/unit/migration_ror_42_to50_store_test.rb
Normal file
|
@ -0,0 +1,82 @@
|
|||
# encoding: utf-8
|
||||
# Rails 5.0 has changed to only store and read ActiveSupport::HashWithIndifferentAccess from stores
|
||||
# we extended lib/core_ext/active_record/store/indifferent_coder.rb to read also ActionController::Parameters
|
||||
# and convert them to ActiveSupport::HashWithIndifferentAccess for migration in db/migrate/20170910000001_fixed_store_upgrade_45.rb.
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class MigrationRor42To50StoreTest < ActiveSupport::TestCase
|
||||
test 'store with ActionController::Parameters object - get ActiveSupport::HashWithIndifferentAccess' do
|
||||
|
||||
user = User.last
|
||||
last_contact = '2017-09-01 10:10:00'
|
||||
state = "--- !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements:
|
||||
ticket: !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements: {}
|
||||
ivars:
|
||||
:@permitted: false
|
||||
article: !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements: {}
|
||||
ivars:
|
||||
:@permitted: false
|
||||
ivars:
|
||||
:@permitted: false
|
||||
"
|
||||
params = "--- !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements:
|
||||
ticket_id: 1234
|
||||
shown: true
|
||||
ivars:
|
||||
:@permitted: false
|
||||
"
|
||||
preferences = "--- !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements:
|
||||
tasks: &1
|
||||
- !ruby/hash-with-ivars:ActionController::Parameters
|
||||
elements:
|
||||
id: 99282
|
||||
user_id: 85370
|
||||
last_contact: 2017-09-08 11:28:00.289663000 Z
|
||||
changed: true
|
||||
ivars:
|
||||
:@permitted: false
|
||||
ivars:
|
||||
:@permitted: false
|
||||
:@converted_arrays: !ruby/object:Set
|
||||
hash:
|
||||
*1: true
|
||||
"
|
||||
sql = "INSERT INTO taskbars (`user_id`, `client_id`, `key`, `callback`, `state`, `params`, `prio`, `notify`, `active`, `preferences`, `last_contact`, `updated_at`, `created_at`) VALUES (#{user.id}, '123', 'Ticket-123', 'TicketZoom', '#{state}', '#{params}', 1, FALSE, TRUE, '#{preferences}', '#{last_contact}', '#{last_contact}', '#{last_contact}')"
|
||||
if ActiveRecord::Base.connection_config[:adapter] != 'mysql2'
|
||||
sql.delete!('`')
|
||||
end
|
||||
records_array = ActiveRecord::Base.connection.execute(sql)
|
||||
|
||||
taskbar = Taskbar.last
|
||||
assert(taskbar)
|
||||
assert(taskbar.params)
|
||||
assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.params.class)
|
||||
assert_equal(1234, taskbar.params[:ticket_id])
|
||||
assert(taskbar.state)
|
||||
assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.state.class)
|
||||
assert(taskbar.state[:ticket].blank?)
|
||||
assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:ticket].class)
|
||||
assert(taskbar.state[:article].blank?)
|
||||
assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:article].class)
|
||||
|
||||
taskbar.save!
|
||||
taskbar.reload
|
||||
assert(taskbar)
|
||||
assert(taskbar.params)
|
||||
assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.params.class)
|
||||
assert_equal(1234, taskbar.params[:ticket_id])
|
||||
assert(taskbar.state)
|
||||
assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.state.class)
|
||||
assert(taskbar.state[:ticket].blank?)
|
||||
assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:ticket].class)
|
||||
assert(taskbar.state[:article].blank?)
|
||||
assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:article].class)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue