PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/uiorder-fix.php

http://webgloo.googlecode.com/
PHP | 123 lines | 74 code | 33 blank | 16 comment | 10 complexity | 30ec915bcd23a41b9ff4c6b58823246d MD5 | raw file
  1. <?php
  2. require_once ('gloo.inc' );
  3. require_once ($_SERVER['GLOO_INC_DIR'] . 'class_loader.inc' );
  4. require_once ($_SERVER['GLOO_INC_DIR'] . 'error.inc' );
  5. // script to fix old ui_order
  6. function run_main() {
  7. $organizations = getOrganizations();
  8. foreach($organizations as $organization) {
  9. printf("trying org = %d \n", $organization['id']);
  10. rearrangeOrg($organization['id']);
  11. sleep(2);
  12. }
  13. }
  14. function rearrangeOrg($orgId) {
  15. $pages = getPages($orgId);
  16. //get all blocks for this page from gloo_block_data
  17. foreach($pages as $page) {
  18. rearrangePage($orgId,$page['ident_key']);
  19. }
  20. }
  21. function rearrangePage($orgId, $pageKey) {
  22. printf("Try Page = %s \n", $pageKey);
  23. $blocks = getBlocks($orgId, $pageKey);
  24. foreach($blocks as $block) {
  25. rearrangeBlock($orgId, $pageKey, $block['block_no']);
  26. }
  27. }
  28. function rearrangeBlock($orgId, $pageKey,$blockNo) {
  29. //printf("Try Org = %d, Page = %s, Block = %d \n", $orgId,$pageKey,$blockNo);
  30. //find max_ui_order
  31. $mysqli = Gloo_DB::getInstance()->getConnection();
  32. $sql = "select id, ui_order from gloo_block_data where org_id = ".$orgId ;
  33. $sql .= " and page_key ='".$pageKey."' and block_no = ".$blockNo;
  34. $sql .= " order by ui_order " ;
  35. $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
  36. //find max ui_order now
  37. $slot = sizeof($rows);
  38. /*
  39. foreach($rows as $row) {
  40. if($row['ui_order'] > $slot ) {
  41. $slot = $row['ui_order'] ;
  42. }
  43. }*/
  44. $end = $slot ;
  45. if($slot > 1) {
  46. printf("Rearrange Org = %d, Page = %s, Block = %d \n", $orgId,$pageKey,$blockNo);
  47. //do swap now
  48. for($pos = 1 ; $pos <= $end ; $pos++ ) {
  49. //position is 1-offset while
  50. swapUIOrder($orgId, $pageKey,$blockNo,$rows[$pos-1]['id'], $pos,$slot);
  51. $slot-- ;
  52. }
  53. }
  54. }
  55. function swapUIOrder($orgId, $pageKey, $blockNo, $widgetId,$oldPos,$newPos) {
  56. if($oldPos == $newPos ) return ;
  57. if($widgetId == 0 || $widgetId == '0')
  58. trigger_error("wrong - empty widgetId !");
  59. if(empty($oldPos))
  60. trigger_error("wrong - empty old position!");
  61. if(empty($newPos))
  62. trigger_error("wrong - empty new position !");
  63. printf("widget = %d, old pos = %d, new pos = %d \n",$widgetId,$oldPos,$newPos);
  64. $mysqli = Gloo_DB::getInstance()->getConnection();
  65. $sql = " update gloo_block_data set ui_order = ".$newPos. " where id = ".$widgetId ;
  66. Gloo_MySQL_Helper::executeSQL($mysqli, $sql);
  67. }
  68. function getOrganizations() {
  69. $mysqli = Gloo_DB::getInstance()->getConnection();
  70. $sql =" select id from gloo_org where id >= 1241 and id <= 1250" ;
  71. $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
  72. return $rows ;
  73. }
  74. function getPages($orgId) {
  75. $mysqli = Gloo_DB::getInstance()->getConnection();
  76. $sql =" select ident_key from gloo_page where org_id = ".$orgId ;
  77. $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
  78. return $rows ;
  79. }
  80. function getBlocks($orgId,$pageKey) {
  81. $mysqli = Gloo_DB::getInstance()->getConnection();
  82. $sql =" select distinct block_no from gloo_block_data where org_id = ".$orgId." and page_key = '".$pageKey. "' " ;
  83. $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
  84. return $rows ;
  85. }
  86. //rearrangeOrg(1200);
  87. //rearrangePage(1207,'home');
  88. //rearrangeBlock(1207, 'home', 100);
  89. run_main();
  90. ?>