Newer
Older
<?php
/*********************************************************************
class.setup.php
osTicket setup wizard.
Peter Rotich <peter@osticket.com>
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:
**********************************************************************/
Class SetupWizard {
//Mimimum requirements
var $prereq = array('php' => '5.3',
'mysql' => '5.0');
//Version info - same as the latest version.
Peter Rotich
committed
var $version =THIS_VERSION;
var $version_verbose = THIS_VERSION;
//Errors
var $errors=array();
function SetupWizard(){
$this->errors=array();
$this->version_verbose = ('osTicket '. strtoupper(THIS_VERSION));
function load_sql_file($file, $prefix, $abort=true, $debug=false) {
Peter Rotich
committed
if(!file_exists($file) || !($schema=file_get_contents($file)))
return $this->abort('Error accessing SQL file '.basename($file), $debug);
return $this->load_sql($schema, $prefix, $abort, $debug);
}
/*
load SQL schema - assumes MySQL && existing connection
*/
function load_sql($schema, $prefix, $abort=true, $debug=false) {
$schema=preg_replace('%^\s*(#|--).*$%m', '', $schema);
Peter Rotich
committed
# Replace table prefix
$schema = str_replace('%TABLE_PREFIX%', $prefix, $schema);
Peter Rotich
committed
# Split by semicolons - and cleanup
if(!($statements = array_filter(array_map('trim',
// Thanks, http://stackoverflow.com/a/3147901
preg_split("/;(?=(?:[^']*'[^']*')*[^']*$)/", $schema)))))
return $this->abort('Error parsing SQL schema', $debug);
Peter Rotich
committed
db_query('SET SESSION SQL_MODE =""', false);
Peter Rotich
committed
if(db_query($sql, false)) continue;
$error = "[$sql] ".db_error();
if($abort)
return $this->abort($error, $debug);
}
return true;
}
function getVersion() {
return $this->version;
}
function getVersionVerbose() {
return $this->version_verbose;
}
function getPHPVersion() {
return $this->prereq['php'];
}
function getMySQLVersion() {
return $this->prereq['mysql'];
}
function check_php() {
return (version_compare(PHP_VERSION, $this->getPHPVersion())>=0);
return (extension_loaded('mysqli'));
function check_mysql_version() {
return (version_compare(db_version(), $this->getMySQLVersion())>=0);
}
function check_prereq() {
return ($this->check_php() && $this->check_mysql());
}
/*
@error is a mixed var.
*/
Peter Rotich
committed
$this->onError($error);
return false; // Always false... It's an abort.
}
Peter Rotich
committed
$this->errors = array_merge($this->errors, $error);
elseif($error)
$this->errors[] = $error;
}
function getErrors(){
return $this->errors;
}
function onError($error) {
return $this->setError($error);