PageRenderTime 63ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/install/migration/migrate_17/migrate_17_to_18_functions.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 292 lines | 206 code | 42 blank | 44 comment | 18 complexity | ab97ae44b1e170635a3b69179acf4731 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. * This script is distributed under the GNU General Public License 2 or later.
  5. *
  6. * Support functions for migration from 1.7.2 to 1.8.0
  7. *
  8. * @package TestLink
  9. * @author franciscom
  10. * @copyright 2008, TestLink community
  11. * @version CVS: $Id: migrate_17_to_18_functions.php,v 1.10 2009/08/30 00:56:06 havlat Exp $
  12. *
  13. * @internal
  14. * rev: 20090127 - franciscom - added checkTableFields()
  15. * 20081210 - BUGID 1921 - missing update of attachment table
  16. * added updateExecutionsTCVersionInfo()
  17. */
  18. function reqSpecMigration(&$source_db,&$treeMgr)
  19. {
  20. $mapping_old_new = null;
  21. $hhmmss=date("H:i:s");
  22. $msg_click_to_show="click to show";
  23. echo "<a onclick=\"return DetailController.toggle('details-req_spec_table')\" href=\"tplan/\">
  24. <img src='../../img/icon-foldout.gif' align='top' title='show/hide'> Requirement Specification: {$msg_click_to_show} {$hhmmss}</a>";
  25. echo '<div class="detail-container" id="details-req_spec_table" style="display: none;">';
  26. $sql="SELECT * from req_specs";
  27. $rspec=$source_db->fetchRowsIntoMap($sql,'id');
  28. if(is_null($rspec))
  29. {
  30. echo "<span class='notok'>There are no req specs to be migrated!</span></b>";
  31. }
  32. else
  33. {
  34. $mapping_old_new->req_spec=migrateReqSpecs($source_db,$treeMgr,$rspec);
  35. }
  36. echo "</div><p>";
  37. return $mapping_old_new;
  38. }
  39. /*
  40. function: migrateReqSpecs
  41. args:
  42. returns:
  43. */
  44. function migrateReqSpecs(&$source_db,&$treeMgr,&$rspec)
  45. {
  46. $oldNewMapping=array();
  47. $mappingDescrID=$treeMgr->get_available_node_types();
  48. $counter=0;
  49. $rspec_qty=count($rspec);
  50. echo "<pre>Number of Requirements Specifications (SRS): " . $rspec_qty; echo "</pre>";
  51. foreach($rspec as $req_id => $rdata)
  52. {
  53. $nodeID=$treeMgr->new_node($rdata['testproject_id'],
  54. $mappingDescrID['requirement_spec'],$rdata['title']);
  55. $oldNewMapping[$req_id]=$nodeID;
  56. }
  57. return $oldNewMapping;
  58. }
  59. function requirementsMigration(&$source_db,&$treeMgr,&$oldNewMapping)
  60. {
  61. $msg_click_to_show="click to show";
  62. $hhmmss=date("H:i:s");
  63. echo "<a onclick=\"return DetailController.toggle('details-reqtable')\" href=\"tplan/\">
  64. <img src='../../img/icon-foldout.gif' align='top' title='show/hide'> Requirements: {$msg_click_to_show} {$hhmmss}</a>";
  65. echo '<div class="detail-container" id="details-reqtable" style="display: none;">';
  66. $sql="SELECT * from requirements";
  67. $req=$source_db->fetchRowsIntoMap($sql,'id');
  68. if(is_null($req))
  69. {
  70. echo "<span class='notok'>There are no requirements to be migrated!</span></b>";
  71. }
  72. else
  73. {
  74. $oldNewMapping=migrateRequirements($source_db,$treeMgr,$req,$oldNewMapping);
  75. }
  76. echo "</div><p>";
  77. return $oldNewMapping;
  78. }
  79. function migrateRequirements(&$source_db,&$treeMgr,&$req,&$oldNewMapping)
  80. {
  81. $mappingDescrID=$treeMgr->get_available_node_types();
  82. $req_qty=count($req);
  83. echo "<pre>Number of requirements: " . $req_qty; echo "</pre>";
  84. foreach($req as $req_id => $rdata)
  85. {
  86. $parentID=$oldNewMapping->req_spec[$rdata['srs_id']];
  87. $nodeID=$treeMgr->new_node($parentID,
  88. $mappingDescrID['requirement'],
  89. $rdata['title'],$rdata['node_order']);
  90. $oldNewMapping->req[$req_id]=$nodeID;
  91. }
  92. return $oldNewMapping;
  93. }
  94. function updateReqInfo(&$source_db,&$treeMgr,&$oldNewMapping)
  95. {
  96. $sql="SELECT id,srs_id FROM requirements ";
  97. $requirements=$source_db->fetchRowsIntoMap($sql,'id');
  98. // Update ID in descending order to avoid wrong replacement
  99. // because we can not be certain that new generated ID will
  100. // be crash with old IDs.
  101. //
  102. // krsort
  103. krsort($oldNewMapping->req_spec);
  104. krsort($oldNewMapping->req);
  105. foreach($oldNewMapping->req_spec as $oldID => $newID)
  106. {
  107. $sql="UPDATE req_specs " .
  108. "SET id={$newID} WHERE id={$oldID}";
  109. $source_db->exec_query($sql);
  110. }
  111. foreach($oldNewMapping->req as $oldID => $newID)
  112. {
  113. $parentID=$oldNewMapping->req_spec[$requirements[$oldID]['srs_id']];
  114. $sql="UPDATE requirements " .
  115. " SET id={$newID}, srs_id={$parentID} " .
  116. " WHERE id={$oldID}";
  117. $source_db->exec_query($sql);
  118. $sql="UPDATE req_coverage " .
  119. " SET req_id={$newID} " .
  120. " WHERE req_id={$oldID}";
  121. $source_db->exec_query($sql);
  122. // BUGID - Missing update of attachments
  123. $sql="UPDATE attachments " .
  124. "SET fk_id={$newID} ".
  125. " WHERE fk_id={$oldID} AND fk_table='requirements'";
  126. $source_db->exec_query($sql);
  127. }
  128. }
  129. function updateTProjectInfo(&$source_db,&$tprojectMgr)
  130. {
  131. $all_tprojects=$tprojectMgr->get_all();
  132. if( !is_null($all_tprojects) )
  133. {
  134. initNewTProjectProperties($source_db,$all_tprojects,$tprojectMgr);
  135. updateTestCaseExternalID($source_db,$all_tprojects,$tprojectMgr);
  136. }
  137. }
  138. function initNewTProjectProperties(&$db,&$tprojectMap,&$tprojectMgr)
  139. {
  140. if( !is_null($tprojectMap) )
  141. {
  142. // test case prefix
  143. foreach($tprojectMap as $key => $value)
  144. {
  145. $tcPrefix=trim(substr($value['name'],0,5) . " (ID={$value['id']})");
  146. $sql="UPDATE testprojects " .
  147. "SET prefix='" . $db->prepare_string($tcPrefix) ."', " .
  148. " tc_counter=0 " .
  149. "WHERE id={$value['id']}";
  150. $db->exec_query($sql);
  151. }
  152. }
  153. }
  154. function updateTestCaseExternalID(&$db,&$all_tprojects,&$tprojectMgr)
  155. {
  156. $show_memory=true;
  157. if( !is_null($all_tprojects) )
  158. {
  159. $numtproject=count($all_tprojects);
  160. echo "Total number of Test Projects to process: {$numtproject}<br>";
  161. ob_flush();flush();
  162. $feedback_counter=0;
  163. $tproject_counter=0;
  164. foreach($all_tprojects as $tproject_key => $tproject_value)
  165. {
  166. $feedback_counter=0;
  167. $tproject_counter++;
  168. $tcaseSet = array();
  169. $tprojectMgr->get_all_testcases_id($tproject_value['id'],$tcaseSet);
  170. echo "Working on Test Project ({$tproject_counter}/{$numtproject}) : {$tproject_value['name']}<br>";
  171. if( function_exists('memory_get_usage') && function_exists('memory_get_peak_usage') && $show_memory)
  172. {
  173. echo "(Memory Usage: ".memory_get_usage() . " | Peak: " . memory_get_peak_usage() . ")<br><br>";
  174. }
  175. ob_flush();flush();
  176. if( !is_null($tcaseSet) && ($numtc=count($tcaseSet)) > 0 )
  177. {
  178. $do_feedback=$numtc > 100;
  179. echo "Test Cases to process: {$numtc}<br><br>";
  180. ob_flush();flush();
  181. foreach($tcaseSet as $tckey => $tcvalue)
  182. {
  183. $feedback_counter++;
  184. $eid=$tckey+1;
  185. $sql="UPDATE tcversions " .
  186. "SET tc_external_id={$eid} " .
  187. "WHERE id IN (SELECT id FROM nodes_hierarchy WHERE parent_id={$tcvalue})";
  188. $db->exec_query($sql);
  189. if( $do_feedback && $feedback_counter%100 == 0)
  190. {
  191. echo "Test Cases Processed: {$feedback_counter} - " . date("H:i:s") . "<br>";
  192. ob_flush();flush();
  193. }
  194. }
  195. echo "ALL Test Cases Processed: {$feedback_counter} - " . date("H:i:s") ."<br><br>";
  196. $sql="UPDATE testprojects " .
  197. "SET tc_counter={$eid} " .
  198. "WHERE id={$tproject_value['id']}";
  199. $db->exec_query($sql);
  200. }
  201. unset($tcaseSet);
  202. }
  203. }
  204. }
  205. function updateExecutionsTCVersionInfo(&$db)
  206. {
  207. if (!isset($cfg['db_type']) || strtolower($cfg['db_type']) == 'postgres')
  208. {
  209. // Bug #2325
  210. $sql = "UPDATE executions SET tcversion_number = " .
  211. "(SELECT version FROM tcversions WHERE id = executions.tcversion_id)";
  212. } else {
  213. $sql = "UPDATE executions E,tcversions TCV " .
  214. "SET tcversion_number=TCV.version " .
  215. "WHERE TCV.id = E.tcversion_id";
  216. }
  217. $db->exec_query($sql);
  218. }
  219. /*
  220. function: checkTableFields
  221. args: adoObj: reference to ado object
  222. table: table name
  223. fields2check: array with field names
  224. returns: array($status_ok,$msg)
  225. rev: 20090127 - franciscom
  226. */
  227. function checkTableFields(&$adoObj,$table,$fields2check)
  228. {
  229. $status_ok=true;
  230. $msg='';
  231. $fields=$adoObj->MetaColumns($table);
  232. foreach($fields2check as $field_name)
  233. {
  234. if( !isset($fields[strtoupper($field_name)]) )
  235. {
  236. $msg="Table {$table} - Missing field {$field_name}";
  237. $status_ok=false;
  238. break;
  239. }
  240. }
  241. return array($status_ok,$msg);
  242. }
  243. ?>