Skip to content
Snippets Groups Projects
Commit fc82978a authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge remote-tracking branch 'jared/feature/upgrader-revisited' into feature/upgrader-revisited

parents ef8124ea 8deac644
Branches
Tags
No related merge requests found
...@@ -34,6 +34,25 @@ Follow the usual install instructions (beginning from Manual Installation ...@@ -34,6 +34,25 @@ Follow the usual install instructions (beginning from Manual Installation
above), except, don't delete the setup/ folder. For this reason, such an above), except, don't delete the setup/ folder. For this reason, such an
installation is not recommended for a public-facing support system. installation is not recommended for a public-facing support system.
Upgrading
---------
osTicket supports upgrading from 1.6-rc1 and later versions. As with any
upgrade, strongly consider a backup of your attachment files, database, and
osTicket codebase before embarking on an upgrade.
To trigger the update process, fetch the osTicket-1.7 tarball from either
the osTicket [github](http://github.com/osTicket/osTicket-1.7) page or from
the osTicket website. Extract the tarball into the folder of you osTicket
codebase. This can also be accomplished with the zip file, and a FTP client
can of course be used to upload the new source code to your server.
Any way you choose your adventure, when you have your codebase upgraded to
osTicket-1.7, visit the /scp page of you ticketing system. The upgrader will
be presented and will walk you through the rest of the process. (The couple
clicks needed to go through the process are pretty boring to describe).
View the UPGRADING.txt file for other todo items to complete your upgrade.
Help Help
---- ----
Visit the [wiki](http://osticket.com/wiki/Home) or the Visit the [wiki](http://osticket.com/wiki/Home) or the
......
...@@ -172,10 +172,18 @@ class AttachmentFile { ...@@ -172,10 +172,18 @@ class AttachmentFile {
.',type='.db_input($file['type']) .',type='.db_input($file['type'])
.',size='.db_input($file['size']) .',size='.db_input($file['size'])
.',name='.db_input($file['name']) .',name='.db_input($file['name'])
.',hash='.db_input($file['hash']) .',hash='.db_input($file['hash']);
.',filedata='.db_input($file['data']);
return db_query($sql)?db_insert_id():0; if (!(db_query($sql) && ($id=db_insert_id())))
return false;
foreach (str_split($file['data'], 1024*100) as $chunk) {
if (!db_query('UPDATE '.FILE_TABLE.' SET filedata = CONCAT(filedata,'
.db_input($chunk).') WHERE id='.db_input($id)))
# Remove partially uploaded file contents
return false;
}
return $id;
} }
/* Static functions */ /* Static functions */
......
...@@ -114,7 +114,7 @@ class AttachmentMigrater { ...@@ -114,7 +114,7 @@ class AttachmentMigrater {
*/ */
function do_batch($time=30, $max=0) { function do_batch($time=30, $max=0) {
if(!$this->queueAttachments() || !$this->getQueueLength()) if(!$this->queueAttachments($max) || !$this->getQueueLength())
return 0; return 0;
$count = 0; $count = 0;
...@@ -123,7 +123,7 @@ class AttachmentMigrater { ...@@ -123,7 +123,7 @@ class AttachmentMigrater {
if($this->next() && $max && ++$count>=$max) if($this->next() && $max && ++$count>=$max)
break; break;
return $this->queueAttachments(); return $this->queueAttachments($max);
} }
...@@ -131,7 +131,7 @@ class AttachmentMigrater { ...@@ -131,7 +131,7 @@ class AttachmentMigrater {
return $this->skipList; return $this->skipList;
} }
function queue($fileinfo) { function enqueue($fileinfo) {
$this->queue[] = $fileinfo; $this->queue[] = $fileinfo;
} }
...@@ -159,8 +159,14 @@ class AttachmentMigrater { ...@@ -159,8 +159,14 @@ class AttachmentMigrater {
} }
# Get the mime/type of each file # Get the mime/type of each file
# XXX: Use finfo_buffer for PHP 5.3+ # XXX: Use finfo_buffer for PHP 5.3+
if(function_exists('mime_content_type')) //XXX: function depreciated in newer versions of PHP!!!!! if(function_exists('mime_content_type')) {
//XXX: function depreciated in newer versions of PHP!!!!!
$info['type'] = mime_content_type($info['path']); $info['type'] = mime_content_type($info['path']);
} elseif (function_exists('finfo_file')) { // PHP 5.3.0+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$info['type'] = finfo_file($finfo, $info['path']);
}
# TODO: Add extension-based mime-type lookup
if (!($fileId = AttachmentFile::save($info))) { if (!($fileId = AttachmentFile::save($info))) {
return $this->skip($info['attachId'], return $this->skip($info['attachId'],
...@@ -194,8 +200,8 @@ class AttachmentMigrater { ...@@ -194,8 +200,8 @@ class AttachmentMigrater {
$sql='SELECT attach_id, file_name, file_key, Ti.created' $sql='SELECT attach_id, file_name, file_key, Ti.created'
.' FROM '.TICKET_ATTACHMENT_TABLE.' TA' .' FROM '.TICKET_ATTACHMENT_TABLE.' TA'
.' JOIN '.TICKET_TABLE.' Ti ON Ti.ticket_id=TA.ticket_id' .' INNER JOIN '.TICKET_TABLE.' Ti ON (Ti.ticket_id=TA.ticket_id)'
.' WHERE NOT file_id '; //XXX: ignore orphaned attachments? .' WHERE NOT file_id ';
if(($skipList=$this->getSkipList())) if(($skipList=$this->getSkipList()))
$sql.= ' AND attach_id NOT IN('.implode(',', db_input($skipList)).')'; $sql.= ' AND attach_id NOT IN('.implode(',', db_input($skipList)).')';
...@@ -253,10 +259,10 @@ class AttachmentMigrater { ...@@ -253,10 +259,10 @@ class AttachmentMigrater {
# anyway. # anyway.
$info['size'] = @filesize($info['path']); $info['size'] = @filesize($info['path']);
# Coroutines would be nice .. # Coroutines would be nice ..
$this->queue($info); $this->enqueue($info);
} }
return $this->getQueueLength(); return $this->queueAttachments($limit);
} }
function skip($attachId, $error) { function skip($attachId, $error) {
......
...@@ -67,10 +67,13 @@ class osTicketSession { ...@@ -67,10 +67,13 @@ class osTicketSession {
function write($id, $data){ function write($id, $data){
global $thisstaff; global $thisstaff;
$ttl = ($this && get_class($this) == 'osTicketSession')
? $this->getTTL() : SESSION_TTL;
$sql='REPLACE INTO '.SESSION_TABLE.' SET session_updated=NOW() '. $sql='REPLACE INTO '.SESSION_TABLE.' SET session_updated=NOW() '.
',session_id='.db_input($id). ',session_id='.db_input($id).
',session_data='.db_input($data). ',session_data='.db_input($data).
',session_expire=(NOW() + INTERVAL '.$this->getTTL().' SECOND)'. ',session_expire=(NOW() + INTERVAL '.$ttl.' SECOND)'.
',user_id='.db_input($thisstaff?$thisstaff->getId():0). ',user_id='.db_input($thisstaff?$thisstaff->getId():0).
',user_ip='.db_input($_SERVER['REMOTE_ADDR']). ',user_ip='.db_input($_SERVER['REMOTE_ADDR']).
',user_agent='.db_input($_SERVER['HTTP_USER_AGENT']); ',user_agent='.db_input($_SERVER['HTTP_USER_AGENT']);
......
...@@ -181,9 +181,11 @@ class Upgrader extends SetupWizard { ...@@ -181,9 +181,11 @@ class Upgrader extends SetupWizard {
function doTasks() { function doTasks() {
global $ost;
if(!($tasks=$this->getPendingTasks())) if(!($tasks=$this->getPendingTasks()))
return true; //Nothing to do. return true; //Nothing to do.
$ost->logDebug('Upgrader', sprintf('There are %d pending upgrade tasks', count($tasks)));
$start_time = Misc::micro_time(); $start_time = Misc::micro_time();
foreach($tasks as $k => $task) { foreach($tasks as $k => $task) {
//TODO: check time used vs. max execution - break if need be //TODO: check time used vs. max execution - break if need be
...@@ -238,6 +240,9 @@ class Upgrader extends SetupWizard { ...@@ -238,6 +240,9 @@ class Upgrader extends SetupWizard {
$shash = substr($phash, 9, 8); $shash = substr($phash, 9, 8);
$_SESSION['ost_upgrader'][$shash]['tasks'] = $tasks; $_SESSION['ost_upgrader'][$shash]['tasks'] = $tasks;
$_SESSION['ost_upgrader'][$shash]['state'] = 'upgrade'; $_SESSION['ost_upgrader'][$shash]['state'] = 'upgrade';
$ost->logDebug('Upgrader', sprintf('Found %d tasks to be executed for %s',
count($tasks), $shash));
break; break;
} }
...@@ -253,13 +258,16 @@ class Upgrader extends SetupWizard { ...@@ -253,13 +258,16 @@ class Upgrader extends SetupWizard {
case 'c00511c7-7be60a84': //V1.6 ST- 1.7 * {{MD5('1.6 ST') -> c00511c7c1db65c0cfad04b4842afc57}} case 'c00511c7-7be60a84': //V1.6 ST- 1.7 * {{MD5('1.6 ST') -> c00511c7c1db65c0cfad04b4842afc57}}
$tasks[] = array('func' => 'migrateAttachments2DB', $tasks[] = array('func' => 'migrateAttachments2DB',
'desc' => 'Migrating attachments to database, it might take a while depending on the number of files.'); 'desc' => 'Migrating attachments to database, it might take a while depending on the number of files.');
$tasks[] = array('func' => 'migrateSessionFile2DB',
'desc' => 'Transitioning to db-backed sessions');
break; break;
} }
//Check IF SQL cleanup is exists. //Check IF SQL cleanup is exists.
$file=$this->getSQLDir().$phash.'.cleanup.sql'; $file=$this->getSQLDir().$phash.'.cleanup.sql';
if(file_exists($file)) if(file_exists($file))
$tasks[] = array('func' => 'cleanup', 'desc' => 'Post-upgrade cleanup!'); $tasks[] = array('func' => 'cleanup', 'desc' => 'Post-upgrade cleanup!',
'phash' => $phash);
return $tasks; return $tasks;
...@@ -267,8 +275,11 @@ class Upgrader extends SetupWizard { ...@@ -267,8 +275,11 @@ class Upgrader extends SetupWizard {
/************* TASKS **********************/ /************* TASKS **********************/
function cleanup($taskId) { function cleanup($taskId) {
global $ost;
$phash = $this->tasks[$taskId]['phash'];
$file=$this->getSQLDir().$phash.'.cleanup.sql';
$file=$this->getSQLDir().$this->getShash().'-cleanup.sql';
if(!file_exists($file)) //No cleanup script. if(!file_exists($file)) //No cleanup script.
return 0; return 0;
...@@ -276,11 +287,13 @@ class Upgrader extends SetupWizard { ...@@ -276,11 +287,13 @@ class Upgrader extends SetupWizard {
if($this->load_sql_file($file, $this->getTablePrefix(), false, true)) if($this->load_sql_file($file, $this->getTablePrefix(), false, true))
return 0; return 0;
//XXX: ??? $ost->logDebug('Upgrader', sprintf("%s: Unable to process cleanup file",
return false; $phash));
return 0;
} }
function migrateAttachments2DB($taskId) { function migrateAttachments2DB($taskId) {
global $ost;
if(!($max_time = ini_get('max_execution_time'))) if(!($max_time = ini_get('max_execution_time')))
$max_time = 30; //Default to 30 sec batches. $max_time = 30; //Default to 30 sec batches.
...@@ -291,5 +304,11 @@ class Upgrader extends SetupWizard { ...@@ -291,5 +304,11 @@ class Upgrader extends SetupWizard {
return $att_migrater->getQueueLength(); return $att_migrater->getQueueLength();
} }
function migrateSessionFile2DB($taskId) {
# How about 'dis for a hack?
osTicketSession::write(session_id(), session_encode());
return 0;
}
} }
?> ?>
...@@ -15,5 +15,47 @@ CREATE TABLE `%TABLE_PREFIX%ticket_event` ( ...@@ -15,5 +15,47 @@ CREATE TABLE `%TABLE_PREFIX%ticket_event` (
DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_history`; DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_history`;
DROP TABLE IF EXISTS `%TABLE_PREFIX%history`; DROP TABLE IF EXISTS `%TABLE_PREFIX%history`;
-- Transfer ticket statistics from the %ticket table (inaccurate)
-- REOPENED
INSERT INTO `%TABLE_PREFIX%ticket_event`
(`ticket_id`, `staff_id`, `team_id`, `dept_id`, `topic_id`,
`state`, `staff`, `timestamp`)
SELECT `ticket_id`, T1.`staff_id`, `team_id`, T1.`dept_id`, `topic_id`,
'reopened', T2.`username`, `reopened`
FROM `%TABLE_PREFIX%ticket` T1
INNER JOIN `%TABLE_PREFIX%staff` T2
ON (T1.`staff_id` = T2.`staff_id`)
WHERE `status` = 'open' and `reopened` is not null;
-- CLOSED
INSERT INTO `%TABLE_PREFIX%ticket_event`
(`ticket_id`, `staff_id`, `team_id`, `dept_id`, `topic_id`,
`state`, `staff`, `timestamp`)
SELECT `ticket_id`, T1.`staff_id`, `team_id`, T1.`dept_id`, `topic_id`,
'closed', COALESCE(T2.`username`,'unknown'), `closed`
FROM `%TABLE_PREFIX%ticket` T1
LEFT JOIN `%TABLE_PREFIX%staff` T2
ON (T1.`staff_id` = T2.`staff_id`)
WHERE `status` = 'closed' and `closed` is not null;
-- OVERDUE
INSERT INTO `%TABLE_PREFIX%ticket_event`
(`ticket_id`, `staff_id`, `team_id`, `dept_id`, `topic_id`,
`state`, `staff`, `timestamp`)
SELECT `ticket_id`, T1.`staff_id`, `team_id`, T1.`dept_id`, `topic_id`,
'overdue', 'SYSTEM', `duedate`
FROM `%TABLE_PREFIX%ticket` T1
INNER JOIN `%TABLE_PREFIX%staff` T2
ON (T1.`staff_id` = T2.`staff_id`)
WHERE `status` = 'open' and `isoverdue`;
-- OPENED
INSERT INTO `%TABLE_PREFIX%ticket_event`
(`ticket_id`, `staff_id`, `team_id`, `dept_id`, `topic_id`,
`state`, `staff`, `timestamp`)
SELECT `ticket_id`, 0, 0, 0, `topic_id`,
'created', 'SYSTEM', T1.`created`
FROM `%TABLE_PREFIX%ticket` T1;
UPDATE `%TABLE_PREFIX%config` UPDATE `%TABLE_PREFIX%config`
SET `schema_signature`='f8856d56e51c5cc3416389de78b54515'; SET `schema_signature`='f8856d56e51c5cc3416389de78b54515';
/** /**
* No longer necessary -- don't clobber email templates for previous
* osTicket administrators
*
* @version v1.7-DPR1 (P1) * @version v1.7-DPR1 (P1)
*/ */
UPDATE `%TABLE_PREFIX%email_template`
SET `ticket_overlimit_subj` = 'Open Tickets Limit Reached'
WHERE `tpl_id` = 1 AND `cfg_id` = 1;
UPDATE `%TABLE_PREFIX%config` UPDATE `%TABLE_PREFIX%config`
SET `schema_signature`='522e5b783c2824c67222260ee22baa93'; SET `schema_signature`='522e5b783c2824c67222260ee22baa93';
-- Drop columns we nolonger need - (must be at the very bottom or after session table is created)
ALTER TABLE `%TABLE_PREFIX%config`
DROP COLUMN `ostversion`,
DROP COLUMN `timezone_offset`,
DROP COLUMN `api_passphrase`;
-- Drop fields we no longer need in the reference table.
ALTER TABLE `%TABLE_PREFIX%ticket_attachment`
DROP `file_size`,
DROP `file_name`,
DROP `file_key`,
DROP `updated`,
DROP `isdeleted`;
-- Drop fields we no longer need in staff table.
ALTER TABLE `%TABLE_PREFIX%staff`
DROP `append_signature`,
DROP `timezone_offset`;
-- Drop fields we no longer need in department table.
ALTER TABLE `%TABLE_PREFIX%department`
DROP `can_append_signature`;
-- Banlist table has been migrated to the email_filter_rule table
DROP TABLE `%TABLE_PREFIX%email_banlist`;
...@@ -302,12 +302,6 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq_topic` ( ...@@ -302,12 +302,6 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq_topic` (
PRIMARY KEY (`faq_id`,`topic_id`) PRIMARY KEY (`faq_id`,`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- Drop columns we nolonger need - (must be at the very bottom or after session table is created)
ALTER TABLE `%TABLE_PREFIX%config`
DROP COLUMN `ostversion`,
DROP COLUMN `timezone_offset`,
DROP COLUMN `api_passphrase`;
UPDATE `%TABLE_PREFIX%config` UPDATE `%TABLE_PREFIX%config`
SET `schema_signature`='7be60a8432e44989e782d5914ef784d2'; SET `schema_signature`='7be60a8432e44989e782d5914ef784d2';
...@@ -28,6 +28,7 @@ CREATE TABLE `%TABLE_PREFIX%ticket_thread` ( ...@@ -28,6 +28,7 @@ CREATE TABLE `%TABLE_PREFIX%ticket_thread` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `ticket_id` (`ticket_id`), KEY `ticket_id` (`ticket_id`),
KEY `staff_id` (`staff_id`), KEY `staff_id` (`staff_id`),
KEY `old_pk` (`old_pk`),
FULLTEXT KEY `body` (`body`) FULLTEXT KEY `body` (`body`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
...@@ -57,7 +58,9 @@ INSERT INTO `%TABLE_PREFIX%ticket_thread` ...@@ -57,7 +58,9 @@ INSERT INTO `%TABLE_PREFIX%ticket_thread`
-- Connect responses to (new) messages -- Connect responses to (new) messages
CREATE TABLE `%TABLE_PREFIX%T_resp_links` CREATE TABLE `%TABLE_PREFIX%T_resp_links`
SELECT `id`, `old_pk`, `old_pid` FROM `%TABLE_PREFIX%ticket_thread`; SELECT `id`, `old_pk`, `old_pid`, `thread_type`
FROM `%TABLE_PREFIX%ticket_thread`
WHERE `thread_type` = 'M';
UPDATE `%TABLE_PREFIX%ticket_thread` UPDATE `%TABLE_PREFIX%ticket_thread`
SET `pid` = ( SELECT T2.`id` FROM `%TABLE_PREFIX%T_resp_links` T2 SET `pid` = ( SELECT T2.`id` FROM `%TABLE_PREFIX%T_resp_links` T2
......
...@@ -21,7 +21,6 @@ $ost->logDebug('Staff logout', ...@@ -21,7 +21,6 @@ $ost->logDebug('Staff logout',
$_SESSION['_staff']=array(); $_SESSION['_staff']=array();
session_unset(); session_unset();
session_destroy(); session_destroy();
session_write_close();
@header('Location: login.php'); @header('Location: login.php');
require('login.php'); require('login.php');
?> ?>
...@@ -27,9 +27,10 @@ if($_POST && $_POST['s'] && !$upgrader->isAborted()) { ...@@ -27,9 +27,10 @@ if($_POST && $_POST['s'] && !$upgrader->isAborted()) {
$errors['err']=' Nothing to do! System already upgraded to the current version'; $errors['err']=' Nothing to do! System already upgraded to the current version';
elseif(!$upgrader->isUpgradable()) elseif(!$upgrader->isUpgradable())
$errors['err']='The upgrader does NOT support upgrading from the current vesion!'; $errors['err']='The upgrader does NOT support upgrading from the current vesion!';
elseif($upgrader->check_prereq()) elseif($upgrader->check_prereq()) {
$upgrader->setState('upgrade'); $upgrader->setState('upgrade');
else $_SESSION['ost_upgrader'] = null;
} else
$errors['prereq']='Minimum requirements not met!'; $errors['prereq']='Minimum requirements not met!';
break; break;
case 'upgrade': //Manual upgrade.... when JS (ajax) is not supported. case 'upgrade': //Manual upgrade.... when JS (ajax) is not supported.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment