From eee2645fdb55e4e280bf5d3a2dac76f616e849c4 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 20 Jun 2014 02:18:08 +0000 Subject: [PATCH] * finish task #1893. --- bin/init.sh | 9 ------ bin/php/win2unix.php | 60 ------------------------------------- db/zentao.sql | 62 +++++++++++++++++++-------------------- module/upgrade/config.php | 17 +++++++++++ module/upgrade/model.php | 37 +++++++++++++++++++++++ 5 files changed, 85 insertions(+), 100 deletions(-) delete mode 100755 bin/php/win2unix.php create mode 100644 module/upgrade/config.php diff --git a/bin/init.sh b/bin/init.sh index 778cf81483..7dbf98b722 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -73,15 +73,6 @@ fi echo $checkdb > $basePath/checkdb.sh echo "checkdb.sh ok" -# win to unix -if [ $requestType == 'PATH_INFO' ]; then - win2Unix="$phpcli $basePath/ztcli '$pmsRoot/admin-win2Unix'"; -else - win2Unix="$phpcli $basePath/ztcli '$pmsRoot/index.php?m=admin&f=win2Unix'"; -fi -echo $win2Unix > $basePath/win2unix.sh -echo "win2unix.sh ok" - # syncsvn. if [ $requestType == 'PATH_INFO' ]; then syncsvn="$phpcli $basePath/ztcli '$pmsRoot/svn-run'"; diff --git a/bin/php/win2unix.php b/bin/php/win2unix.php deleted file mode 100755 index 360f2cc0bd..0000000000 --- a/bin/php/win2unix.php +++ /dev/null @@ -1,60 +0,0 @@ -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"); -} -catch(PDOException $e) -{ - echo 'Connection failed: ' . $e->getMessage() . "\n"; - die("connect to db failed.\n"); -} - -$tablesExists = $dbh->query('SHOW TABLES')->fetchAll(); -foreach($tablesExists as $key => $table) $tablesExists[$key] = current((array)$table); -$tablesExists = array_flip($tablesExists); - -foreach($tables2Rename as $oldTable => $newTable) -{ - if(isset($tablesExists[$newTable])) - { - echo "Has existed table '$newTable'\n"; - } - elseif(!isset($tablesExists[$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"; diff --git a/db/zentao.sql b/db/zentao.sql index f9f58f4f6b..0fb60cc5a9 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -119,8 +119,8 @@ CREATE TABLE IF NOT EXISTS `zt_case` ( `lastRunResult` char(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_caseStep`; -CREATE TABLE IF NOT EXISTS `zt_caseStep` ( +-- DROP TABLE IF EXISTS `zt_casestep`; +CREATE TABLE IF NOT EXISTS `zt_casestep` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `case` mediumint(8) unsigned NOT NULL default '0', `version` smallint(3) unsigned NOT NULL default '0', @@ -201,8 +201,8 @@ CREATE TABLE IF NOT EXISTS `zt_doc` ( `deleted` enum('0','1') NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_docLib`; -CREATE TABLE IF NOT EXISTS `zt_docLib` ( +-- DROP TABLE IF EXISTS `zt_doclib`; +CREATE TABLE IF NOT EXISTS `zt_doclib` ( `id` smallint(5) unsigned NOT NULL auto_increment, `name` varchar(60) NOT NULL, `deleted` enum('0','1') NOT NULL default '0', @@ -270,8 +270,8 @@ CREATE TABLE IF NOT EXISTS `zt_group` ( `desc` char(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_groupPriv`; -CREATE TABLE IF NOT EXISTS `zt_groupPriv` ( +-- DROP TABLE IF EXISTS `zt_grouppriv`; +CREATE TABLE IF NOT EXISTS `zt_grouppriv` ( `group` mediumint(8) unsigned NOT NULL default '0', `module` char(30) NOT NULL default '', `method` char(30) NOT NULL default '', @@ -318,8 +318,8 @@ CREATE TABLE IF NOT EXISTS `zt_product` ( `deleted` enum('0','1') NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_productPlan`; -CREATE TABLE IF NOT EXISTS `zt_productPlan` ( +-- DROP TABLE IF EXISTS `zt_productplan`; +CREATE TABLE IF NOT EXISTS `zt_productplan` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `product` mediumint(8) unsigned NOT NULL, `title` varchar(90) NOT NULL, @@ -363,14 +363,14 @@ CREATE TABLE IF NOT EXISTS `zt_project` ( PRIMARY KEY (`id`), KEY `project` (`type`,`parent`,`begin`,`end`,`status`,`statge`,`pri`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_projectProduct`; -CREATE TABLE IF NOT EXISTS `zt_projectProduct` ( +-- DROP TABLE IF EXISTS `zt_projectproduct`; +CREATE TABLE IF NOT EXISTS `zt_projectproduct` ( `project` mediumint(8) unsigned NOT NULL, `product` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`project`,`product`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_projectStory`; -CREATE TABLE IF NOT EXISTS `zt_projectStory` ( +-- DROP TABLE IF EXISTS `zt_projectstory`; +CREATE TABLE IF NOT EXISTS `zt_projectstory` ( `project` mediumint(8) unsigned NOT NULL default '0', `product` mediumint(8) unsigned NOT NULL, `story` mediumint(8) unsigned NOT NULL default '0', @@ -428,8 +428,8 @@ CREATE TABLE IF NOT EXISTS `zt_story` ( KEY `product` (`product`,`module`,`plan`,`type`,`pri`), KEY `status` (`status`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_storySpec`; -CREATE TABLE IF NOT EXISTS `zt_storySpec` ( +-- DROP TABLE IF EXISTS `zt_storyspec`; +CREATE TABLE IF NOT EXISTS `zt_storyspec` ( `story` mediumint(9) NOT NULL, `version` smallint(6) NOT NULL, `title` varchar(90) NOT NULL, @@ -476,8 +476,8 @@ CREATE TABLE IF NOT EXISTS `zt_task` ( KEY `statusOrder` (`statusCustom`), KEY `type` (`type`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_taskEstimate`; -CREATE TABLE IF NOT EXISTS `zt_taskEstimate` ( +-- DROP TABLE IF EXISTS `zt_taskestimate`; +CREATE TABLE IF NOT EXISTS `zt_taskestimate` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `task` mediumint(8) unsigned NOT NULL default '0', `date` date NOT NULL, @@ -498,8 +498,8 @@ CREATE TABLE IF NOT EXISTS `zt_team` ( `hours` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`project`,`account`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_testResult`; -CREATE TABLE IF NOT EXISTS `zt_testResult` ( +-- DROP TABLE IF EXISTS `zt_testresult`; +CREATE TABLE IF NOT EXISTS `zt_testresult` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `run` mediumint(8) unsigned NOT NULL, `case` mediumint(8) unsigned NOT NULL, @@ -512,8 +512,8 @@ CREATE TABLE IF NOT EXISTS `zt_testResult` ( KEY `run` (`run`), KEY `case` (`case`,`version`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_testRun`; -CREATE TABLE IF NOT EXISTS `zt_testRun` ( +-- DROP TABLE IF EXISTS `zt_testrun`; +CREATE TABLE IF NOT EXISTS `zt_testrun` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `task` mediumint(8) unsigned NOT NULL default '0', `case` mediumint(8) unsigned NOT NULL default '0', @@ -526,8 +526,8 @@ CREATE TABLE IF NOT EXISTS `zt_testRun` ( PRIMARY KEY (`id`), UNIQUE KEY `task` (`task`,`case`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_testTask`; -CREATE TABLE IF NOT EXISTS `zt_testTask` ( +-- DROP TABLE IF EXISTS `zt_testtask`; +CREATE TABLE IF NOT EXISTS `zt_testtask` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `name` char(90) NOT NULL, `product` mediumint(8) unsigned NOT NULL, @@ -594,22 +594,22 @@ CREATE TABLE IF NOT EXISTS `zt_user` ( UNIQUE KEY `account` (`account`), KEY `dept` (`dept`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_userContact`; -CREATE TABLE IF NOT EXISTS `zt_userContact` ( +-- DROP TABLE IF EXISTS `zt_usercontact`; +CREATE TABLE IF NOT EXISTS `zt_usercontact` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `account` char(30) NOT NULL, `listName` varchar(60) NOT NULL, `userList` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_userGroup`; -CREATE TABLE IF NOT EXISTS `zt_userGroup` ( +-- DROP TABLE IF EXISTS `zt_usergroup`; +CREATE TABLE IF NOT EXISTS `zt_usergroup` ( `account` char(30) NOT NULL default '', `group` mediumint(8) unsigned NOT NULL default '0', UNIQUE KEY `account` (`account`,`group`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_userQuery`; -CREATE TABLE IF NOT EXISTS `zt_userQuery` ( +-- DROP TABLE IF EXISTS `zt_userquery`; +CREATE TABLE IF NOT EXISTS `zt_userquery` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `account` char(30) NOT NULL, `module` varchar(30) NOT NULL, @@ -620,8 +620,8 @@ CREATE TABLE IF NOT EXISTS `zt_userQuery` ( KEY `account` (`account`), KEY `module` (`module`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_userTPL`; -CREATE TABLE IF NOT EXISTS `zt_userTPL` ( +-- DROP TABLE IF EXISTS `zt_usertpl`; +CREATE TABLE IF NOT EXISTS `zt_usertpl` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `account` char(30) NOT NULL, `type` char(30) NOT NULL, @@ -644,7 +644,7 @@ INSERT INTO `zt_group` (`id`, `name`, `role`, `desc`) VALUES (10, 'OTHERS', '', 'for others.'), (11, 'guest', 'guest', 'For guest'); -INSERT INTO `zt_groupPriv` (`group`, `module`, `method`) VALUES +INSERT INTO `zt_grouppriv` (`group`, `module`, `method`) VALUES (1, 'action', 'hideAll'), (1, 'action', 'hideOne'), (1, 'action', 'trash'), diff --git a/module/upgrade/config.php b/module/upgrade/config.php new file mode 100644 index 0000000000..ad9d97b0bc --- /dev/null +++ b/module/upgrade/config.php @@ -0,0 +1,17 @@ +upgrade->lowerTables = array(); +$config->upgrade->lowerTables['zt_caseStep'] = 'zt_casestep'; +$config->upgrade->lowerTables['zt_docLib'] = 'zt_doclib'; +$config->upgrade->lowerTables['zt_groupPriv'] = 'zt_grouppriv'; +$config->upgrade->lowerTables['zt_productPlan'] = 'zt_productplan'; +$config->upgrade->lowerTables['zt_projectProduct'] = 'zt_projectproduct'; +$config->upgrade->lowerTables['zt_projectStory'] = 'zt_projectstory'; +$config->upgrade->lowerTables['zt_storySpec'] = 'zt_storyspec'; +$config->upgrade->lowerTables['zt_taskEstimate'] = 'zt_taskestimate'; +$config->upgrade->lowerTables['zt_testResult'] = 'zt_testresult'; +$config->upgrade->lowerTables['zt_testRun'] = 'zt_testrun'; +$config->upgrade->lowerTables['zt_testTask'] = 'zt_testtask'; +$config->upgrade->lowerTables['zt_userContact'] = 'zt_usercontact'; +$config->upgrade->lowerTables['zt_userGroup'] = 'zt_usergroup'; +$config->upgrade->lowerTables['zt_userQuery'] = 'zt_userquery'; +$config->upgrade->lowerTables['zt_userTPL'] = 'zt_usertpl'; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 7a5e5dba13..9b1f6c7069 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -710,6 +710,43 @@ class upgradeModel extends model return true; } + public function toLowerTable($build = 'basic') + { + $results = $this->dbh->query("show Variables like '%table_names'")->fetchAll(); + $hasLowered = false; + foreach($results as $result) + { + if(strtolower($result->Variable_name) == 'lower_case_table_names' and $result->Value == 1) + { + $hasLowered = true; + break; + } + } + if($hasLowered) return true; + + if($build == 'basic') $tables2Rename = $this->config->upgrade->lowerTables; + if(!isset($tables2Rename)) return false; + + $tablesExists = $this->dbh->query('SHOW TABLES')->fetchAll(); + foreach($tablesExists as $key => $table) $tablesExists[$key] = current((array)$table); + $tablesExists = array_flip($tablesExists); + + foreach($tables2Rename as $oldTable => $newTable) + { + if(!isset($tablesExists[$oldTable])) continue; + + $upgradebak = $newTable . '_othertablebak'; + if(isset($tablesExists[$upgradebak])) $this->dbh->query("DROP TABLE `$upgradebak`"); + if(isset($tablesExists[$newTable])) $this->dbh->query("RENAME TABLE `$newTable` TO `$upgradebak`"); + + $tempTable = $oldTable . '_zentaotmp'; + $this->dbh->query("RENAME TABLE `$oldTable` TO `$tempTable`"); + $this->dbh->query("RENAME TABLE `$tempTable` TO `$newTable`"); + } + + return true; + } + /** * Process finishedBy and finishedDate of task. *