* adjust win2unix.

This commit is contained in:
wyd621
2014-01-02 03:22:11 +00:00
parent 07892750be
commit f3c2af5a1e
3 changed files with 38 additions and 56 deletions

View File

@@ -1,11 +1,45 @@
<?php
error_reporting(E_ALL);
include dirname(dirname(dirname(__FILE__))) . "/config/config.php";
if($config->requestType == 'PATH_INFO')
$renameTables = array('zt_casestep' => 'zt_caseStep', 'zt_doclib' => 'zt_docLib', 'zt_grouppriv' => 'zt_groupPriv',
'zt_productplan' => 'zt_productPlan', 'zt_projectproduct' => 'zt_projectProduct', 'zt_projectstory' => 'zt_projectStory',
'zt_storyspec' => 'zt_storySpec', 'zt_taskestimate' => 'zt_taskEstimate', 'zt_testresult' => 'zt_testResult',
'zt_testrun' => 'zt_testRun', 'zt_testtask' => 'zt_testTask', 'zt_usercontact' => 'zt_userContact', 'zt_usergroup' => 'zt_userGroup',
'zt_userquery' => 'zt_userQuery', 'zt_usertpl' => 'zt_userTPL');
try
{
system('php ztcli "http://localhost/admin-win2Unix"');
$params = $config->db;
$dbh = new PDO("mysql:host={$params->host}; port={$params->port}; dbname={$params->name}", $params->user, $params->password);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec("SET NAMES utf8");
}
elseif($config->requestType == 'GET')
catch(PDOException $e)
{
system('php ztcli "http://localhost/?m=admin&f=win2Unix"');
echo 'Connection failed: ' . $e->getMessage() . "\n";
die("connect to db failed.\n");
}
$existTables = $dbh->query('SHOW TABLES')->fetchAll();
foreach($existTables as $key => $table) $existTables[$key] = current((array)$table);
$existTables = array_flip($existTables);
foreach($renameTables as $oldTable => $newTable)
{
if(isset($existTables[$newTable]))
{
echo "Has existed table '$newTable'\n";
}
elseif(!isset($existTables[$oldTable]))
{
echo "No found table '$oldTable'\n";
}
else
{
$dbh->query("RENAME TABLE `$oldTable` TO `$newTable`");
echo "RENAME TABLE `$oldTable` TO `$newTable`\n";
}
}
echo "Finish!\n";

View File

@@ -8,22 +8,3 @@ $config->url->faq = 'http://www.zentao.net/ask-faq.html';
$config->url->extension = 'http://www.zentao.net/extension-browse.html';
$config->url->donation = 'http://www.zentao.net/help-donation.html';
$config->url->service = 'http://www.cnezsoft.com/article-browse-1078.html';
$config->win2Unix = new stdclass();
$config->win2Unix->renameTables = array(
'zt_casestep' => 'zt_caseStep' ,
'zt_doclib' => 'zt_docLib' ,
'zt_grouppriv' => 'zt_groupPriv' ,
'zt_productplan' => 'zt_productPlan' ,
'zt_projectproduct' => 'zt_projectProduct' ,
'zt_projectstory' => 'zt_projectStory' ,
'zt_storyspec' => 'zt_storySpec' ,
'zt_taskestimate' => 'zt_taskEstimate' ,
'zt_testresult' => 'zt_testResult' ,
'zt_testrun' => 'zt_testRun' ,
'zt_testtask' => 'zt_testTask' ,
'zt_usercontact' => 'zt_userContact' ,
'zt_usergroup' => 'zt_userGroup' ,
'zt_userquery' => 'zt_userQuery' ,
'zt_usertpl' => 'zt_userTPL'
);

View File

@@ -121,39 +121,6 @@ class admin extends control
}
}
/**
* Rename table for from windows to linux.
*
* @access public
* @return void
*/
public function win2Unix()
{
$renameTables = $this->config->win2Unix->renameTables;
$existTables = $this->dbh->query('SHOW TABLES')->fetchAll();
foreach($existTables as $key => $table) $existTables[$key] = current((array)$table);
$existTables = array_flip($existTables);
foreach($renameTables as $oldTable => $newTable)
{
if(isset($existTables[$newTable]))
{
echo "Has existed table '$newTable'\n";
}
elseif(!isset($existTables[$oldTable]))
{
echo "No found table '$oldTable'\n";
}
else
{
$this->dbh->query("RENAME TABLE `$oldTable` TO `$newTable`");
echo "RENAME TABLE `$oldTable` TO `$newTable`\n";
}
}
echo "Finish!\n";
}
/**
* Confirm clear data.
*