/tools/uiorder-fix.php
PHP | 123 lines | 74 code | 33 blank | 16 comment | 10 complexity | 30ec915bcd23a41b9ff4c6b58823246d MD5 | raw file
- <?php
- require_once ('gloo.inc' );
- require_once ($_SERVER['GLOO_INC_DIR'] . 'class_loader.inc' );
- require_once ($_SERVER['GLOO_INC_DIR'] . 'error.inc' );
- // script to fix old ui_order
- function run_main() {
- $organizations = getOrganizations();
- foreach($organizations as $organization) {
- printf("trying org = %d \n", $organization['id']);
- rearrangeOrg($organization['id']);
- sleep(2);
- }
-
- }
- function rearrangeOrg($orgId) {
- $pages = getPages($orgId);
- //get all blocks for this page from gloo_block_data
- foreach($pages as $page) {
- rearrangePage($orgId,$page['ident_key']);
-
- }
- }
- function rearrangePage($orgId, $pageKey) {
- printf("Try Page = %s \n", $pageKey);
- $blocks = getBlocks($orgId, $pageKey);
-
- foreach($blocks as $block) {
- rearrangeBlock($orgId, $pageKey, $block['block_no']);
- }
- }
- function rearrangeBlock($orgId, $pageKey,$blockNo) {
- //printf("Try Org = %d, Page = %s, Block = %d \n", $orgId,$pageKey,$blockNo);
- //find max_ui_order
- $mysqli = Gloo_DB::getInstance()->getConnection();
- $sql = "select id, ui_order from gloo_block_data where org_id = ".$orgId ;
- $sql .= " and page_key ='".$pageKey."' and block_no = ".$blockNo;
- $sql .= " order by ui_order " ;
-
- $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
-
- //find max ui_order now
- $slot = sizeof($rows);
-
- /*
- foreach($rows as $row) {
- if($row['ui_order'] > $slot ) {
- $slot = $row['ui_order'] ;
- }
- }*/
-
- $end = $slot ;
-
- if($slot > 1) {
- printf("Rearrange Org = %d, Page = %s, Block = %d \n", $orgId,$pageKey,$blockNo);
- //do swap now
- for($pos = 1 ; $pos <= $end ; $pos++ ) {
- //position is 1-offset while
- swapUIOrder($orgId, $pageKey,$blockNo,$rows[$pos-1]['id'], $pos,$slot);
- $slot-- ;
- }
- }
-
-
- }
- function swapUIOrder($orgId, $pageKey, $blockNo, $widgetId,$oldPos,$newPos) {
- if($oldPos == $newPos ) return ;
- if($widgetId == 0 || $widgetId == '0')
- trigger_error("wrong - empty widgetId !");
-
- if(empty($oldPos))
- trigger_error("wrong - empty old position!");
-
- if(empty($newPos))
- trigger_error("wrong - empty new position !");
-
-
-
- printf("widget = %d, old pos = %d, new pos = %d \n",$widgetId,$oldPos,$newPos);
-
- $mysqli = Gloo_DB::getInstance()->getConnection();
- $sql = " update gloo_block_data set ui_order = ".$newPos. " where id = ".$widgetId ;
- Gloo_MySQL_Helper::executeSQL($mysqli, $sql);
- }
- function getOrganizations() {
- $mysqli = Gloo_DB::getInstance()->getConnection();
- $sql =" select id from gloo_org where id >= 1241 and id <= 1250" ;
- $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
- return $rows ;
-
- }
- function getPages($orgId) {
- $mysqli = Gloo_DB::getInstance()->getConnection();
- $sql =" select ident_key from gloo_page where org_id = ".$orgId ;
- $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
- return $rows ;
- }
- function getBlocks($orgId,$pageKey) {
- $mysqli = Gloo_DB::getInstance()->getConnection();
- $sql =" select distinct block_no from gloo_block_data where org_id = ".$orgId." and page_key = '".$pageKey. "' " ;
- $rows = Gloo_MySQL_Helper::fetchRows($mysqli,$sql);
- return $rows ;
-
- }
- //rearrangeOrg(1200);
- //rearrangePage(1207,'home');
- //rearrangeBlock(1207, 'home', 100);
- run_main();
- ?>