From 96fb303b7e8dada0f200c752114b62bab56300b3 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 23 May 2015 02:41:29 +0200 Subject: [PATCH] Added also channel support, remove auto_wizard file after auto wizard has been done. --- contrib/auto_wizard_example.json | 15 +++++++++++++++ lib/auto_wizard.rb | 24 ++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/contrib/auto_wizard_example.json b/contrib/auto_wizard_example.json index 5c488c104..0987e2fbe 100644 --- a/contrib/auto_wizard_example.json +++ b/contrib/auto_wizard_example.json @@ -25,6 +25,7 @@ ], "EmailAddresses": [ { + "id": 1, "realname": "Zammad Demo System", "email": "zammad_demo@localhost" } @@ -33,5 +34,19 @@ { "name": "Demo Organization" } + ], + "Channels": [ + { + "area": "Email::Inbound", + "adapter": "IMAP", + "group_id": 1, + "options": { + "host": "mx1.example.com", + "user": "some user", + "password": "some pw", + "ssl": true + }, + "active":false + } ] } diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 77e8c13cb..6a1ddcdf8 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -48,7 +48,7 @@ returns } ) - Organization.create_if_not_exists( + Organization.create_or_update( organization_data_symbolized ) } @@ -103,12 +103,32 @@ returns } ) - EmailAddress.create_if_not_exists( + EmailAddress.create_or_update( email_address_data_symbolized ) } end + # create Channels + if auto_wizard_hash['Channels'] + auto_wizard_hash['Channels'].each { |channel_data| + + channel_data_symbolized = channel_data.symbolize_keys.merge( + { + updated_by_id: admin_user.id, + created_by_id: admin_user.id + } + ) + + Channel.create( + channel_data_symbolized + ) + } + end + + # remove auto wizard file + FileUtils.rm auto_wizard_file_location + admin_user end end