[geeklog-cvs] geeklog-1.3/sql/updates mysql_1.3.9_to_1.3.10.php,1.4,1.5

vinny at iowaoutdoors.org vinny at iowaoutdoors.org
Fri May 21 15:35:02 EDT 2004


Update of /var/cvs/geeklog-1.3/sql/updates
In directory www:/tmp/cvs-serv5672

Modified Files:
	mysql_1.3.9_to_1.3.10.php 
Log Message:
Fater update of new comment columsn 'lft', 'rht', and 'indent' using
improvements to the upgrade script provided by Niels Leenheer.


Index: mysql_1.3.9_to_1.3.10.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/sql/updates/mysql_1.3.9_to_1.3.10.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** mysql_1.3.9_to_1.3.10.php	20 May 2004 18:32:14 -0000	1.4
--- mysql_1.3.9_to_1.3.10.php	21 May 2004 19:34:58 -0000	1.5
***************
*** 1,28 ****
  <?php
  
! function commentsToPreorderTreeHelper($commentid, $left, $indent)
  {
      global $_TABLES;
      $right = $left + 1;
      
!     //get all children of the comment
!     $q = "SELECT cid FROM {$_TABLES['comments']} WHERE pid = $commentid";
!     $result = DB_query($q);
!     
!     //foreach child run the recursive function
!     while ( $A = DB_fetchArray($result) )
      {
!         //DEBUG: print("calling recurisive({$A['cid']}, $right)\n");
!         $right = commentsToPreorderTreeHelper($A['cid'], $right, $indent + 1);
!         $right++;   
      }
      
      //Update the comment, set lft = $left and rht = return value + 1
      $q = "UPDATE {$_TABLES['comments']} SET lft = $left, rht = $right, "
!        . "indent = $indent WHERE cid = $commentid";
      DB_query($q);
-     //DEBUG: print "$q\n";
      
!     //return rht
      return $right;
  }
--- 1,30 ----
  <?php
  
! function commentsToPreorderTreeHelper(&$tP, $left, $indent = 0)
  {
      global $_TABLES;
+ 
+     // start with the right terminal value = left terminal value + 1
      $right = $left + 1;
      
!     //foreach child (if any) run the recursive function
!     if ( isset( $tP['children'] ))
      {
! 	    while( list( $k, $A ) = each( $tP['children'] ) )
!     	{
!         	//DEBUG: print("calling recurisive($k, $right)\n");
!         	$right = commentsToPreorderTreeHelper($A, $right, $indent + 1);
!         	$right++;   
!     	}
      }
      
      //Update the comment, set lft = $left and rht = return value + 1
      $q = "UPDATE {$_TABLES['comments']} SET lft = $left, rht = $right, "
!        . "indent = $indent WHERE cid = " . $tP['cid'];
      DB_query($q);
      
!     //DEBUG: print $q."<br>";
!     
!     //return right
      return $right;
  }
***************
*** 32,61 ****
      global $_TABLES;
      
!     //Get all the unique sid's from the database
      $q = "SELECT sid FROM {$_TABLES['comments']} group by sid";
      $result = DB_query($q);
  
!     //Foreach sid, get all the top level comments
!     // begin with $left = 1
      while ( $A = DB_fetchArray($result) )
      {
!         // initialize left terminal value
!         $left = 1;
          
!         // get top level comments
!         $q = "SELECT cid FROM {$_TABLES['comments']} "
!            . "WHERE sid = '{$A['sid']}' AND pid = 0";
!         $res2 = DB_query($q); 
          
!         //Foreach toplevel comment run the recursive funtion
!         while ( $B = DB_fetchArray($res2) ) 
          {
!             //DEBUG: print("calling recurisive({$B['cid']}, $left)\n");
!             $left = commentsToPreorderTreeHelper($B['cid'], $left, 0);
              $left++;   
          }
          
!         //Print results to error log
!         $left = ($left-1)/2;
      }
  }
--- 34,89 ----
      global $_TABLES;
      
!     // Get all the unique sid's from the database
      $q = "SELECT sid FROM {$_TABLES['comments']} group by sid";
      $result = DB_query($q);
  
!     // Loop through every sid supplementing comments with new rows
!     //   'lft', 'rht', and 'indent'
      while ( $A = DB_fetchArray($result) )
      {
!         // build a tree
!     	$aP = array();
!     	$tP = array();
!     	
!         // grab comments associated with the current 'sid'
!         $qC = "SELECT cid,pid FROM {$_TABLES['comments']} "
!            	. "WHERE sid = '{$A['sid']}' ORDER BY cid ASC";
!         $rC = DB_query( $qC ); 
          
!         // put the comments in a usefull array
!         while ( $dC = DB_fetchArray( $rC ) )
!         {
!         	if ( $dC['pid'] == 0 )
!         	{
!         		// Root comment
!         		$tP[$dC['cid']] = $dC;
!         		$aP[$dC['cid']] =& $tP[$dC['cid']];
!         	}
!         	else
!         	{
!         		// Child comment
!         		$aP[$dC['pid']]['children'][$dC['cid']] = $dC;
!        			$aP[$dC['cid']] =& $aP[$dC['pid']]['children'][$dC['cid']];	
!        		}
!         }
          
!         unset ($aP);
!         
!         // initialize left terminal value, this starts with 1 for every
!         //   set of comments associated with a 'sid'
!         $left = 1;
!         
!         // Foreach toplevel comment run the recursive funtion
!         while( list( $k, $B ) = each( $tP ) )
          {
!         	//DEBUG: print("calling recurisive({$B['cid']}, $left)\n");
!             $left = commentsToPreorderTreeHelper($B, $left);
              $left++;   
          }
          
!         /* Print results to error log for DEBUGing
!          * $left = ($left-1)/2;
!          * COM_errorLog("$left comments in story {$A['sid']} converted");
!          */
      }
  }




More information about the geeklog-cvs mailing list