From e33c97116a1caa71f935dcfceb27b71e81a9271b Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Sat, 6 Oct 2018 15:07:21 -0300 Subject: [PATCH] Add 4.3.0 upgrade script --- version_upgrades/4.3.0/4.3.0.php | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 version_upgrades/4.3.0/4.3.0.php diff --git a/version_upgrades/4.3.0/4.3.0.php b/version_upgrades/4.3.0/4.3.0.php new file mode 100644 index 00000000..d1c92246 --- /dev/null +++ b/version_upgrades/4.3.0/4.3.0.php @@ -0,0 +1,67 @@ +query("SELECT id,profile_pic FROM staff") or die(PHP_EOL . 'Error: profile_pic can\'t be found on `staff` table'. PHP_EOL); +while($staff = $queryResult->fetch_array(MYSQLI_ASSOC)) { + global $filePath; + $id = $staff['id']; + $profilePicFileName = $staff['profile_pic']; + $updatedProfilePicFileName = "p_$profilePicFileName"; + + if(!$profilePicFileName || $profilePicFileName[0] == 'p') continue; + + rename("$filePath/$profilePicFileName", "$filePath/$updatedProfilePicFileName") + or die("Error: could not change file name from $profilePicFileName to $updatedProfilePicFileName"); + + $mysql->query("UPDATE staff SET profile_pic='$updatedProfilePicFileName' WHERE id='$id'") + or die (PHP_EOL . "Error: could not update profile_pic for staff id:$id" . PHP_EOL); +} + +// Change ticket attachments +print '[2/3] Updating ticket attachments...' . PHP_EOL; +function updateTicketFile($ticketNumber, $fileName) { + global $filePath; + $updatedFileName = "t$ticketNumber" . "_$fileName"; + + rename("$filePath/$fileName", "$filePath/$updatedFileName") + or die(PHP_EOL . "Error: could not change file name from $fileName to $updatedFileName" . PHP_EOL); + + return $updatedFileName; +} + +$queryResult = $mysql->query("SELECT id,ticket_number,file FROM ticket"); +while($queryResult && $ticket = $queryResult->fetch_array(MYSQLI_ASSOC)) { + $id = $ticket['id']; + + if(!$ticket['file'] || $ticket['file'][0] == 't') continue; + + $updatedFileName = updateTicketFile($ticket['ticket_number'], $ticket['file']); + + $mysql->query("UPDATE ticket SET file='$updatedFileName' WHERE id='$id'") + or die (PHP_EOL . "Error: could not update file for ticket id:$id" . PHP_EOL); +} + +// Change ticket attachments +print '[3/3] Updating ticketevent attachments...' . PHP_EOL; +$queryResult = $mysql->query("SELECT id,ticket_id,file FROM ticketevent"); +while($queryResult && $ticketEvent = $queryResult->fetch_array(MYSQLI_ASSOC)) { + $id = $ticketEvent['id']; + $ticketId = $ticketEvent['ticket_id']; + $ticketQuery = $mysql->query("SELECT ticket_number FROM ticket WHERE id='$ticketId'") or die(PHP_EOL . "Error: could not find ticket id:$id" . PHP_EOL); + $ticketNumber = $ticketQuery->fetch_array()[0]; + + if(!$ticketEvent['file'] || $ticketEvent['file'][0] == 't') continue; + + $updatedFileName = updateTicketFile($ticketNumber, $ticketEvent['file']); + + $mysql->query("UPDATE ticketevent SET file='$updatedFileName' WHERE id='$id'") + or die (PHP_EOL . "Error: could not update file for ticketevent id:$id" . PHP_EOL); +} + +print 'Update Completed!' . PHP_EOL;