Skip to content

Instantly share code, notes, and snippets.

@jezuk
Created February 21, 2014 11:05
Show Gist options
  • Save jezuk/9132513 to your computer and use it in GitHub Desktop.
Save jezuk/9132513 to your computer and use it in GitHub Desktop.
Migrate a custom text field from osTicket 1.6 to 1.8
-- jezuk @ http://osticket.com/forum/profile/120676/jezuk
-- You must change all references to `vessel` with your own source column name from ost_ticket
CREATE PROCEDURE `ost_cf_migrate`()
BEGIN
DECLARE my_form_id INT DEFAULT 2; -- form_id taken from ost_form_field
DECLARE my_field_id INT DEFAULT 14; -- id taken from ost_form_field
DECLARE my_object_type CHAR DEFAULT "T"; -- field type (ticket)
DECLARE this_ticket_id INT;
DECLARE my_field_data CHAR(255);
DECLARE new_entry_id INT;
DECLARE created_datetime DATETIME;
DECLARE updated_datetime DATETIME;
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) INTO n FROM `ost_ticket` WHERE `vessel` IS NOT NULL AND `vessel` != '';
SET i=0;
WHILE i<n DO
SELECT `ticket_id`, `vessel`, `created`, `updated` INTO this_ticket_id, my_field_data, created_datetime, updated_datetime
FROM `ost_ticket`
WHERE `vessel` IS NOT NULL AND `vessel` != '' LIMIT i,1;
INSERT INTO `ost_form_entry` SET
`form_id` = my_form_id,
`object_id` = this_ticket_id,
`object_type` = my_object_type,
`created` = created_datetime,
`updated` = updated_datetime;
SELECT LAST_INSERT_ID() INTO new_entry_id;
INSERT INTO `ost_form_entry_values` SET
`entry_id` = new_entry_id,
`field_id` = my_field_id,
`value` = my_field_data;
SET i = i + 1;
END WHILE;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment