.
*
* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
* California 94120-7775, or email info@knowledgetree.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
*
* @copyright 2008-2009, KnowledgeTree Inc.
* @license GNU General Public License version 3
* @author KnowledgeTree Team
* @package Upgrader
* @version Version 0.1
*/
require_once('../../config/dmsDefaults.php');
require_once("../wizard/installUtil.php");
class UpgradeUtil extends InstallUtil {
/**
* Check if system needs to be upgraded
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return boolean
*/
public function isSystemUpgraded() {
if (file_exists(dirname(__FILE__)."/upgrade.lock")) {
return true;
}
return false;
}
public function error($error) {
$template_vars['error'] = $error;
$file = "templates/error.tpl";
if (!file_exists($file)) {
return false;
}
extract($template_vars); // Extract the vars to local namespace
ob_start();
include($file);
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
}
public function loadInstallIni($path) {
require_once("../wizard/iniUtilities.php");
return new iniUtilities($path);
}
public function loadInstallDBUtil() {
require_once("../wizard/dbUtilities.php");
return new dbUtilities();
}
/**
* Function to send output to the browser prior to normal dynamic loading of a template after code execution
*
* @param string $template The name of the template to use
* @param array $output [optional] Optional array containing output text to be inserted into the template
* @return
*/
public function flushOutput($template, $output = null) {
if (is_array($output)) {
foreach ($output as $key => $value) {
$template_vars[$key] = $value;
}
}
$file = "templates/" . $template;
if (!file_exists($file)) {
return false;
}
extract($template_vars); // Extract the vars to local namespace
ob_start();
include($file);
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
}
/**
* Check if system needs to be upgraded
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return mixed
*/
public function checkStructurePermissions() {
// Check if Wizard Directory is writable
if(!$this->_checkPermission(WIZARD_DIR)) {
return 'wizard';
}
return true;
}
public function create_restore_stmt($targetfile)
{
$oKTConfig =& KTConfig::getSingleton();
$adminUser = $oKTConfig->get('db/dbAdminUser');
$adminPwd = $oKTConfig->get('db/dbAdminPass');
$dbHost = $oKTConfig->get('db/dbHost');
$dbName = $oKTConfig->get('db/dbName');
$dbPort = trim($oKTConfig->get('db/dbPort'));
if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port');
if (empty($dbPort)) $dbPort='3306';
$dbSocket = trim($oKTConfig->get('db/dbSocket'));
if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket');
if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock';
$dir = $this->resolveMysqlDir();
$info['dir']=$dir;
$prefix='';
if (OS_UNIX) {
$prefix .= "./";
}
if (@stat($dbSocket) !== false) {
$mechanism="--socket=\"$dbSocket\"";
}
else {
$mechanism="--port=\"$dbPort\"";
}
$tmpdir = $this->resolveTempDir();
$stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"
";
$stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"
";
$stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n";
$info['display']=$stmt;
$stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n";
$stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n";
$stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\"";
$info['cmd']=$stmt;
return $info;
}
public function resolveMysqlDir()
{
// possibly detect existing installations:
if (OS_UNIX) {
$dirs = array('/opt/mysql/bin','/usr/local/mysql/bin');
$mysqlname ='mysql';
}
else
{
$dirs = explode(';', $_SERVER['PATH']);
$dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin';
$dirs[] = 'c:/program files/ktdms/mysql/bin';
$mysqlname ='mysql.exe';
}
$oKTConfig =& KTConfig::getSingleton();
$mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir);
$dirs[] = $mysqldir;
if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) {
$dirs [] = realpath(dirname($FILE) . '/../../mysql/bin');
}
foreach($dirs as $dir)
{
if (is_file($dir . '/' . $mysqlname))
{
return $dir;
}
}
return '';
}
public function resolveTempDir()
{
if (OS_UNIX) {
$dir='/tmp/kt-db-backup';
}
else {
$dir='c:/kt-db-backup';
}
$oKTConfig =& KTConfig::getSingleton();
$dir = $oKTConfig->get('backup/backupDirectory',$dir);
if (!is_dir($dir)) {
mkdir($dir);
}
return $dir;
}
}
?>