bizext.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. class bizextUpgrade extends upgradeModel
  3. {
  4. /**
  5. * Record finished task effort.
  6. *
  7. * @access public
  8. * @return bool
  9. */
  10. public function recordFinished()
  11. {
  12. $this->saveLogs('Run Method ' . __FUNCTION__);
  13. $tasks = $this->dao->select('id,finishedBy,lastEditedBy,finishedDate,lastEditedDate')->from(TABLE_TASK)
  14. ->where('status')->in('done,closed')
  15. ->andWhere("(finishedDate='0000-00-00 00:00:00' or lastEditedDate='0000-00-00 00:00:00')")
  16. ->fetchAll('id');
  17. $efforts = $this->dao->select('t1.*,t2.date as actionDate')->from(TABLE_EFFORT)->alias('t1')
  18. ->leftJoin(TABLE_ACTION)->alias('t2')->on('t1.id=t2.objectID')
  19. ->where('t2.objectType')->eq('effort')
  20. ->andWhere('t1.left')->eq(0)
  21. ->andWhere('t1.objectType')->eq('task')
  22. ->andWhere('t1.objectID')->in(array_keys($tasks))
  23. ->orderBy('id')
  24. ->fetchAll('objectID');
  25. foreach($efforts as $taskID => $effort)
  26. {
  27. $data = array();
  28. if(empty($tasks[$taskID]->finishedBy)) $data['finishedBy'] = $effort->account;
  29. if(empty($tasks[$taskID]->lastEditedBy)) $data['lastEditedBy'] = $effort->account;
  30. if(helper::isZeroDate($tasks[$taskID]->finishedDate)) $data['finishedDate'] = $effort->actionDate;
  31. if(helper::isZeroDate($tasks[$taskID]->lastEditedDate)) $data['lastEditedDate'] = $effort->actionDate;
  32. if(!empty($data))
  33. {
  34. $this->dao->update(TABLE_TASK)->data($data)->where('id')->eq($taskID)->exec();
  35. $this->saveLogs($this->dao->get());
  36. }
  37. }
  38. return !dao::isError();
  39. }
  40. /**
  41. * Fix repo prefix.
  42. *
  43. * @access public
  44. * @return void
  45. */
  46. public function fixRepo()
  47. {
  48. $this->saveLogs('Run Method ' . __FUNCTION__);
  49. $this->app->loadConfig('repo');
  50. $repos = $this->dao->select('*')->from(TABLE_REPO)->fetchAll();
  51. foreach($repos as $repo)
  52. {
  53. if($repo->SCM == 'Subversion')
  54. {
  55. $scm = $this->app->loadClass('scm');
  56. $scm->setEngine($repo);
  57. $info = $scm->info('');
  58. $prefix = empty($info->root) ? '' : trim(str_ireplace($info->root, '', str_replace('\\', '/', $repo->path)), '/');
  59. if($prefix)
  60. {
  61. $prefix = '/' . $prefix;
  62. $this->dao->update(TABLE_REPO)->set('prefix')->eq($prefix)->where('id')->eq($repo->id)->exec();
  63. $this->saveLogs($this->dao->get());
  64. }
  65. }
  66. }
  67. }
  68. /**
  69. * Fix report for add unique key.
  70. *
  71. * @access public
  72. * @return bool
  73. */
  74. public function fixReport()
  75. {
  76. $this->saveLogs('Run Method ' . __FUNCTION__);
  77. $reports = $this->dao->select('`code`,count(`code`) as count')->from(TABLE_REPORT)->groupBy('`code`')->orderBy('id')->fetchAll();
  78. $backSql = '';
  79. foreach($reports as $report)
  80. {
  81. if($report->count == 1) continue;
  82. $row = $this->dao->select('*')->from(TABLE_REPORT)->where('`code`')->eq($report->code)->orderBy('id')->limit(1)->query()->fetch(PDO::FETCH_ASSOC);
  83. /* Create key sql for insert. */
  84. $keys = array_keys($row);
  85. $keys = array_map('addslashes', $keys);
  86. $keys = join('`,`', $keys);
  87. $keys = "`" . $keys . "`";
  88. /* Create a value sql. */
  89. $value = array_values($row);
  90. $value = array_map('addslashes', $value);
  91. $value = join("','", $value);
  92. $value = "'" . $value . "'";
  93. $backSql .= "REPLACE INTO " . TABLE_REPORT . "($keys) VALUES (" . $value . ");\n";
  94. $this->dao->delete()->from(TABLE_REPORT)->where('id')->eq($row['id'])->exec();
  95. $this->saveLogs($this->dao->get());
  96. }
  97. if(!empty($backSql)) file_put_contents($this->app->getCacheRoot() . 'reportback.sql', $backSql);
  98. $codeIndex = $this->dao->query("show index from " . TABLE_REPORT . " where `key_name`= 'code'")->fetch();
  99. if(empty($codeIndex))
  100. {
  101. $this->dao->exec("ALTER TABLE " . TABLE_REPORT . " ADD UNIQUE `code` (`code`)");
  102. $this->saveLogs($this->dao->get());
  103. }
  104. return true;
  105. }
  106. public function checkURAndSR()
  107. {
  108. $hasURAndSR = $this->loadModel('setting')->getItem('owner=system&module=common&section=global&key=URAndSR');
  109. if($hasURAndSR) return true;
  110. $ur = $this->dao->select('*')->from(TABLE_STORY)->where('type')->eq('requirement')->limit(1)->fetch();
  111. if($ur) $this->setting->setItem('system.common.global.URAndSR', 1);
  112. return true;
  113. }
  114. /**
  115. * Convert simplified Chinese to traditional Chinese in the report.
  116. *
  117. * @access public
  118. * @return bool
  119. */
  120. public function fixReportLang()
  121. {
  122. $reportList = $this->dao->select('id,`name`,`desc`')->from(TABLE_REPORT)->fetchAll();
  123. foreach($reportList as $report)
  124. {
  125. if(!empty($report->name))
  126. {
  127. $nameList = json_decode($report->name, true);
  128. $result = $this::simplifiedtoTraditional($nameList['zh-cn']);
  129. if($result)
  130. {
  131. $nameList['zh-tw'] = $result;
  132. $report->name = json_encode($nameList);
  133. }
  134. }
  135. if(!empty($report->desc))
  136. {
  137. $descList = json_decode($report->desc, true);
  138. $result = $this::simplifiedtoTraditional($descList['zh-cn']);
  139. if($result)
  140. {
  141. $descList['zh-tw'] = $result;
  142. $report->desc = json_encode($descList);
  143. }
  144. }
  145. }
  146. foreach($reportList as $report)
  147. {
  148. $this->dao->update(TABLE_REPORT)->set('name')->eq($report->name)->set('desc')->eq($report->desc)->where('id')->eq($report->id)->exec();
  149. }
  150. return true;
  151. }
  152. /**
  153. * Convert simplified characters to traditional characters.
  154. *
  155. * @access public
  156. * @return string
  157. */
  158. public static function simplifiedtoTraditional($input)
  159. {
  160. include('traditionalchinese.php');
  161. if(trim($input) == '') return '';
  162. $simplified = array_keys($traditionalChinese);
  163. $traditional = array_values($traditionalChinese);
  164. $output = str_replace($simplified, $traditional, $input);
  165. return $output;
  166. }
  167. }