Skip to content
Snippets Groups Projects
Commit 0e0f6dcb authored by Jared Hancock's avatar Jared Hancock
Browse files

Various bug-fixes for the upgrader

- timezone_offset was dropped from the config table at 1.7-dpr1
- upgrader: only apply five patches in one request
- upgrader: fix readPatchInfo to work correctly
- session: support migrating from 1.6 (again)
- config: support migrating from 1.6 (fallback)
- config: no default for 'isonline' setting
- config: fix SQL whitespace issue for schema signature fallbacks
- config: hash 1.6 versions in the schema signature lookup
- upgrader: fix logging bug in attachment migration
parent 517f86c4
Branches
Tags
No related merge requests found
......@@ -39,13 +39,9 @@ class Config {
$sql='SELECT id, `key`, value FROM '.$this->table
.' WHERE `'.$this->section_column.'` = '.db_input($this->section);
if(!($res=db_query($sql)) || !db_num_rows($res))
return false;
while ($row = db_fetch_array($res))
$this->config[$row['key']] = $row;
return true;
if(($res=db_query($sql)) && db_num_rows($res))
while ($row = db_fetch_array($res))
$this->config[$row['key']] = $row;
}
function getNamespace() {
......@@ -59,6 +55,7 @@ class Config {
return $this->session[$key];
elseif ($default !== null)
return $this->set($key, $default);
return null;
}
function exists($key) {
......@@ -75,11 +72,11 @@ class Config {
}
function create($key, $value) {
$res = db_query('INSERT INTO '.$this->table
$sql = 'INSERT INTO '.$this->table
.' SET `'.$this->section_column.'`='.db_input($this->section)
.', `key`='.db_input($key)
.', value='.db_input($value));
if (!db_query($res) || !($id=db_insert_id()))
.', value='.db_input($value);
if (!db_query($sql) || !($id=db_insert_id()))
return false;
$this->config[$key] = array('key'=>$key, 'value'=>$value, 'id'=>$id);
......@@ -123,6 +120,14 @@ class OsticketConfig extends Config {
function OsticketConfig($section=null) {
parent::Config($section);
if (count($this->config) == 0) {
// Fallback for osticket < 1.7@852ca89e
$sql='SELECT * FROM '.$this->table.' WHERE id = 1';
if (($res=db_query($sql)) && db_num_rows($res))
foreach (db_fetch_array($res) as $key=>$value)
$this->config[$key] = array('value'=>$value);
}
//Get the default time zone
// We can't JOIN timezone table above due to upgrade support.
if ($this->get('default_timezone_id')) {
......@@ -146,7 +151,7 @@ class OsticketConfig extends Config {
}
function isOnline() {
return ($this->get('isonline', false));
return ($this->get('isonline'));
}
function isKnowledgebaseEnabled() {
......@@ -166,19 +171,19 @@ class OsticketConfig extends Config {
// 1.7 after namespaced configuration, other namespace
if ($section) {
$sql='SELECT value FROM '.$this->table
.'WHERE `key` = "schema_signature" and namespace='.db_input($section);
.' WHERE `key` = "schema_signature" and namespace='.db_input($section);
if (($res=db_query($sql, false)) && db_num_rows($res))
return db_result($res);
}
// 1.7 before namespaced configuration
$sql='SELECT `schema_signature` FROM '.$this->table
.'WHERE id=1';
.' WHERE id=1';
if (($res=db_query($sql, false)) && db_num_rows($res))
return db_result($res);
// old version 1.6
return self::getDBVersion();
return md5(self::getDBVersion());
}
function getDBTZoffset() {
......
......@@ -212,7 +212,7 @@ class AttachmentMigrater {
if(!($res=db_query($sql)))
return $this->error('Unable to query DB for attached files to migrate!');
$ost->logDebug('Found '.db_num_rows($res).' attachments to migrate');
$ost->logDebug("Attachment migration", 'Found '.db_num_rows($res).' attachments to migrate');
if(!db_num_rows($res))
return 0; //Nothing else to do!!
......
......@@ -229,7 +229,7 @@ class osTicket {
if($email) {
$email->sendAlert($to, $subject, $message);
} else {//no luck - try the system mail.
Email::sendmail($to, $subject, $message, sprintf('"osTicket Alerts"<%s>',$to));
Mailer::sendmail($to, $subject, $message, sprintf('"osTicket Alerts"<%s>',$to));
}
//log the alert? Watch out for loops here.
......
......@@ -26,7 +26,7 @@ class osTicketSession {
if(!$this->ttl)
$this->ttl=SESSION_TTL;
if ($this->read(session_id()) !== false) {
if (!OsticketConfig::getDBVersion()) {
//Set handlers.
session_set_save_handler(
array(&$this, 'open'),
......
......@@ -148,10 +148,11 @@ class Upgrader extends SetupWizard {
function readPatchInfo($patch) {
$info = array();
if (preg_match('/\*(.*)\*/', file_get_contents($patch), $matches)) {
if (preg_match('/@([\w\d_-]+)\s+(.*)$/', $matches[0], $matches2))
if (preg_match(':/\*\*(.*)\*/:s', file_get_contents($patch), $matches)) {
if (preg_match_all('/@([\w\d_-]+)\s+(.*)$/m', $matches[0],
$matches2, PREG_SET_ORDER))
foreach ($matches2 as $match)
$info[$match[0]] = $match[1];
$info[$match[1]] = $match[2];
}
if (!isset($info['version']))
$info['version'] = substr(basename($patch), 9, 8);
......@@ -249,7 +250,8 @@ class Upgrader extends SetupWizard {
if(!($max_time = ini_get('max_execution_time')))
$max_time = 300; //Apache/IIS defaults.
foreach ($patches as $patch) {
// Apply up to five patches at a time
foreach (array_slice($patches, 0, 5) as $patch) {
//TODO: check time used vs. max execution - break if need be
if (!$this->load_sql_file($patch, $this->getTablePrefix()))
return false;
......
/**
* @version v1.7.1
* @signature 75fce76967f1549ffd296a44139dea57
* @signature 852ca89e1440e736d763b3b87f039bd7
*
* - Changes config table to be key/value based and allows for
* configuration key clobbering by defining a namespace for the keys. The
......@@ -18,9 +18,8 @@ CREATE TABLE `%TABLE_PREFIX%_config` (
UNIQUE KEY (`namespace`, `key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `%TABLE_PREFIX%_config` (`key`, `value`, `namespace`) VALUES
INSERT INTO `%TABLE_PREFIX%_config` (`key`, `value`, `namespace`) VALUES
('isonline', (SELECT `isonline` FROM `%TABLE_PREFIX%config` WHERE `id` = 1), 'core')
, ('timezone_offset', (SELECT `timezone_offset` FROM `%TABLE_PREFIX%config` WHERE `id` = 1), 'core')
, ('enable_daylight_saving', (SELECT `enable_daylight_saving` FROM `%TABLE_PREFIX%config` WHERE `id` = 1), 'core')
, ('staff_ip_binding', (SELECT `staff_ip_binding` FROM `%TABLE_PREFIX%config` WHERE `id` = 1), 'core')
, ('staff_max_logins', (SELECT `staff_max_logins` FROM `%TABLE_PREFIX%config` WHERE `id` = 1), 'core')
......@@ -120,5 +119,5 @@ ALTER TABLE `%TABLE_PREFIX%_config` RENAME TO `%TABLE_PREFIX%config`;
-- Finished with patch
UPDATE `%TABLE_PREFIX%config`
SET `value` = '75fce76967f1549ffd296a44139dea57'
SET `value` = '852ca89e1440e736d763b3b87f039bd7'
WHERE `key` = 'schema_signature' AND `namespace` = 'core';
......@@ -76,7 +76,7 @@
#Current version && schema signature (Changes from version to version)
define('THIS_VERSION','1.7.0+'); //Shown on admin panel
define('SCHEMA_SIGNATURE', '75fce76967f1549ffd296a44139dea57'); //MD5 signature of the db schema. (used to trigger upgrades)
define('SCHEMA_SIGNATURE', '852ca89e1440e736d763b3b87f039bd7'); //MD5 signature of the db schema. (used to trigger upgrades)
#load config info
$configfile='';
if(file_exists(ROOT_DIR.'ostconfig.php')) //Old installs prior to v 1.6 RC5
......
......@@ -91,7 +91,6 @@ CREATE TABLE `%TABLE_PREFIX%config` (
INSERT INTO `%TABLE_PREFIX%config` (`namespace`, `key`, `value`) VALUES
('core', 'isonline', '0'),
('core', 'timezone_offset', '0.0'),
('core', 'enable_daylight_saving', '0'),
('core', 'staff_ip_binding', '1'),
('core', 'staff_max_logins', '4'),
......
75fce76967f1549ffd296a44139dea57
852ca89e1440e736d763b3b87f039bd7
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment