* @package upgrade * @version $Id: model.php 5019 2013-07-05 02:02:31Z wyd621@gmail.com $ * @link http://www.zentao.net */ ?> loadModel('setting'); } /** * The execute method. According to the $fromVersion call related methods. * * @param string $fromVersion * @access public * @return void */ public function execute($fromVersion) { set_time_limit(0); $executeXuanxuan = false; switch($fromVersion) { case '0_3beta': $this->saveLogs('Execute 0_3beta'); $this->execSQL($this->getUpgradeFile('0.3')); case '0_4beta': $this->saveLogs('Execute 0_4beta'); $this->execSQL($this->getUpgradeFile('0.4')); case '0_5beta': $this->saveLogs('Execute 0_5beta'); $this->execSQL($this->getUpgradeFile('0.5')); case '0_6beta': $this->saveLogs('Execute 0_6beta'); $this->execSQL($this->getUpgradeFile('0.6')); case '1_0beta': $this->saveLogs('Execute 1_0beta'); $this->execSQL($this->getUpgradeFile('1.0.beta')); $this->updateCompany(); case '1_0rc1': $this->saveLogs('Execute 1_0rc1'); $this->execSQL($this->getUpgradeFile('1.0.rc1')); case '1_0rc2': $this->saveLogs('Execute 1_0rc2'); case '1_0': $this->saveLogs('Execute 1_0'); case '1_0_1': $this->saveLogs('Execute 1_0_1'); $this->execSQL($this->getUpgradeFile('1.0.1')); case '1_1': $this->saveLogs('Execute 1_1'); $this->execSQL($this->getUpgradeFile('1.1')); case '1_2': $this->saveLogs('Execute 1_2'); $this->execSQL($this->getUpgradeFile('1.2')); $this->updateUBB(); $this->updateNL1_2(); case '1_3': $this->saveLogs('Execute 1_3'); $this->execSQL($this->getUpgradeFile('1.3')); $this->updateNL1_3(); $this->updateTasks(); case '1_4': $this->saveLogs('Execute 1_4'); $this->execSQL($this->getUpgradeFile('1.4')); case '1_5': $this->saveLogs('Execute 1_5'); $this->execSQL($this->getUpgradeFile('1.5')); case '2_0': $this->saveLogs('Execute 2_0'); $this->execSQL($this->getUpgradeFile('2.0')); case '2_1': $this->saveLogs('Execute 2_1'); $this->execSQL($this->getUpgradeFile('2.1')); case '2_2': $this->saveLogs('Execute 2_2'); $this->execSQL($this->getUpgradeFile('2.2')); $this->updateCases(); $this->updateActivatedCountOfBug(); case '2_3': $this->saveLogs('Execute 2_3'); $this->execSQL($this->getUpgradeFile('2.3')); case '2_4': $this->saveLogs('Execute 2_4'); $this->execSQL($this->getUpgradeFile('2.4')); case '3_0_beta1': $this->saveLogs('Execute 3_0_beta1'); $this->execSQL($this->getUpgradeFile('3.0.beta1')); $this->updateAction(); $this->setOrderData(); case '3_0_beta2': $this->saveLogs('Execute 3_0_beta2'); case '3_0': $this->saveLogs('Execute 3_0'); case '3_1': $this->saveLogs('Execute 3_1'); $this->execSQL($this->getUpgradeFile('3.1')); case '3_2': $this->saveLogs('Execute 3_2'); $this->execSQL($this->getUpgradeFile('3.2')); case '3_2_1': $this->saveLogs('Execute 3_2_1'); $this->execSQL($this->getUpgradeFile('3.2.1')); case '3_3': $this->saveLogs('Execute 3_3'); $this->execSQL($this->getUpgradeFile('3.3')); $this->updateTaskAssignedTo(); case '4_0_beta1': $this->saveLogs('Execute 4_0_beta1'); $this->execSQL($this->getUpgradeFile('4.0.beta1')); case '4_0_beta2': $this->saveLogs('Execute 4_0_beta2'); $this->execSQL($this->getUpgradeFile('4.0.beta2')); $this->updateProjectType(); $this->updateEstimatePriv(); case '4_0': $this->saveLogs('Execute 4_0'); $this->execSQL($this->getUpgradeFile('4.0')); case '4_0_1': $this->saveLogs('Execute 4_0_1'); $this->execSQL($this->getUpgradeFile('4.0.1')); $this->addPriv4_0_1(); case '4_1': $this->saveLogs('Execute 4_1'); $this->execSQL($this->getUpgradeFile('4.1')); $this->addPriv4_1(); $this->processTaskFinish(); $this->deleteCompany(); case '4_2_beta': $this->saveLogs('Execute 4_2_beta'); $this->execSQL($this->getUpgradeFile('4.2')); case '4_3_beta': $this->saveLogs('Execute 4_3_beta'); $this->execSQL($this->getUpgradeFile('4.3')); case '5_0_beta1': $this->saveLogs('Execute 5_0_beta1'); case '5_0_beta2': $this->saveLogs('Execute 5_0_beta2'); case '5_0': $this->saveLogs('Execute 5_0'); case '5_1': $this->saveLogs('Execute 5_1'); case '5_2': $this->saveLogs('Execute 5_2'); case '5_2_1': $this->saveLogs('Execute 5_2_1'); $this->mergeProjectGoalAndDesc(); $this->execSQL($this->getUpgradeFile('5.2.1')); case '5_3': $this->saveLogs('Execute 5_3'); case '6_0_beta1': $this->saveLogs('Execute 6_0_beta'); $this->execSQL($this->getUpgradeFile('6.0.beta1')); $this->toLowerTable(); $this->fixBugOSInfo(); $this->fixTaskFinishedBy(); case '6_0': $this->saveLogs('Execute 6_0'); $this->execSQL($this->getUpgradeFile('6.0')); $this->fixDataIndex(); case '6_1': $this->saveLogs('Execute 6_1'); $this->execSQL($this->getUpgradeFile('6.1')); case '6_2': $this->saveLogs('Execute 6_2'); case '6_3': $this->saveLogs('Execute 6_3'); case '6_4': $this->saveLogs('Execute 6_4'); case '7_0': $this->saveLogs('Execute 7_0'); $this->execSQL($this->getUpgradeFile('7.0')); case '7_1': $this->saveLogs('Execute 7_1'); $this->execSQL($this->getUpgradeFile('7.1')); $this->initOrder(); case '7_2': $this->saveLogs('Execute 7_2'); case '7_2_4': $this->saveLogs('Execute 7_2_4'); $this->execSQL($this->getUpgradeFile('7.2.4')); case '7_2_5': $this->saveLogs('Execute 7_2_5'); $this->adjustOrder7_3(); case '7_3': $this->saveLogs('Execute 7_3'); $this->execSQL($this->getUpgradeFile('7.3')); $this->adjustPriv7_4_beta(); case '7_4_beta': $this->saveLogs('Execute 7_4_beta'); $this->execSQL($this->getUpgradeFile('7.4.beta')); case '8_0': $this->saveLogs('Execute 8_0'); case '8_0_1': $this->saveLogs('Execute 8_0_1'); $this->execSQL($this->getUpgradeFile('8.0.1')); $this->addPriv8_1(); case '8_1': $this->saveLogs('Execute 8_1'); $this->execSQL($this->getUpgradeFile('8.1')); case '8_1_3': $this->saveLogs('Execute 8_1_3'); $this->execSQL($this->getUpgradeFile('8.1.3')); $this->addPriv8_2_beta(); $this->adjustConfigSectionAndKey(); case '8_2_beta': $this->saveLogs('Execute 8_2_beta'); case '8_2': $this->saveLogs('Execute 8_2'); case '8_2_1': $this->saveLogs('Execute 8_2_1'); $this->execSQL($this->getUpgradeFile('8.2.1')); case '8_2_2': $this->saveLogs('Execute 8_2_2'); case '8_2_3': $this->saveLogs('Execute 8_2_3'); case '8_2_4': $this->saveLogs('Execute 8_2_4'); case '8_2_5': $this->saveLogs('Execute 8_2_5'); case '8_2_6': $this->saveLogs('Execute 8_2_6'); $this->execSQL($this->getUpgradeFile('8.2.6')); $this->adjustDocModule(); $this->moveDocContent(); $this->adjustPriv8_3(); case '8_3': $this->saveLogs('Execute 8_3'); case '8_3_1': $this->saveLogs('Execute 8_3_1'); $this->execSQL($this->getUpgradeFile('8.3.1')); $this->renameMainLib(); $this->adjustPriv8_4(); case '8_4': $this->saveLogs('Execute 8_4'); case '8_4_1': $this->saveLogs('Execute 8_4_1'); $this->execSQL($this->getUpgradeFile('8.4.1')); case '9_0_beta': $this->saveLogs('Execute 9_0_beta'); $this->execSQL($this->getUpgradeFile('9.0.beta')); $this->adjustPriv9_0(); case '9_0': $this->saveLogs('Execute 9_0'); $this->fixProjectProductData(); case '9_0_1': $this->saveLogs('Execute 9_0_1'); $this->execSQL($this->getUpgradeFile('9.0.1')); $this->addBugDeadlineToCustomFields(); $this->adjustPriv9_0_1(); case '9_1': $this->saveLogs('Execute 9_1'); $this->execSQL($this->getUpgradeFile('9.1')); case '9_1_1': $this->saveLogs('Execute 9_1_1'); $this->execSQL($this->getUpgradeFile('9.1.1')); case '9_1_2': $this->saveLogs('Execute 9_1_2'); $this->execSQL($this->getUpgradeFile('9.1.2')); $this->processCustomMenus(); $this->adjustPriv9_2(); case '9_2': $this->saveLogs('Execute 9_2'); case '9_2_1': $this->saveLogs('Execute 9_2_1'); case '9_3_beta': $this->saveLogs('Execute 9_3_beta'); $this->execSQL($this->getUpgradeFile('9.3.beta')); case '9_4': $this->saveLogs('Execute 9_4'); $this->execSQL($this->getUpgradeFile('9.4')); $this->adjustPriv9_4(); case '9_5': $this->saveLogs('Execute 9_5'); $this->execSQL($this->getUpgradeFile('9.5')); case '9_5_1': $this->saveLogs('Execute 9_5_1'); $this->execSQL($this->getUpgradeFile('9.5.1')); $this->initProjectStoryOrder(); case '9_6': $this->saveLogs('Execute 9_6'); $this->execSQL($this->getUpgradeFile('9.6')); $this->fixDatatableColsConfig(); case '9_6_1': $this->saveLogs('Execute 9_6_1'); $this->addLimitedGroup(); case '9_6_2': $this->saveLogs('Execute 9_6_2'); case '9_6_3': $this->saveLogs('Execute 9_6_3'); $this->execSQL($this->getUpgradeFile('9.6.3')); $this->changeLimitedName(); $this->adjustPriv9_7(); $this->changeStoryWidth(); case '9_7': $this->saveLogs('Execute 9_7'); $this->execSQL($this->getUpgradeFile('9.7')); $this->changeTeamFields(); $this->moveData2Notify(); case '9_8': $this->saveLogs('Execute 9_8'); $this->fixTaskFinishedInfo(); case '9_8_1': $this->saveLogs('Execute 9_8_1'); $this->execSQL($this->getUpgradeFile('9.8.1')); $this->fixTaskAssignedTo(); $this->fixProjectClosedInfo(); $this->resetProductLine(); case '9_8_2': $this->saveLogs('Execute 9_8_2'); $this->execSQL($this->getUpgradeFile('9.8.2')); $this->addUniqueKeyToTeam(); case '9_8_3': $this->saveLogs('Execute 9_8_3'); $this->execSQL($this->getUpgradeFile('9.8.3')); $this->adjustPriv10_0_alpha(); case '10_0_alpha': $this->saveLogs('Execute 10_0_alpha'); $this->execSQL($this->getUpgradeFile('10.0.alpha')); $this->fixProjectStatisticBlock(); case '10_0_beta': $this->saveLogs('Execute 10_0_beta'); $this->execSQL($this->getUpgradeFile('10.0.beta')); case '10_0': $this->saveLogs('Execute 10_0'); $this->execSQL($this->getUpgradeFile('10.0')); $this->fixStorySpecTitle(); $this->removeUnlinkPriv();//Remove unlink privilege for story, bug and testcase module. case '10_1': $this->saveLogs('Execute 10_1'); $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'xuanxuan.sql'; $this->execSQL($xuanxuanSql); $executeXuanxuan = true; case '10_2': $this->saveLogs('Execute 10_2'); case '10_3': $this->saveLogs('Execute 10_3'); case '10_3_1': $this->saveLogs('Execute 10_3_1'); $this->execSQL($this->getUpgradeFile('10.3.1')); $this->removeCustomMenu(); $this->initUserView(); case '10_4': $this->saveLogs('Execute 10_4'); $this->execSQL($this->getUpgradeFile('10.4')); $this->changeTaskParentValue(); case '10_5': $this->saveLogs('Execute 10_5'); case '10_5_1': $this->saveLogs('Execute 10_5_1'); $this->execSQL($this->getUpgradeFile('10.5.1')); case '10_6': $this->saveLogs('Execute 10_6'); if(!$executeXuanxuan) { $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.1.0.sql'; $this->execSQL($xuanxuanSql); $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.2.0.sql'; $this->execSQL($xuanxuanSql); } $this->initXuanxuan(); case '11_0': $this->saveLogs('Execute 11_0'); case '11_1': $this->saveLogs('Execute 11_1'); $this->execSQL($this->getUpgradeFile('11.1')); if(!isset($this->config->isINT) or !($this->config->isINT)) { if(!$executeXuanxuan) { $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.3.0.sql'; $this->execSQL($xuanxuanSql); } $this->dao->update(TABLE_CONFIG)->set('value')->eq('off')->where('`key`')->eq('isHttps')->andWhere('`section`')->eq('xuanxuan')->andWhere('`value`')->eq('0')->exec(); $this->dao->update(TABLE_CONFIG)->set('value')->eq('on')->where('`key`')->eq('isHttps')->andWhere('`section`')->eq('xuanxuan')->andWhere('`value`')->eq('1')->exec(); } case '11_2': $this->saveLogs('Execute 11_2'); $this->execSQL($this->getUpgradeFile('11.2')); $this->processDocLibAcl(); case '11_3': $this->saveLogs('Execute 11_3'); $this->execSQL($this->getUpgradeFile('11.3')); $this->addPriv11_4(); case '11_4': $this->saveLogs('Execute 11_4'); $this->execSQL($this->getUpgradeFile('11.4')); case '11_4_1': $this->saveLogs('Execute 11_4_1'); $this->execSQL($this->getUpgradeFile('11.4.1')); $this->addPriv11_5(); if(!isset($this->config->isINT) or !($this->config->isINT)) { if(!$executeXuanxuan) { $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.4.0.sql'; $this->execSQL($xuanxuanSql); $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.5.0.sql'; $this->execSQL($xuanxuanSql); } $this->updateXX_11_5(); } } $this->deletePatch(); return true; } /** * Create the confirm contents. * * @param string $fromVersion * @access public * @return string */ public function getConfirm($fromVersion) { $confirmContent = ''; switch($fromVersion) { case '0_3beta': $confirmContent .= file_get_contents($this->getUpgradeFile('0.3')); case '0_4beta': $confirmContent .= file_get_contents($this->getUpgradeFile('0.4')); case '0_5beta': $confirmContent .= file_get_contents($this->getUpgradeFile('0.5')); case '0_6beta': $confirmContent .= file_get_contents($this->getUpgradeFile('0.6')); case '1_0beta': $confirmContent .= file_get_contents($this->getUpgradeFile('1.0.beta')); case '1_0rc1': $confirmContent .= file_get_contents($this->getUpgradeFile('1.0.rc1')); case '1_0rc2': case '1_0': case '1_0_1': $confirmContent .= file_get_contents($this->getUpgradeFile('1.0.1')); case '1_1': $confirmContent .= file_get_contents($this->getUpgradeFile('1.1')); case '1_2': $confirmContent .= file_get_contents($this->getUpgradeFile('1.2')); case '1_3': $confirmContent .= file_get_contents($this->getUpgradeFile('1.3')); case '1_4': $confirmContent .= file_get_contents($this->getUpgradeFile('1.4')); case '1_5': $confirmContent .= file_get_contents($this->getUpgradeFile('1.5')); case '2_0': $confirmContent .= file_get_contents($this->getUpgradeFile('2.0')); case '2_1': $confirmContent .= file_get_contents($this->getUpgradeFile('2.1')); case '2_2': $confirmContent .= file_get_contents($this->getUpgradeFile('2.2')); case '2_3': $confirmContent .= file_get_contents($this->getUpgradeFile('2.3')); case '2_4': $confirmContent .= file_get_contents($this->getUpgradeFile('2.4')); case '3_0_beta1': $confirmContent .= file_get_contents($this->getUpgradeFile('3.0.beta1')); case '3_0_beta2': case '3_0': case '3_1': $confirmContent .= file_get_contents($this->getUpgradeFile('3.1')); case '3_2': $confirmContent .= file_get_contents($this->getUpgradeFile('3.2')); case '3_2_1': $confirmContent .= file_get_contents($this->getUpgradeFile('3.2.1')); case '3_3': $confirmContent .= file_get_contents($this->getUpgradeFile('3.3')); case '4_0_beta1': $confirmContent .= file_get_contents($this->getUpgradeFile('4.0.beta1')); case '4_0_beta2': $confirmContent .= file_get_contents($this->getUpgradeFile('4.0.beta2')); case '4_0': $confirmContent .= file_get_contents($this->getUpgradeFile('4.0')); case '4_0_1': $confirmContent .= file_get_contents($this->getUpgradeFile('4.0.1')); case '4_1': $confirmContent .= file_get_contents($this->getUpgradeFile('4.1')); case '4_2_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('4.2')); case '4_3_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('4.3')); case '5_0_beta1': case '5_0_beta2': case '5_0': case '5_1': case '5_2': case '5_2_1': $confirmContent .= file_get_contents($this->getUpgradeFile('5.2.1')); case '5_3': case '6_0_beta1': $confirmContent .= file_get_contents($this->getUpgradeFile('6.0.beta1')); case '6_0': $confirmContent .= file_get_contents($this->getUpgradeFile('6.0')); case '6_1': $confirmContent .= file_get_contents($this->getUpgradeFile('6.1')); case '6_2': case '6_3': case '6_4': case '7_0': $confirmContent .= file_get_contents($this->getUpgradeFile('7.0')); case '7_1': $confirmContent .= file_get_contents($this->getUpgradeFile('7.1')); case '7_2': case '7_2_4': $confirmContent .= file_get_contents($this->getUpgradeFile('7.2.4')); case '7_2_5': case '7_3': $confirmContent .= file_get_contents($this->getUpgradeFile('7.3')); case '7_4_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('7.4.beta')); case '8_0': case '8_0_1': $confirmContent .= file_get_contents($this->getUpgradeFile('8.0.1')); case '8_1': $confirmContent .= file_get_contents($this->getUpgradeFile('8.1')); case '8_1_3': $confirmContent .= file_get_contents($this->getUpgradeFile('8.1.3')); case '8_2_beta': case '8_2': case '8_2_1': $confirmContent .= file_get_contents($this->getUpgradeFile('8.2.1')); case '8_2_2': case '8_2_3': case '8_2_4': case '8_2_5': case '8_2_6': $confirmContent .= file_get_contents($this->getUpgradeFile('8.2.6')); case '8_3': case '8_3_1': $confirmContent .= file_get_contents($this->getUpgradeFile('8.3.1')); case '8_4': case '8_4_1': $confirmContent .= file_get_contents($this->getUpgradeFile('8.4.1')); case '9_0_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('9.0.beta')); case '9_0': case '9_0_1': $confirmContent .= file_get_contents($this->getUpgradeFile('9.0.1')); case '9_1': $confirmContent .= file_get_contents($this->getUpgradeFile('9.1')); case '9_1_1': $confirmContent .= file_get_contents($this->getUpgradeFile('9.1.1')); case '9_1_2': $confirmContent .= file_get_contents($this->getUpgradeFile('9.1.2')); case '9_2': case '9_2_1': case '9_3_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('9.3.beta')); case '9_4': $confirmContent .= file_get_contents($this->getUpgradeFile('9.4')); case '9_5': $confirmContent .= file_get_contents($this->getUpgradeFile('9.5')); case '9_5_1': $confirmContent .= file_get_contents($this->getUpgradeFile('9.5.1')); case '9_6': $confirmContent .= file_get_contents($this->getUpgradeFile('9.6')); case '9_6_1': case '9_6_2': case '9_6_3': $confirmContent .= file_get_contents($this->getUpgradeFile('9.6.3')); case '9_7': $confirmContent .= file_get_contents($this->getUpgradeFile('9.7')); case '9_8': case '9_8_1': $confirmContent .= file_get_contents($this->getUpgradeFile('9.8.1')); case '9_8_2': $confirmContent .= file_get_contents($this->getUpgradeFile('9.8.2')); case '9_8_3': $confirmContent .= file_get_contents($this->getUpgradeFile('9.8.3')); case '10_0_alpha': $confirmContent .= file_get_contents($this->getUpgradeFile('10.0.alpha')); case '10_0_beta': $confirmContent .= file_get_contents($this->getUpgradeFile('10.0.beta')); case '10_0': $confirmContent .= file_get_contents($this->getUpgradeFile('10.0')); case '10_1': $confirmContent .= file_get_contents($this->app->getAppRoot() . 'db' . DS . 'xuanxuan.sql'); case '10_2': case '10_3': case '10_3_1': $confirmContent .= file_get_contents($this->getUpgradeFile('10.3.1')); case '10_4': $confirmContent .= file_get_contents($this->getUpgradeFile('10.4')); case '10_5': case '10_5_1': $confirmContent .= file_get_contents($this->getUpgradeFile('10.5.1')); case '10_6': $confirmContent .= file_get_contents($this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.1.0.sql'); $confirmContent .= file_get_contents($this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.2.0.sql'); case '11_0': case '11_1': $confirmContent .= file_get_contents($this->getUpgradeFile('11.1')); if(!isset($this->config->isINT) or !($this->config->isINT)) { $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.3.0.sql'; $confirmContent .= file_get_contents($xuanxuanSql); } case '11_2': $confirmContent .= file_get_contents($this->getUpgradeFile('11.2')); case '11_3': $confirmContent .= file_get_contents($this->getUpgradeFile('11.3')); case '11_4': $confirmContent .= file_get_contents($this->getUpgradeFile('11.4')); case '11_4_1': $confirmContent .= file_get_contents($this->getUpgradeFile('11.4.1')); if(!isset($this->config->isINT) or !($this->config->isINT)) { $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.4.0.sql'; $confirmContent .= file_get_contents($xuanxuanSql); $xuanxuanSql = $this->app->getAppRoot() . 'db' . DS . 'upgradexuanxuan2.5.0.sql'; $confirmContent .= file_get_contents($xuanxuanSql); } } return str_replace('zt_', $this->config->db->prefix, $confirmContent); } /** * Update company field. * * This method is used to update since 1.0 beta. Any new tables added after 1.0 beta should skip. * * @access public * @return void */ public function updateCompany() { $this->saveLogs('Run Method ' . __FUNCTION__); /* Get user defined constants. */ $constants = get_defined_constants(true); $userConstants = $constants['user']; /* Update tables. */ foreach($userConstants as $key => $value) { if(strpos($key, 'TABLE') === false) continue; if($key == 'TABLE_COMPANY') continue; $table = $value; $result = $this->dbh->query("SHOW TABLES LIKE '$table'"); if($result->rowCount() > 0) { $this->dbh->query("UPDATE $table SET company = '{$this->app->company->id}'"); } } } /** * Check consistency. * * @param string $version * @access public * @return string */ public function checkConsistency($version = '') { if(empty($version)) $version = $this->config->installedVersion; $alterSQL = ''; $standardSQL = $this->app->getAppRoot() . 'db' . DS . 'standard' . DS . 'zentao' . $version . '.sql'; if(!file_exists($standardSQL)) return $alterSQL; $tableExists = true; $handle = fopen($standardSQL, 'r'); if($handle) { while(!feof($handle)) { $line = trim(fgets($handle)); if(strpos($line, 'DROP TABLE ') !== false) continue; if(strpos($line, 'CREATE TABLE ') !== false) { preg_match_all('/`([^`]*)`/', $line, $out); if(isset($out[1][0])) { $fields = array(); $table = str_replace('zt_', $this->config->db->prefix, $out[1][0]); try { $tableExists = true; $stmt = $this->dbh->query("show fields from `{$table}`"); while($row = $stmt->fetch()) $fields[$row->Field] = $row->Field; } catch(PDOException $e) { $errorInfo = $e->errorInfo; $errorCode = $errorInfo[1]; $line = str_replace('zt_', $this->config->db->prefix, $line); if($errorCode == '1146') $tableExists = false; } } } if(!$tableExists) $alterSQL .= $line . "\n"; if(!empty($fields)) { if(preg_match('/^`([^`]*)` /', $line)) { list($field) = explode(' ', $line); $field = trim($field, '`'); if(!isset($fields[$field])) { $line = rtrim($line, ','); if(stripos($line, 'auto_increment') !== false) $line .= ' primary key'; try { $this->dbh->exec("ALTER TABLE `{$table}` ADD $line"); } catch(PDOException $e) { $alterSQL .= "ALTER TABLE `{$table}` ADD $line;\n"; } } } } } fclose($handle); } return $alterSQL; } /** * Delete Useless Files * * @access public * @return array */ public function deleteFiles() { $result = array(); foreach($this->config->delete as $deleteFiles) { $basePath = $this->app->getBasePath(); foreach($deleteFiles as $file) { if(isset($this->config->excludeFiles[$file])) continue; $fullPath = $basePath . str_replace('/', DIRECTORY_SEPARATOR, $file); if(file_exists($fullPath) and !unlink($fullPath)) $result[] = $fullPath; } } return $result; } /** * Update ubb code in bug table and user Templates table to html. * * @access public * @return void */ public function updateUBB() { $this->saveLogs('Run Method ' . __FUNCTION__); $this->app->loadClass('ubb', true); $bugs = $this->dao->select('id, steps')->from(TABLE_BUG)->fetchAll(); $userTemplates = $this->dao->select('id, content')->from($this->config->db->prefix . 'userTPL')->fetchAll(); foreach($bugs as $id => $bug) { $bug->steps = ubb::parseUBB($bug->steps); $this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bug->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($userTemplates as $template) { $template->content = ubb::parseUBB($template->content); $this->dao->update($this->config->db->prefix . 'userTPL')->data($template)->where('id')->eq($template->id)->exec(); $this->saveLogs($this->dao->get()); } } /** * Update nl to br from 1.2 version. * * @access public * @return void */ public function updateNL1_2() { $this->saveLogs('Run Method ' . __FUNCTION__); $tasks = $this->dao->select('id, `desc`')->from(TABLE_TASK)->fetchAll(); $stories = $this->dao->select('story, version, spec')->from($this->config->db->prefix . 'storySpec')->fetchAll(); $todos = $this->dao->select('id, `desc`')->from(TABLE_TODO)->fetchAll(); $testTasks = $this->dao->select('id, `desc`')->from($this->config->db->prefix . 'testTask')->fetchAll(); foreach($tasks as $task) { $task->desc = nl2br($task->desc); $this->dao->update(TABLE_TASK)->data($task)->where('id')->eq($task->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($stories as $story) { $story->spec = nl2br($story->spec); $this->dao->update($this->config->db->prefix . 'storySpec')->data($story)->where('story')->eq($story->story)->andWhere('version')->eq($story->version)->exec(); $this->saveLogs($this->dao->get()); } foreach($todos as $todo) { $todo->desc = nl2br($todo->desc); $this->dao->update(TABLE_TODO)->data($todo)->where('id')->eq($todo->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($testTasks as $testtask) { $testtask->desc = nl2br($testtask->desc); $this->dao->update($this->config->db->prefix . 'testTask')->data($testtask)->where('id')->eq($testtask->id)->exec(); $this->saveLogs($this->dao->get()); } } /** * Update nl to br from 1.3 version. * * @access public * @return void */ public function updateNL1_3() { $this->saveLogs('Run Method ' . __FUNCTION__); $products = $this->dao->select('id, `desc`')->from(TABLE_PRODUCT)->fetchAll(); $plans = $this->dao->select('id, `desc`')->from($this->config->db->prefix . 'productPlan')->fetchAll(); $releases = $this->dao->select('id, `desc`')->from(TABLE_RELEASE)->fetchAll(); $projects = $this->dao->select('id, `desc`, goal')->from(TABLE_PROJECT)->fetchAll(); $builds = $this->dao->select('id, `desc`')->from(TABLE_BUILD)->fetchAll(); foreach($products as $product) { $product->desc = nl2br($product->desc); $this->dao->update(TABLE_PRODUCT)->data($product)->where('id')->eq($product->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($plans as $plan) { $plan->desc = nl2br($plan->desc); $this->dao->update($this->config->db->prefix . 'productPlan')->data($plan)->where('id')->eq($plan->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($releases as $release) { $release->desc = nl2br($release->desc); $this->dao->update(TABLE_RELEASE)->data($release)->where('id')->eq($release->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($projects as $project) { $project->desc = nl2br($project->desc); $project->goal = nl2br($project->goal); $this->dao->update(TABLE_PROJECT)->data($project)->where('id')->eq($project->id)->exec(); $this->saveLogs($this->dao->get()); } foreach($builds as $build) { $build->desc = nl2br($build->desc); $this->dao->update(TABLE_BUILD)->data($build)->where('id')->eq($build->id)->exec(); $this->saveLogs($this->dao->get()); } } /** * Update task fields. * * @access public * @return void */ public function updateTasks() { $this->saveLogs('Run Method ' . __FUNCTION__); /* Get all actions of tasks. */ $actions = $this->dao->select('*')->from(TABLE_ACTION) ->where('objectType')->eq('task') ->orderBy('id') ->fetchAll('id'); /* Get histories about status field. */ $histories = $this->dao->select()->from(TABLE_HISTORY) ->where('action')->in(array_keys($actions)) ->andWhere('field')->eq('status') ->orderBy('id') ->fetchGroup('action'); $tasks = array(); foreach($actions as $action) { if(!isset($tasks[$action->objectID])) { $tasks[$action->objectID] = new stdclass; } $task = $tasks[$action->objectID]; $task->id = $action->objectID; $actionType = strtolower($action->action); /* Set the openedBy info. */ if($actionType == 'opened') { $task->openedBy = $action->actor; $task->openedDate = $action->date; } else { if(!isset($histories[$action->id])) continue; $actionHistories = $histories[$action->id]; foreach($actionHistories as $history) { /* Finished by. */ if($history->new == 'done') { $task->finishedBy = $action->actor; $task->finishedDate = $action->date; $action->action = 'finished'; } /* Canceled By. */ elseif($history->new == 'cancel') { $task->canceledBy = $action->actor; $task->canceledDate = $action->date; $action->action = 'canceled'; } } /* Last edited by .*/ $task->lastEditedBy = $action->actor; $task->lastEditedDate = $action->date; /* Update action type. */ $this->dao->update(TABLE_ACTION)->set('action')->eq($action->action)->where('id')->eq($action->id)->exec(); $this->saveLogs($this->dao->get()); } } /* Update db. */ foreach($tasks as $task) { $this->dao->update(TABLE_TASK)->data($task)->where('id')->eq($task->id)->exec(); $this->saveLogs($this->dao->get()); } $this->dao->update(TABLE_TASK)->set('assignedTo=openedBy, assignedDate = finishedDate')->where('status')->eq('done')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_TASK)->set('assignedTo=openedBy, assignedDate = canceledDate')->where('status')->eq('cancel')->exec(); $this->saveLogs($this->dao->get()); /* Update action name. */ } /** * Update activated count of Bug. * * @access public * @return void */ public function updateActivatedCountOfBug() { $this->saveLogs('Run Method ' . __FUNCTION__); $bugActivatedActions = $this->dao->select('*')->from(TABLE_ACTION)->where('action')->eq('activated')->andWhere('objectType')->eq('bug')->fetchAll(); if(!empty($bugActivatedActions)) { foreach($bugActivatedActions as $action) { if(!isset($counts[$action->objectID])) $counts[$action->objectID] = 0; $counts[$action->objectID] ++; } foreach($counts as $key => $count) { $this->dao->update(TABLE_BUG)->set('activatedCount')->eq($count)->where('id')->eq($key)->exec(); $this->saveLogs($this->dao->get()); } } } /** * Update lastRun and lastResult field in zt_case * * @access public * @return void */ public function updateCases() { $this->saveLogs('Run Method ' . __FUNCTION__); $results = $this->dao->select('`case`, date, caseResult')->from($this->config->db->prefix . 'testResult')->orderBy('id desc')->fetchGroup('case'); foreach($results as $result) { $this->dao->update(TABLE_CASE) ->set('lastRun')->eq($result[0]->date) ->set('lastResult')->eq($result[0]->caseResult) ->where('id')->eq($result[0]->case) ->exec(); $this->saveLogs($this->dao->get()); } } /** * Update type of projects. * * @access public * @return void */ public function updateProjectType() { $this->saveLogs('Run Method ' . __FUNCTION__); $projects = $this->dao->select('root')->from(TABLE_MODULE)->where('type')->eq('task')->fetchPairs('root'); $this->dao->update(TABLE_PROJECT)->set('type')->eq('waterfall')->where('id')->in($projects)->exec(); $this->saveLogs($this->dao->get()); return true; } /** * Update estimate priv. * * @access public * @return void */ public function updateEstimatePriv() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'groupPriv'; $groups = $this->dao->select('*')->from($privTable) ->where('module')->eq('task') ->andWhere('method')->eq('edit') ->fetchAll(); foreach($groups as $group) { $this->dao->delete()->from($privTable) ->where('`group`')->eq($group->group) ->andWhere('module')->eq('task') ->andWhere('method')->eq('recordEstimate') ->exec(); $this->saveLogs($this->dao->get()); $this->dao->insert($privTable) ->set('company')->eq($group->company) ->set('`group`')->eq($group->group) ->set('module')->eq('task') ->set('method')->eq('recordEstimate') ->exec(); $this->saveLogs($this->dao->get()); $this->dao->delete()->from($privTable) ->where('`group`')->eq($group->group) ->andWhere('module')->eq('task') ->andWhere('method')->eq('editEstimate') ->exec(); $this->saveLogs($this->dao->get()); $this->dao->insert($privTable) ->set('company')->eq($group->company) ->set('`group`')->eq($group->group) ->set('module')->eq('task') ->set('method')->eq('editEstimate') ->exec(); $this->saveLogs($this->dao->get()); $this->dao->delete()->from($privTable) ->where('`group`')->eq($group->group) ->andWhere('module')->eq('task') ->andWhere('method')->eq('deleteEstimate') ->exec(); $this->saveLogs($this->dao->get()); $this->dao->insert($privTable) ->set('company')->eq($group->company) ->set('`group`')->eq($group->group) ->set('module')->eq('task') ->set('method')->eq('deleteEstimate') ->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Update the data of action. * * @access public * @return void */ public function updateAction() { $this->saveLogs('Run Method ' . __FUNCTION__); /* Get projects and tasks from action table. */ $projects = $this->dao->select('id')->from(TABLE_PROJECT)->fetchPairs('id'); $tasks = $this->dao->select('id, project')->from(TABLE_TASK)->fetchPairs('id'); /* Get products of projects and tasks. */ $projectProducts = $this->dao->select('project,product')->from($this->config->db->prefix . 'projectProduct')->where('project')->in(array_keys($projects))->fetchGroup('project', 'product'); $taskProducts = $this->dao->select('t1.id, t2.product')->from(TABLE_TASK)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->where('t1.id')->in(array_keys($tasks)) ->fetchPairs('id'); /* Process project actions. */ foreach($projects as $projectID) { $productList = isset($projectProducts[$projectID]) ? join(',', array_keys($projectProducts[$projectID])) : ''; $this->dao->update(TABLE_ACTION)->set('product')->eq($productList)->where('objectType')->eq('project')->andWhere('objectID')->eq($projectID)->exec(); $this->saveLogs($this->dao->get()); } /* Process task actions. */ foreach($tasks as $taskID => $projectID) { $productList = ''; if($taskProducts[$taskID]) { $productList = $taskProducts[$taskID]; } else { $productList = isset($projectProducts[$projectID]) ? join(',', array_keys($projectProducts[$projectID])) : ''; } $this->dao->update(TABLE_ACTION)->set('product')->eq($productList)->where('objectType')->eq('task')->andWhere('objectID')->eq($taskID)->andWhere('project')->eq($projectID)->exec(); $this->saveLogs($this->dao->get()); } $this->dao->update(TABLE_ACTION)->set("product = concat(',',product,',')")->exec(); $this->saveLogs($this->dao->get()); return true; } /** * Init the data of product and project order field. * * @access public * @return void */ public function setOrderData() { $this->saveLogs('Run Method ' . __FUNCTION__); $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->orderBy('code')->fetchAll('id'); foreach(array_keys($products) as $key => $productID) { $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq(($key + 1) * 10)->where('id')->eq($productID)->exec(); $this->saveLogs($this->dao->get()); } $projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('iscat')->eq(0)->andWhere('deleted')->eq(0)->orderBy('status, id desc')->fetchAll('id'); foreach(array_keys($projects) as $key => $projectID) { $this->dao->update(TABLE_PROJECT)->set('`order`')->eq(($key + 1) * 10)->where('id')->eq($projectID)->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Update task assignedTo. * * @access public * @return void */ public function updateTaskAssignedTo() { $this->saveLogs('Run Method ' . __FUNCTION__); $this->dao->update(TABLE_TASK)->set('assignedTo')->eq('closed') ->where('status')->eq('closed') ->andWhere('assignedTo')->eq('') ->exec(); $this->saveLogs($this->dao->get()); return true; } /** * Delete the patch record. * * @access public * @return void */ public function deletePatch() { $this->dao->delete()->from(TABLE_EXTENSION)->where('type')->eq('patch')->exec(); $this->dao->delete()->from(TABLE_EXTENSION)->where('code')->in('zentaopatch,patch')->exec(); } /** * Get the upgrade sql file. * * @param string $version * @access public * @return string */ public function getUpgradeFile($version) { return $this->app->getAppRoot() . 'db' . DS . 'update' . $version . '.sql'; } /** * Execute a sql. * * @param string $sqlFile * @access public * @return void */ public function execSQL($sqlFile) { if(!file_exists($sqlFile)) return false; $this->saveLogs('Run Method ' . __FUNCTION__); $mysqlVersion = $this->loadModel('install')->getMysqlVersion(); $ignoreCode = '|1050|1060|1091|1061|'; /* Read the sql file to lines, remove the comment lines, then join theme by ';'. */ $sqls = explode("\n", file_get_contents($sqlFile)); foreach($sqls as $key => $line) { $line = trim($line); $sqls[$key] = $line; /* Skip sql that is note. */ if(preg_match('/^--|^#|^\/\*/', $line) or empty($line)) unset($sqls[$key]); } $sqls = explode(';', join("\n", $sqls)); foreach($sqls as $sql) { if(empty($sql)) continue; if($mysqlVersion <= 4.1) { $sql = str_replace('DEFAULT CHARSET=utf8', '', $sql); $sql = str_replace('CHARACTER SET utf8 COLLATE utf8_general_ci', '', $sql); } $sql = str_replace('zt_', $this->config->db->prefix, $sql); try { $this->saveLogs($sql); $this->dbh->exec($sql); } catch(PDOException $e) { $this->saveLogs($e->getMessage()); $errorInfo = $e->errorInfo; $errorCode = $errorInfo[1]; if(strpos($ignoreCode, "|$errorCode|") === false) self::$errors[] = $e->getMessage() . "
The sql is: $sql
"; } } } /** * Add priv for version 4.0.1 * * @access public * @return void */ public function addPriv4_0_1() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'groupPriv'; $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('company') ->andWhere('method')->eq('edit') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('company')->eq($item->company) ->set('module')->eq('company') ->set('method')->eq('view') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('todo') ->andWhere('method')->eq('finish') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('company')->eq($item->company) ->set('module')->eq('todo') ->set('method')->eq('batchFinish') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Add priv for version 4.1 * * @access public * @return bool */ public function addPriv4_1() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'groupPriv'; $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('tree') ->andWhere('method')->eq('browse') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('company')->eq($item->company) ->set('module')->eq('tree') ->set('method')->eq('browseTask') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Add priv for version 8.1 * * @access public * @return bool */ public function addPriv8_1() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'grouppriv'; $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('bug') ->andWhere('method')->eq('edit') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('module')->eq('bug') ->set('method')->eq('linkBugs') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); $this->dao->replace($privTable) ->set('module')->eq('bug') ->set('method')->eq('unlinkBug') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('story') ->andWhere('method')->eq('edit') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('module')->eq('story') ->set('method')->eq('linkStory') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); $this->dao->replace($privTable) ->set('module')->eq('story') ->set('method')->eq('unlinkStory') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } $oldPriv = $this->dao->select('*')->from($privTable) ->where('module')->eq('testcase') ->andWhere('method')->eq('edit') ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable) ->set('module')->eq('testcase') ->set('method')->eq('linkCases') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); $this->dao->replace($privTable) ->set('module')->eq('testcase') ->set('method')->eq('unlinkCase') ->set('`group`')->eq($item->group) ->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Add priv for 8.2. * * @access public * @return bool */ public function addPriv8_2_beta() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'grouppriv'; /* Change product-all priv. */ $groups = $this->dao->select('`group`')->from($privTable)->where('`module`')->eq('product')->andWhere('`method`')->eq('index')->fetchPairs('group', 'group'); foreach($groups as $group) { $this->dao->replace($privTable)->set('module')->eq('product')->set('method')->eq('all')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); } /* Change project-all priv. */ $groups = $this->dao->select('`group`')->from($privTable)->where('`module`')->eq('project')->andWhere('`method`')->eq('index')->fetchPairs('group', 'group'); foreach($groups as $group) { $this->dao->replace($privTable)->set('module')->eq('project')->set('method')->eq('all')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); } /* Add kanban and tree priv. */ $groups = $this->dao->select('`group`')->from($privTable)->where('`module`')->eq('project')->andWhere('`method`')->eq('task')->fetchPairs('group', 'group'); foreach($groups as $group) { $this->dao->replace($privTable)->set('module')->eq('project')->set('method')->eq('kanban')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); $this->dao->replace($privTable)->set('module')->eq('project')->set('method')->eq('tree')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); } /* Change manageContacts priv. */ $groups = $this->dao->select('`group`')->from($privTable)->where('`module`')->eq('user')->andWhere('`method`')->eq('manageContacts')->fetchPairs('group', 'group'); foreach($groups as $group) { $this->dao->replace($privTable)->set('module')->eq('my')->set('method')->eq('manageContacts')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); } /* Change deleteContacts priv. */ $groups = $this->dao->select('`group`')->from($privTable)->where('`module`')->eq('user')->andWhere('`method`')->eq('deleteContacts')->fetchPairs('group', 'group'); foreach($groups as $group) { $this->dao->replace($privTable)->set('module')->eq('my')->set('method')->eq('deleteContacts')->set('`group`')->eq($group)->exec(); $this->saveLogs($this->dao->get()); } /* Change batchChangeModule priv. */ $oldPriv = $this->dao->select('*')->from($privTable) ->where("(`module`='story' and `method`='edit')") ->orWhere("(`module`='task' and `method`='edit')") ->orWhere("(`module`='bug' and `method`='edit')") ->orWhere("(`module`='testcase' and `method`='edit')") ->fetchAll(); foreach($oldPriv as $item) { $this->dao->replace($privTable)->set('module')->eq($item->module)->set('method')->eq('batchChangeModule')->set('`group`')->eq($item->group)->exec(); $this->saveLogs($this->dao->get()); } return true; } /** * Adjust config section and key. * * @access public * @return bool */ public function adjustConfigSectionAndKey() { $this->saveLogs('Run Method ' . __FUNCTION__); $this->dao->update(TABLE_CONFIG)->set('`key`')->eq('productProject')->where('`key`')->eq('productproject')->andWhere('module')->eq('custom')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_CONFIG)->set('section')->eq('bugBrowse')->where('section')->eq('bugbrowse')->andWhere('module')->eq('datatable')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_CONFIG)->set('section')->eq('productBrowse')->where('section')->eq('productbrowse')->andWhere('module')->eq('datatable')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_CONFIG)->set('section')->eq('projectTask')->where('section')->eq('projecttask')->andWhere('module')->eq('datatable')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_CONFIG)->set('section')->eq('testcaseBrowse')->where('section')->eq('testcasebrowse')->andWhere('module')->eq('datatable')->exec(); $this->saveLogs($this->dao->get()); $this->dao->update(TABLE_CONFIG)->set('section')->eq('testtaskCases')->where('section')->eq('testtaskcases')->andWhere('module')->eq('datatable')->exec(); $this->saveLogs($this->dao->get()); return true; } /** * To lower table. * * @param string $build * @access public * @return bool */ public function toLowerTable($build = 'basic') { $this->saveLogs('Run Method ' . __FUNCTION__); $results = $this->dao->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($build == 'pro') $tables2Rename = $this->config->upgrade->lowerProTables; if(!isset($tables2Rename)) return false; $tablesExists = $this->dao->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->dao->query("DROP TABLE `$upgradebak`"); $this->saveLogs($this->dao->get()); } if(isset($tablesExists[$newTable])) { $this->dao->query("RENAME TABLE `$newTable` TO `$upgradebak`"); $this->saveLogs($this->dao->get()); } $tempTable = $oldTable . '_zentaotmp'; $this->dao->query("RENAME TABLE `$oldTable` TO `$tempTable`"); $this->saveLogs($this->dao->get()); $this->dao->query("RENAME TABLE `$tempTable` TO `$newTable`"); $this->saveLogs($this->dao->get()); } return true; } /** * Process finishedBy and finishedDate of task. * * @access public * @return bool */ public function processTaskFinish() { $this->saveLogs('Run Method ' . __FUNCTION__); $this->dao->update(TABLE_TASK) ->set('finishedBy = lastEditedBy') ->set('finishedDate = lastEditedDate') ->where('status')->in('done,closed') ->andWhere('finishedBy')->eq('') ->exec(); $this->saveLogs($this->dao->get()); return true; } /** * Delete company field for the table of zt_config and zt_groupPriv. * * @access public * @return void */ public function deleteCompany() { $this->saveLogs('Run Method ' . __FUNCTION__); $privTable = $this->config->db->prefix . 'groupPriv'; /* Delete priv that is not in this company. Prevent conflict when delete company's field.*/ $this->dao->delete()->from($privTable)->where('company')->ne($this->app->company->id)->exec(); $this->saveLogs($this->dao->get()); $this->dao->exec("ALTER TABLE " . $privTable . " DROP `company`;"); $this->saveLogs($this->dao->get()); /* Delete config that don't conform to the rules. Prevent conflict when delete company's field.*/ $rows = $this->dao->select('*')->from(TABLE_CONFIG)->orderBy('id desc')->fetchAll('id'); $items = array(); $delList = array(); foreach($rows as $config) { if(isset($items[$config->owner][$config->module][$config->section][$config->key])) { $delList[] = $config->id; continue; } $items[$config->owner][$config->module][$config->section][$config->key] = $config->id; } if($delList) $this->dao->delete()->from(TABLE_CONFIG)->where('id')->in($delList)->exec(); $this->dao->exec("ALTER TABLE " . TABLE_CONFIG . " DROP `company`;"); $this->saveLogs($this->dao->get()); return true; } /** * Merge the goal and desc of project. * * @access public * @return void */ public function mergeProjectGoalAndDesc() { $this->saveLogs('Run Method ' . __FUNCTION__); $projects = $this->dao->select('*')->from(TABLE_PROJECT)->fetchAll('id'); foreach($projects as $id => $project) { if(!isset($project->goal)) continue; $this->dao->update(TABLE_PROJECT) ->set('`desc`')->eq($project->desc . '