History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: CHD-921
Type: Task Task
Status: Open Open
Assignee: Unassigned
Reporter: Joe Geck
Votes: 7
Watchers: 6
Operations

Clone this issue
If you were logged in you would be able to see more operations.
Cerberus Helpdesk

[Imp/Exp] Add support for customer custom fields

Created: 14/Nov/08 07:58 PM   Updated: 26/Jan/11 11:19 PM
Fix Version/s: Catch and Release

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Value: 2 - Significant Value


 Description   
Summary:
[[quote]]
Our company has a license for Cerberus 3.x. We'd really like to upgrade to Cerberus 4, but the one thing that has been holding us back is the inability to transfer over Custom Field information. This is critical to us, as we store customer server information in there, to easily recognize them upon receiving a ticket.

I've emailed about this before and was told there was currently no tool for this, but I wanted to know if you have any way of doing this now. Please let me know what our options would be regarding this.
[[/quote]]

 All   Comments   Work Log   Change History      Sort Order:
Comment by Adam Johnson [04/Jan/10 11:27 AM]
I've been looking into migrating from 3.6 to 4.x on and off since 4.0 first came out. I'm pretty close at this point. I managed to migrate our custom field data, but it was a quick and dirty method. over the years (we started using Cerberus at v.1.3) we had various custom fields, some of which we no longer care about, so I was only migrating fields who's field ID was > 10 - I also created a bunch of contact custom fields we're now importing from Active Directory (via a CGI script which uses LDAP and exports CSV), so I don't need/want to migrate those fields. I also had to decide if the new custom fields would be Global or group based. I made them global for our case, but perhaps I'll rethink that and make them group. Logically for us, they should probably be bucket-based, but that's not available at this version, so...

I did make sure to create the new custom fields in the same order as the old ones by ID number, so all I had to do was subtract 2 from the old field_id value to map to the new custom fields' IDs. If you want to try this script, you'll have to adjust the "WHERE v.field_id > 10" clause, and the "SELECT v.field_id - 2 AS field_id" clauses to match your mapping requirements, but here it is in a few variables, a couple password prompts, and one long 4-pipe shell command:

Another warning - I ended up combing through the schema in 4 to find which tables to delete all rows from, and which sequences to reset so I could re-import everything without having to set up all the agent accounts, custom fields, groups, etc. - and I've had to do so often while developing this script. I've also cleaned out soem site-specific usernames and such and have not tested it since I did so. Caveat Emptor

Oh yeah, all my custom fields were stringvalue ones - this gets harder if they have different types as well. I'm using a temp table, because I couldn't figure out another way to map the old ticket id's through the masks to the new ticket ID's in one pass, since the ID's only exist in their own databases.

#------------- cut here ------------------

echo "Migrating custom field data from cerb3 instance to cerb4 instance"
echo "Assuming field_id from cerb3 is just 2 higher than corresponding "
echo "field_ids in cerb4. If not, adjust script for your environment "
echo

# hosts to connect to via mysql command line utility. include -h, or
# leave blank for localhost

CERB3HOST="-h cerb3server"
CERB4HOST=

CERB3USER=cerb3dbuser
CERB4USER=cerb4dbuser

CERB3DB=cerb3
CERB4DB=cerb4

TEMPHN=${CERB3HOST?localhost}
CERB3HPROMPT=${TEMPHN#-h}

TEMPHN=${CERB4HOST?localhost}
CERB4HPROMPT=${TEMPHN#-h}

read -s -p "MySQL password for $CERB3USER on $CERB3HPROMPT: " T3PWD
echo
read -s -p "MySQL password for $CERB4USER on $CERB4HPROMPT: " T4PWD
echo

echo 'SELECT v.field_id - 2 AS field_id,
             t.ticket_mask,
             v.field_value,
             "cerberusweb.fields.source.ticket" AS source_extension
      FROM field_group_values as v JOIN ticket as t ON (v.entity_index = t.ticket_id)
      WHERE v.field_id > 10
      ORDER BY v.entity_index;' \
 | mysql $CERB3HOST -u $CERB3USER --password=$T3PWD $CERB3DB \
 | awk -F'\t' 'BEGIN {print "DROP TABLE IF EXISTS temp_stringvalue;";
                      print "CREATE TEMPORARY TABLE temp_stringvalue (field_id INT(11), mask VARCHAR(30), field_value VARCHAR(255), source_extension VARCHAR(255));";
                     }
                   {print "insert into temp_stringvalue values (" $1 ", \""$2"\", \"" $3 "\", \"" $4 "\");"}
               END {print "INSERT INTO custom_field_stringvalue \
                           SELECT v.field_id, t.id, v.field_value, v.source_extension \
                             FROM temp_stringvalue AS v \
                             JOIN ticket AS t \
                               ON (v.mask = t.mask);"}' \
 | mysql $CERB4HOST -u $CERB4USER --password=$T4PWD $CERB4DB

#----------------------- cut here -------------------