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

Upgrader fixes

parent 0933adb2
Branches
Tags
No related merge requests found
......@@ -81,8 +81,9 @@ class Config {
if($this->config['schema_signature'])
return $this->config['schema_signature'];
elseif($this->config['ostversion']) //old version 1.6 st.
return md5(strtoupper($this->config['ostversion']));
if($this->config['ostversion']) //old version 1.6 RC[1-5]-ST
return md5(strtoupper(trim($this->config['ostversion'])));
return null;
}
......
......@@ -2,13 +2,8 @@
/*********************************************************************
class.migrater.php
SQL database migrater. This provides the engine capable of rolling the
database for an osTicket installation forward (and perhaps even
backward) in time using a set of included migration scripts. Each script
will roll the database between two database checkpoints. Where possible,
the migrater will roll several checkpoint scripts into one to be applied
together.
Migration utils required by upgrader.
Jared Hancock <jared@osticket.com>
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
......@@ -19,6 +14,19 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
/*
DatabaseMigrater.
SQL database migrater. This provides the engine capable of rolling the
database for an osTicket installation forward (and perhaps even
backward) in time using a set of included migration scripts. Each script
will roll the database between two database checkpoints. Where possible,
the migrater will roll several checkpoint scripts into one to be applied
together.
*/
class DatabaseMigrater {
var $start;
......@@ -64,4 +72,169 @@ class DatabaseMigrater {
return $patches;
}
}
/*
AttachmentMigrater
Attachment migration from file-based attachments in pre-1.7 to
database-backed attachments in osTicket v1.7. This class provides the
hardware to find and retrieve old attachments and move them into the new
database scheme with the data in the actual database.
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
*/
include_once(INCLUDE_DIR.'class.file.php');
class AttachmentMigrater {
function AttachmentMigrater() {
$this->queue = array();
$this->current = 0;
$this->errors = 0;
$this->errorList = array();
}
/**
* Identifies attachments in need of migration and queues them for
* migration to the new database schema.
*
* @see ::next() for output along the way
*
* Returns:
* TRUE/FALSE to indicate if migration finished without any errors
*/
function start_migration() {
$this->findAttachments();
$this->total = count($this->queue);
}
/**
* Process the migration for a unit of time. This will be used to
* overcome the execution time restriction of PHP. This instance can be
* stashed in a session and have this method called periodically to
* process another batch of attachments
*/
function do_batch($max, $time=20) {
$start = time();
$this->errors = 0;
while (count($this->queue) && $count++ < $max && time()-$start < $time)
$this->next();
# TODO: Log success/error indication of migration of attachments
return (!$this->errors);
}
function queue($fileinfo) {
$this->queue[] = $fileinfo;
}
function getQueueLength() { return count($this->queue); }
/**
* Processes the next item on the work queue. Emits a JSON messages to
* indicate current progress.
*
* Returns:
* TRUE/NULL if the migration was successful
*/
function next() {
# Fetch next item -- use the last item so the array indices don't
# need to be recalculated for every shift() operation.
$info = array_pop($this->queue);
# Attach file to the ticket
if (!($info['data'] = @file_get_contents($info['path']))) {
# Continue with next file
return $this->error(
sprintf('%s: Cannot read file contents', $info['path']));
}
# Get the mime/type of each file
# XXX: Use finfo_buffer for PHP 5.3+
$info['type'] = mime_content_type($info['path']);
if (!($fileId = AttachmentFile::save($info))) {
return $this->error(
sprintf('%s: Unable to migrate attachment', $info['path']));
}
# Update the ATTACHMENT_TABLE record to set file_id
db_query('update '.TICKET_ATTACHMENT_TABLE
.' set file_id='.db_input($fileId)
.' where attach_id='.db_input($info['attachId']));
# Remove disk image of the file. If this fails, the migration for
# this file would not be retried, because the file_id in the
# TICKET_ATTACHMENT_TABLE has a nonzero value now
if (!@unlink($info['path']))
$this->error(
sprintf('%s: Unable to remove file from disk',
$info['path']));
# TODO: Log an internal note to the ticket?
return true;
}
/**
* From (class Ticket::fixAttachments), used to detect the locations of
* attachment files
*/
/* static */ function findAttachments(){
global $cfg;
$res=db_query('SELECT attach_id, file_name, file_key, Ti.created'
.' FROM '.TICKET_ATTACHMENT_TABLE.' TA'
.' JOIN '.TICKET_TABLE.' Ti ON Ti.ticket_id=TA.ticket_id'
.' WHERE NOT file_id');
if (!$res) {
return $this->error('Unable to query for attached files');
} elseif (!db_num_rows($res)) {
return true;
}
$dir=$cfg->getUploadDir();
while (list($id,$name,$key,$created)=db_fetch_row($res)) {
$month=date('my',strtotime($created));
$info=array(
'name'=> $name,
'attachId'=> $id,
);
$filename15=sprintf("%s/%s_%s",rtrim($dir,'/'),$key,$name);
$filename16=sprintf("%s/%s/%s_%s",rtrim($dir,'/'),$month,$key,$name); //new destination.
if (file_exists($filename15)) {
$info['path'] = $filename15;
} elseif (file_exists($filename16)) {
$info['path'] = $filename16;
} else {
# XXX Cannot find file for attachment
$this->error(sprintf('%s: Unable to locate attachment file',
$name));
# No need to further process this file
continue;
}
# TODO: Get the size and mime/type of each file.
#
# NOTE: If filesize() fails and file_get_contents() doesn't,
# then the AttachmentFile::save() method will automatically
# estimate the filesize based on the length of the string data
# received in $info['data'] -- ie. no need to do that here.
#
# NOTE: The size is done here because it should be quick to
# lookup out of file inode already loaded. The mime/type may
# take a while because it will require a second IO to read the
# file data. To ensure this will finish before the
# max_execution_time, perform the type match in the ::next()
# method since the entire file content will be read there
# anyway.
$info['size'] = @filesize($info['path']);
# Coroutines would be nice ..
$this->queue($info);
}
}
function error($what) {
$this->errors++;
$this->errorList[] = $what;
# Assist in returning FALSE for inline returns with this method
return false;
}
function getErrors() {
return $this->errorList;
}
}
?>
......@@ -43,7 +43,7 @@ class osTicket {
}
function isUpgradePending() {
return (defined('SCHEMA_SIGNATURE') && strcasecmp($this->getConfig()->getSchemaSignature(), SCHEMA_SIGNATURE));
return (defined('SCHEMA_SIGNATURE') && strcasecmp($this->getDBSignature(), SCHEMA_SIGNATURE));
}
function getSession() {
......@@ -59,6 +59,14 @@ class osTicket {
return $this->getConfig()?$this->getConfig()->getId():0;
}
function getDBSignature() {
return $this->getConfig()->getSchemaSignature();
}
function getVersion() {
return THIS_VERSION;
}
function addExtraHeader($header) {
$this->headers[md5($header)] = $header;
}
......
......@@ -21,14 +21,17 @@ Class SetupWizard {
'mysql' => '4.4');
//Version info - same as the latest version.
var $version ='1.7-dpr3';
var $version_verbose='1.7 DPR 3';
var $version =THIS_VERSION;
var $version_verbose = THIS_VERSION;
//Errors
var $errors=array();
function SetupWizard(){
$this->errors=array();
$this->version_verbose = ('osTicket v'. strtoupper(THIS_VERSION));
}
function load_sql_file($file, $prefix, $abort=true, $debug=false) {
......
......@@ -14,8 +14,8 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once INC_DIR.'class.setup.php';
require_once INC_DIR.'class.migrater.php';
require_once INCLUDE_DIR.'class.setup.php';
require_once INCLUDE_DIR.'class.migrater.php';
class Upgrader extends SetupWizard {
......@@ -181,6 +181,7 @@ class Upgrader extends SetupWizard {
return true; //Nothing to do.
foreach($tasks as $k => $task) {
//TODO: check time used vs. max execution - break if need be
if(call_user_func(array($this, $task['func']), $k)===0) {
$this->tasks[$k]['done'] = true;
} else { //Task has pending items to process.
......@@ -198,6 +199,7 @@ class Upgrader extends SetupWizard {
return false;
foreach ($patches as $patch) {
//TODO: check time used vs. max execution - break if need be
if (!$this->load_sql_file($patch, $this->getTablePrefix()))
return false;
......@@ -232,13 +234,13 @@ class Upgrader extends SetupWizard {
$tasks=array();
switch($phash) { //Add patch specific scripted tasks.
case 'd4fe13b1-7be60a84': //V1.6 ST- 1.7 *
case 'c00511c7-7be60a84': //V1.6 ST- 1.7 * {{MD5('1.6 ST') -> c00511c7c1db65c0cfad04b4842afc57}}
$tasks[] = array('func' => 'migrateAttachments2DB',
'desc' => 'Migrating attachments to database, it might take a while depending on the number of files.');
break;
}
//Check if cleanup p
//Check IF SQL cleanup is exists.
$file=$this->getSQLDir().$phash.'.cleanup.sql';
if(file_exists($file))
$tasks[] = array('func' => 'cleanup', 'desc' => 'Post-upgrade cleanup!');
......@@ -261,10 +263,9 @@ class Upgrader extends SetupWizard {
//XXX: ???
return false;
}
function migrateAttachments2DB($tId=0) {
echo "Process attachments here - $tId";
$att_migrater = new AttachmentMigrater();
$att_migrater->start_migration();
# XXX: Loop here (with help of task manager)
......
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
?>
<div id="main">
<div id="upgrader">
<div id="main">
<h1 style="color:#FF7700;">Upgrade Aborted!</h1>
<div id="intro">
<p>Upgrade aborted due to errors. Any errors at this stage are fatal. Please note the error(s), if any, when contacting us.<p>
<p><strong>Upgrade aborted due to errors. Any errors at this stage are fatal.</strong></p>
<p>Please note the error(s), if any, when <a target="_blank" href="http://osticket.com/support/">seeking help</a>.<p>
<?php
if($upgrader && ($errors=$upgrader->getErrors())) {
if($errors['err'])
......@@ -20,9 +22,11 @@ if(!defined('SETUPINC')) die('Kwaheri!');
?>
<p>Please, refer to the <a target="_blank" href="http://osticket.com/wiki/Upgrade_and_Migration">Upgrade Guide</a> on the wiki for more information.</p>
</div>
<p><strong>Need Help?</strong> We provide <a target="_blank" href="http://osticket.com/support/professional_services.php"><u>professional upgrade services</u></a> and commercial support. <a target="_blank" href="http://osticket.com/support/">Contact us</a> today for expedited help.</p>
</div>
<div id="sidebar">
<p><strong>Need Help?</strong> We provide <a target="_blank" href="http://osticket.com/support/professional_services.php"><u>professional upgrade services</u></a> and commercial support. <a target="_blank" href="http://osticket.com/support/">Contact us</a> today for <u>expedited</u> help.</p>
</div>
<div id="sidebar">
<h3>What to do?</h3>
<p>Restore your previous version from backup and try again or <a target="_blank" href="http://osticket.com/support/">seek help</a>.</p>
</div>
<div class="clear"></div>
</div>
<?php if(!defined('SETUPINC')) die('Kwaheri!');
$url=URL;
?>
<?php
if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
?>
<div id="upgrader">
<div id="main">
<h1 style="color:green;">Upgrade Completed!</h1>
<div id="intro">
<p>Congratulations osTicket upgrade has been completed successfully. Please refer to Release Notes for more information about changes and/or new features.</p>
<h3 style="color:#FF7700;">Post-upgrade manual cleanup</h3>
Please take a minute to cleanup!
<ul>
<li><b>Delete setup directory</b>:<br> After verifying that the upgrade completed correctly please delete setup folder.</li>
<li><b>Enable the helpdesk</b>:<br> You can now enable osTicket, be sure to take some time to explore changes and new features</li>
</ul>
<p>Congratulations osTicket upgrade has been completed successfully.</p>
<p>Please refer to <a href="http://osticket.com/wiki/Release_Notes" target="_blank">Release Notes</a> for more information about changes and/or new features.</p>
</div>
<p>Once again, thank you for choosing osTicket. Your feedback is welcomed!</p>
<p>We take user feedback seriously and are dedicated to making changes based on your input. Feel free to let us know of any other improvements you would like to see in osTicket, so that we may add them in the future as we continue to develop better and better versions of osTicket.</p>
<p>Once again, thank you for choosing osTicket.</p>
<p>Please feel free to <a target="_blank" href="http://osticket.com/support/">let us know</a> of any other improvements and features you would like to see in osTicket, so that we may add them in the future as we continue to develop better and better versions of osTicket.</p>
<p>We take user feedback seriously and we're dedicated to making changes based on your input.</p>
<p>Good luck.<p>
<p>osTicket Team.</p>
<br>
......@@ -22,9 +18,10 @@ $url=URL;
</div>
<div id="sidebar">
<h3>What's Next?</h3>
<p><b>Post-upgrade</b>: You can now log in to <a href="../scp/admin.php" target="_blank">Admin Panel</a> and explore the new features. For complete and upto date release notes see <a href="http://osticket.com/wiki/Post-Install_Setup_Guide" target="_blank">osTicket wiki</a></p>
<p><b>Post-upgrade</b>: You can now go to <a href="scp/settings.php" target="_blank">Admin Panel</a> to enable the system and explore the new features. For complete and upto date release notes see <a href="http://osticket.com/wiki/Release_Notes" target="_blank">osTicket wiki</a></p>
<p><b>Stay up to date</b>: It's important to keep your osTicket installation up to date. Get announcements, security updates and alerts delivered directly to you!
<a target="_blank" href="http://osticket.com/support/subscribe.php">Subcribe today</a> and be in the loop!</p>
<a target="_blank" href="http://osticket.com/support/subscribe.php">Get in the loop</a> today and stay informed!</p>
<p><b>Commercial support available</b>: Get guidance and hands-on expertise to address unique challenges and make sure your osTicket runs smoothly, efficiently, and securely. <a target="_blank" href="http://osticket.com/support/commercial_support.php.php">Learn More!</a></p>
</div>
<div class="clear"></div>
</div>
/**
* @version v1.7-*
* @schema c00511c7c1db65c0cfad04b4842afc57
*/
-- Add a table to contain the attachment file contents
DROP TABLE IF EXISTS `%TABLE_PREFIX%file`;
CREATE TABLE `%TABLE_PREFIX%file` (
......@@ -287,3 +292,6 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq_topic` (
`topic_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`faq_id`,`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
UPDATE `%TABLE_PREFIX%config`
SET `schema_signature`='7be60a8432e44989e782d5914ef784d2';
<?php
if(!defined('SETUPINC')) die('Kwaheri!');
if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
?>
<h2>osTicket Upgrader</h2>
<div id="upgrader">
<div id="main">
<h1>osTicket Upgrade!</h1>
<font color="red"><b><?php echo $errors['err']; ?></b></font>
<div id="intro">
<p>Thank you for being a loyal osTicket user!</p>
<p>The upgrade wizard will guide you every step of the way in the upgrade process. While we try to ensure that the upgrade process is straightforward and painless, we can't guarantee it will be the case for every user.</p>
......@@ -22,7 +22,6 @@ if(!defined('SETUPINC')) die('Kwaheri!');
<h3>Higly Recommended:</h3>
We hightly recommend that you follow the steps below.
<ul>
<li>Take osTicket offline momentarily during upgrade.</li>
<li>Backup the current database, if you haven't done so already.</li>
<li>Be patient the upgrade process will take a couple of seconds.</li>
</ul>
......@@ -36,15 +35,17 @@ if(!defined('SETUPINC')) die('Kwaheri!');
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Remember to backup your osTicket database</p>
<p>2. Take osTicket offline momentarily</p>
<p>2. Refer to <a href="http://osticket.com/wiki/Upgrade_and_Migration" target="_blank">Upgrade Guide</a> for the latest tips</a>
<p>3. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>4. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Doing stuff!</h4>
Please wait... while we upgrade your osTicket installation!
<div id="udb"></div>
</div>
<div class="clear"></div>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Doing stuff!</h4>
Please wait... while we upgrade your osTicket installation!
<div id="msg"></div>
</div>
<?php
if(!defined('SETUPINC') || !$upgrader) die('Kwaheri!');
if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
$action=$upgrader->getNextAction();
?>
<h2>osTicket Upgrade</h2>
<div id="upgrader">
<div id="main">
<h1>osTicket Upgrade</h1>
<div id="intro">
<p>Thank you for taking the time to upgrade your osTicket intallation!</p>
<p>Please don't cancel or close the browser, any errors at this
stage will be fatal.</p>
<p>Please don't cancel or close the browser, any errors at this stage will be fatal.</p>
</div>
<h2><?php echo $action ?></h2>
<p>The upgrade wizard will now attempt to upgrade your database and core settings!</p>
......@@ -28,13 +27,15 @@ $action=$upgrader->getNextAction();
<div id="sidebar">
<h3>Upgrade Tips</h3>
<p>1. Be patient the process will take a couple of seconds.</p>
<p>2. If you experience any problems, you can always restore your files/dabase backup.</p>
<p>2. If you experience any problems, you can always restore your files/database backup.</p>
<p>3. We can help, feel free to <a href="http://osticket.com/support/" target="_blank">contact us </a> for professional help.</p>
</div>
<div class="clear"></div>
<div id="overlay"></div>
<div id="loading">
<h4><?php echo $action; ?></h4>
Please wait... while we upgrade your osTicket installation!
<div id="msg" style="font-weight: bold;padding-top:10px;">Smile!</div>
</div>
</div>
<div class="clear"></div>`
......@@ -23,7 +23,9 @@ if(!$ost or !$thisstaff or !$thisstaff->isAdmin()){
//Some security related warnings - bitch until fixed!!! :)
if($ost->isUpgradePending()) {
$errors['err']=$sysnotice='System upgrade is pending <a href="../setup/upgrade.php">Upgrade Now</a>';
$errors['err']=$sysnotice='System upgrade is pending <a href="upgrade.php">Upgrade Now</a>';
require('upgrade.php');
exit;
} else {
if(file_exists('../setup/')) {
......
......@@ -19,8 +19,7 @@ $msg='';
$staff=Staff::lookup($thisstaff->getId());
if($_POST && $_POST['id']!=$thisstaff->getId()) { //Check dummy ID used on the form.
$errors['err']='Internal Error. Action Denied';
}
if(!$errors && $_POST) { //Handle post
} elseif(!$errors && $_POST) { //Handle post
if(!$staff)
$errors['err']='Unknown or invalid staff';
......
......@@ -93,7 +93,9 @@ $msg=$warn=$sysnotice='';
$tabs=array();
$submenu=array();
if($ost->isUpgradePending()) {
$errors['err']=$sysnotice='System upgrade is pending <a href="../setup/upgrade.php">Upgrade Now</a>';
$errors['err']=$sysnotice='System upgrade is pending <a href="upgrade.php">Upgrade Now</a>';
require('upgrade.php');
exit;
} elseif($cfg->isHelpDeskOffline()) {
$sysnotice='<strong>System is set to offline mode</strong> - Client interface is disabled and ONLY admins can access staff control panel.';
$sysnotice.=' <a href="settings.php">Enable</a>.';
......
......@@ -13,31 +13,12 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
function staffLoginPage($msg) {
$_SESSION['_staff']['auth']['dest']=THISPAGE;
$_SESSION['_staff']['auth']['msg']=$msg;
header('Location: ../scp/login.php');
exit;
}
require '../scp/staff.inc.php';
if(!$thisstaff or !$thisstaff->isAdmin()) {
staffLoginPage('Admin Access Required!');
exit;
}
define('SETUPINC', true);
define('INC_DIR', './inc/');
define('SQL_DIR', INC_DIR.'sql/');
require_once INC_DIR.'class.upgrader.php';
require_once 'admin.inc.php';
require_once INCLUDE_DIR.'class.upgrader.php';
//$_SESSION['ost_upgrader']=null;
$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, SQL_DIR);
$upgrader = new Upgrader($cfg->getSchemaSignature(), TABLE_PREFIX, PATCH_DIR);
$wizard=array();
$wizard['title']='osTicket Upgrade Wizard';
$wizard['tagline']='Upgrading osTicket to v'.$upgrader->getVersionVerbose();
$wizard['logo']='logo-upgrade.png';
......@@ -77,25 +58,32 @@ if($_POST && $_POST['s'] && !$upgrader->isAborted()) {
switch(strtolower($upgrader->getState())) {
case 'aborted':
$inc='upgrade-aborted.inc.php';
$inc='aborted.inc.php';
break;
case 'upgrade':
$inc='upgrade.inc.php';
break;
case 'done':
$inc='upgrade-done.inc.php';
$inc='done.inc.php';
break;
default:
$inc='upgrade-prereq.inc.php';
$inc='upgrade.inc.php';
if($upgrader->isAborted())
$inc='upgrade-aborted.inc.php';
$inc='aborted.inc.php';
elseif(!$ost->isUpgradePending())
$errors['err']='Nothing to do! System already upgraded to the latest version';
$errors['err']='Nothing to do! System already upgraded to <b>'.$ost->getVersion().'</b> with no pending patches to apply.';
elseif(!$upgrader->isUpgradable())
$errors['err']='The upgrader does NOT support upgrading from the current vesion!';
}
require(INC_DIR.'header.inc.php');
require(INC_DIR.$inc);
require(INC_DIR.'footer.inc.php');
$nav->setTabActive('dashboard');
$nav->addSubMenu(array('desc'=>'Upgrader',
'title'=>'Upgrader',
'href'=>'upgrade.php',
'iconclass'=>'preferences'),
true);
$ost->addExtraHeader('<script type="text/javascript" src="./js/upgrader.js"></script>');
require(STAFFINC_DIR.'header.inc.php');
require(UPGRADE_DIR.$inc);
require(STAFFINC_DIR.'footer.inc.php');
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment