Skip to content

Instantly share code, notes, and snippets.

@isabelc
Last active August 29, 2015 13:56
Show Gist options
  • Save isabelc/8829632 to your computer and use it in GitHub Desktop.
Save isabelc/8829632 to your computer and use it in GitHub Desktop.
Migrate tickets from "wpsc Support Tickets" to "Email Support Tickets" plugin. This script should only be run BEFORE any new tickets in the new plugin are created. So, run immediately upon installing Email Support Tickets. STEPS: 1. Paste the following PHP script into a blank file. 2. Edit line three to replace YOUR_DB_HOST, YOUR_DB_NAME, YOUR_D…
<?php
$db = new PDO('mysql:host=YOUR_DB_HOST;dbname=YOUR_DB_NAME', 'YOUR_DB_USERNAME', 'YOUR_DB_PASSWORD', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,));
// Tickets table
$row = array();
$table1 = "SELECT `primkey`, `title`, `initial_message`, `user_id`, `email`, `assigned_to`, `severity`, `resolution`, `time_posted`, `last_updated`, `last_staff_reply`, `target_response_time`, `type` FROM `wp_wpscst_tickets`";
$result = $db->query($table1);
$row = $result->fetchAll(); // this array holds my incoming data
$stmt = $db->prepare('INSERT IGNORE INTO `wp_emailst_tickets` (`primkey`, `title`, `initial_message`, `user_id`, `email`, `assigned_to`, `severity`, `resolution`, `time_posted`, `last_updated`, `last_staff_reply`, `target_response_time`, `type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)');
foreach ($row as $justone) {
$count = $stmt->execute(array($justone[0], $justone[1], $justone[2], $justone[3], $justone[4], $justone[5], $justone[6], $justone[7], $justone[8], $justone[9], $justone[10], $justone[11], $justone[12]));
}
$numAffected = count($row);
$new_index = $numAffected + 1;
$alter_table = $db->query( "ALTER TABLE `wp_emailst_tickets` AUTO_INCREMENT=$new_index" );
// Replies table
$row_table2 = array();
$table2 = "SELECT `primkey`, `ticket_id`, `user_id`, `timestamp`, `message` FROM `wp_wpscst_replies`";
$result_table2 = $db->query($table2);
$row_table2 = $result_table2->fetchAll(); // this array holds my incoming data
$stmt_table2 = $db->prepare('INSERT IGNORE INTO `wp_emailst_replies` (`primkey`, `ticket_id`, `user_id`, `timestamp`, `message`) VALUES (?,?,?,?,?)');
foreach ($row_table2 as $justone_table2) {
$count_table2 = $stmt_table2->execute(array($justone_table2[0], $justone_table2[1], $justone_table2[2], $justone_table2[3], $justone_table2[4]));
}
$numAffected_table2 = count($row_table2);
$new_index_table2 = $numAffected_table2 + 1;
$alter_table2 = $db->query( "ALTER TABLE `wp_emailst_replies` AUTO_INCREMENT=$new_index_table2" );
echo 'Inserted this many rows into wp_emailst_tickets table: '.$numAffected . '<br />The AUTO_INCREMENT index for the tickets table is set to ' . $new_index . '<br /><br />Inserted this many rows into the replies table: ' . $numAffected_table2 . '<br />The AUTO_INCREMENT index for the replies table is set to ' . $new_index_table2;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment