/[libdata]/trunk/admin/include/scribe_fix.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/admin/include/scribe_fix.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 71 by dpavlin, Thu Mar 4 22:43:50 2004 UTC revision 72 by dpavlin, Thu Mar 18 20:33:37 2004 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /**********************************************************  /**********************************************************
3  Function Library: scribe_fix.php  Function Library: scribe_fix.php
4  Original Author: Paul Bramscher <brams006@tc.umn.edu>  Original Author: Paul Bramscher <brams006@umn.edu>
5  Last Modified: 10.29.2003  Last Modified: 03.16.2004
6  ***********************************************************  ***********************************************************
7  Comments:  Comments:
8  This library brings together CourseLib/PageScribe page  This library brings together CourseLib/PageScribe page
9  debugging and fixing algorithms.  debugging and fixing algorithms.
10  ***********************************************************  ***********************************************************
11    Table of Contents:
12  errorTrap  errorTrap
13  genCalc  genCalc
14  isOrphan  isOrphan
# Line 22  updateOrphans Line 23  updateOrphans
23  /**********************************************************  /**********************************************************
24  Function: errorTrap  Function: errorTrap
25  Author: Paul Bramscher  Author: Paul Bramscher
26  Last Modified: 10.28.2003  Last Modified: 03.04.2004
27  ***********************************************************  ***********************************************************
28  Purpose:  Purpose:
29  Debugger available for CLPS system, to check for various  Debugger available for CLPS system, to check for various
# Line 31  is equal to 1, then this function is use Line 32  is equal to 1, then this function is use
32  scribe.phtml automatically.  Otherwise, it's called  scribe.phtml automatically.  Otherwise, it's called
33  manually from the DBA console.  manually from the DBA console.
34  **********************************************************/  **********************************************************/
35  function errorTrap($con, $page_id){  function errorTrap($page_id){
36    
37          // Fetch title          // Fetch title
38          $page_title = lookupField($con, "page", "page_id", $page_id, "page_title");          $page_title = lookupField("page", "page_id", $page_id, "page_title");
39    
40          // Overall status          // Overall status
41          $passed = 1;          $passed = 1;
42    
43          printf("<center>\n");          printf("<center>\n");
44          printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n");          printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n");
45          printf("<tr><td class=\"cellPlain\">Debug Data: %s (#%d)</td></tr>\n", $page_title, $page_id);          printf("<tr><td class=\"cellPlain\">Debug Data: %s (ID# %d)</td></tr>\n", $page_title, $page_id);
46          printf("<tr><td><br>\n");          printf("<tr><td><br>\n");
47    
48          /***********************          /***********************
49          ** Basic Element Data **          ** Basic Element Data **
50          ***********************/          ***********************/
51                    
52          printf("<b>Element Data:</b><br>");          printf("<b>Element Data:</b><br>\n");
53    
54          // Distinct orders          // Distinct orders
55          $sql = "SELECT DISTINCT element_order FROM element WHERE page_id ="          $sql = "SELECT DISTINCT element_order FROM element WHERE page_id ="
56                  . $page_id;                  . $page_id;
57          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
58          $num_orders = xx_num_rows($rs);          $num_orders = xx_num_rows($rs);
59          printf("Unique orders: %d<br>\n", $num_orders);          printf("Unique orders: %d<br>\n", $num_orders);
60                    
61          // Number of rows (should be the same)          // Number of rows (should be the same)
62          $sql = "SELECT element_id FROM element WHERE page_id = "          $sql = "SELECT element_id FROM element WHERE page_id = "
63                  . $page_id;                  . $page_id;
64          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
65          $num_rows = xx_num_rows($rs);          $num_rows = xx_num_rows($rs);
66          printf("Number of rows: %d<BR>\n", $num_rows);          printf("Number of rows: %d<BR>\n", $num_rows);
67                    
68          // Smallest order (if rows present, should be 1)          // Smallest order (if rows present, should be 1)
69          $sql = "SELECT MIN(element_order) as min_order FROM element WHERE page_id = "          $sql = "SELECT MIN(element_order) as min_order FROM element WHERE page_id = "
70                  . $page_id;                  . $page_id;
71          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
72          $row = xx_fetch_array ($rs);          $row = xx_fetch_array ($rs, xx_ASSOC);
73          $min_order = $row["min_order"];          $min_order = $row["min_order"];
74          printf("First order: %d<br>\n", $min_order);          printf("First order: %d<br>\n", $min_order);
75                    
76          // Largest order (should equal distinct rows and number of rows          // Largest order (should equal distinct rows and number of rows
77          $sql = "SELECT MAX(element_order) as max_order FROM element WHERE page_id = "          $sql = "SELECT MAX(element_order) as max_order FROM element WHERE page_id = "
78                  . $page_id;                  . $page_id;
79          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
80          $row = xx_fetch_array ($rs);          $row = xx_fetch_array ($rs, xx_ASSOC);
81          $max_order = $row["max_order"];          $max_order = $row["max_order"];
82          printf("Last order: %d<br><br>\n", $max_order);          printf("Last order: %d<br><br>\n", $max_order);
83                    
# Line 88  function errorTrap($con, $page_id){ Line 89  function errorTrap($con, $page_id){
89          $c1_sql = "SELECT element_id, parent_id, element_order, indent_level FROM element WHERE page_id = "          $c1_sql = "SELECT element_id, parent_id, element_order, indent_level FROM element WHERE page_id = "
90                  . $page_id                  . $page_id
91                  . " AND parent_id > 0 ORDER BY element_order";                  . " AND parent_id > 0 ORDER BY element_order";
92          $c1_rs = xx_query($c1_sql, $con);          $c1_rs = xx_tryquery($c1_sql);
93                                    
94          while ($c1_row = xx_fetch_array ($c1_rs)) {          while ($c1_row = xx_fetch_array ($c1_rs, xx_ASSOC)) {
95                  $parent_id = $c1_row["parent_id"];                  $parent_id = $c1_row["parent_id"];
96                  $indent_level = $c1_row["indent_level"];                  $indent_level = $c1_row["indent_level"];
97                  $element_id = $c1_row["element_id"];                  $element_id = $c1_row["element_id"];
# Line 99  function errorTrap($con, $page_id){ Line 100  function errorTrap($con, $page_id){
100                  // For each row returned, hunt for the parent                  // For each row returned, hunt for the parent
101                  $c2_sql ="SELECT element_id, element_order, indent_level FROM element WHERE element_id = "                  $c2_sql ="SELECT element_id, element_order, indent_level FROM element WHERE element_id = "
102                           . $parent_id;                           . $parent_id;
103                  $c2_rs = xx_query($c2_sql, $con);                  $c2_rs = xx_tryquery($c2_sql);
104                  $c2_row = xx_fetch_array ($c2_rs);                  $c2_row = xx_fetch_array ($c2_rs, xx_ASSOC);
105                  $c2_indent_level = $c2_row["indent_level"];                  $c2_indent_level = $c2_row["indent_level"];
106                  $c2_element_id = $c2_row["element_id"];                  $c2_element_id = $c2_row["element_id"];
107                  $c2_element_order = $c2_row["element_order"];                  $c2_element_order = $c2_row["element_order"];
# Line 172  function errorTrap($con, $page_id){ Line 173  function errorTrap($con, $page_id){
173                  . $page_id                  . $page_id
174                  . " ORDER BY element_order";                  . " ORDER BY element_order";
175    
176          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
177    
178          while ($row = xx_fetch_array ($rs)) {          while ($row = xx_fetch_array ($rs, xx_ASSOC)) {
179                  $element_id = $row["element_id"];                  $element_id = $row["element_id"];
180                  $indent_level = $row["indent_level"];                            $indent_level = $row["indent_level"];          
181                  $parent_id = $row["parent_id"];                          $parent_id = $row["parent_id"];        
182                  $gen_level = 0;                  $gen_level = 0;
183    
184                  // Call the generational calculator for each element                  // Call the generational calculator for each element
185                  $gen_level = genCalc($con, $element_id, $gen_level, $page_id, $parent_id);                  $gen_level = genCalc($element_id, $gen_level, $page_id, $parent_id);
186    
187                  if ($gen_level != $indent_level) {                  if ($gen_level != $indent_level) {
188                          printf("Failed.  Element ID#%d reported generation of %d, but calculated at %d.<BR>\n", $element_id, $indent_level, $gen_level);                          printf("Failed.  Element ID#%d reported generation of %d, but calculated at %d.<BR>\n", $element_id, $indent_level, $gen_level);
# Line 214  function errorTrap($con, $page_id){ Line 215  function errorTrap($con, $page_id){
215  /**********************************************************  /**********************************************************
216  Function: genCalc  Function: genCalc
217  Author: Paul Bramscher  Author: Paul Bramscher
218  Last Modified: 10.27.2003  Last Modified: 03.04.2004
219  ***********************************************************  ***********************************************************
220  Purpose:  Purpose:
221  Recursively calculate the traversable generational level of  Recursively calculate the traversable generational level of
# Line 223  indent level, then there's an error.  Th Line 224  indent level, then there's an error.  Th
224  will update the indent_level value in the elements table  will update the indent_level value in the elements table
225  with the calculated value determined here.  with the calculated value determined here.
226  **********************************************************/  **********************************************************/
227  function genCalc($con, $element_id, $gen_level, $page_id, $parent_id) {  function genCalc($element_id, $gen_level, $page_id, $parent_id) {
228    
229          // If there is a parent to probe          // If there is a parent to probe
230          if ($parent_id > 0) {          if ($parent_id > 0) {
# Line 236  function genCalc($con, $element_id, $gen Line 237  function genCalc($con, $element_id, $gen
237                          . " AND page_id = "                          . " AND page_id = "
238                          . $page_id;                          . $page_id;
239                                                    
240                  $rs = xx_query($sql, $con);                  $rs = xx_tryquery($sql);
241                  $row = xx_fetch_array ($rs);                  $row = xx_fetch_array ($rs, xx_ASSOC);
242                  $probe_parent_id = $row["parent_id"];                  $probe_parent_id = $row["parent_id"];
243                  $probe_element_id = $row["parent_id"];                            $probe_element_id = $row["parent_id"];          
244                                    
245                  // See if the probed element has any parents to probe further                  // See if the probed element has any parents to probe further
246                  if ($probe_element_id > 0) {                  if ($probe_element_id > 0) {
247                          return 1 + genCalc($con, $probe_element_id, $gen_level, $page_id, $probe_parent_id);                          return 1 + genCalc($probe_element_id, $gen_level, $page_id, $probe_parent_id);
248                    
249                  }                  }
250                                    
# Line 260  function genCalc($con, $element_id, $gen Line 261  function genCalc($con, $element_id, $gen
261  /**********************************************************  /**********************************************************
262  Function: isOrphan  Function: isOrphan
263  Author: Paul Bramscher  Author: Paul Bramscher
264  Last Modified: 08.27.2003  Last Modified: 03.04.2004
265  ***********************************************************  ***********************************************************
266  Purpose:  Purpose:
267  Determines if the supplied PageScribe/CourseLib element is  Determines if the supplied PageScribe/CourseLib element is
# Line 270  an orphaned type element.  To be a valid Line 271  an orphaned type element.  To be a valid
271  fails, the element is said to be orphaned, a bastard or  fails, the element is said to be orphaned, a bastard or
272  otherwise of problematic ancestry.  otherwise of problematic ancestry.
273  **********************************************************/  **********************************************************/
274  function isOrphan($con, $element_id, $element_order, $page_id, $parent_id) {  function isOrphan($element_id, $element_order, $page_id, $parent_id) {
275    
276          //Initialize          //Initialize
277          $orphan = 0;          $orphan = 0;
# Line 290  function isOrphan($con, $element_id, $el Line 291  function isOrphan($con, $element_id, $el
291                  // testing                  // testing
292                  // printf("orphan probe sql was: %s ", $sql);                  // printf("orphan probe sql was: %s ", $sql);
293    
294                  $rs = xx_query($sql, $con);                  $rs = xx_tryquery($sql);
295                  $row = xx_fetch_array ($rs);                  $row = xx_fetch_array ($rs, xx_ASSOC);
296                  $par_found = $row["par_found"];                  $par_found = $row["par_found"];
297    
298                  // Should have only one match.  If none (or multiple) set to 0.                  // Should have only one match.  If none (or multiple) set to 0.
# Line 299  function isOrphan($con, $element_id, $el Line 300  function isOrphan($con, $element_id, $el
300                  else $orphan = 1;                  else $orphan = 1;
301    
302                  // Output                  // Output
303                  if ($orphan == 1) printf("Found orphan: ID#%d.<br>", $element_id);                  if ($orphan == 1) printf("Found orphan: ID#%d.<br>\n", $element_id);
304                                    
305          }          }
306                    
# Line 310  function isOrphan($con, $element_id, $el Line 311  function isOrphan($con, $element_id, $el
311  /**********************************************************  /**********************************************************
312  Function: purgeOrphans  Function: purgeOrphans
313  Author: Paul Bramscher  Author: Paul Bramscher
314  Last Modified: 10.28.2003  Last Modified: 03.04.2004
315  ***********************************************************  ***********************************************************
316  Purpose:  Purpose:
317  Purges and orphans found on the page.  Purges and orphans found on the page.
318  **********************************************************/  **********************************************************/
319    function purgeOrphans($page_id) {
 function purgeOrphans($con, $page_id) {  
320    
321          printf("<b>Method #2 Delete fostered children and their descendants</b><br><br>\n");          printf("<b>Method #2 Delete fostered children and their descendants</b><br><br>\n");
322          printf("<b>Messages:</b><br>\n");          printf("<b>Messages:</b><br>\n");
# Line 331  function purgeOrphans($con, $page_id) { Line 331  function purgeOrphans($con, $page_id) {
331                  . $page_id                  . $page_id
332                  . " ORDER BY element_order";                  . " ORDER BY element_order";
333    
334          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
335    
336          while ($row = xx_fetch_array ($rs)) {          while ($row = xx_fetch_array ($rs, xx_ASSOC)) {
337                  $element_id = $row["element_id"];                  $element_id = $row["element_id"];
338                  $element_order = $row["element_order"];                  $element_order = $row["element_order"];
339                  $parent_id = $row["parent_id"];                          $parent_id = $row["parent_id"];        
# Line 341  function purgeOrphans($con, $page_id) { Line 341  function purgeOrphans($con, $page_id) {
341                  /* If an orphan, delete it and its first generation.                  /* If an orphan, delete it and its first generation.
342                  Recall some Egyptian/Biblical curse here.*/                  Recall some Egyptian/Biblical curse here.*/
343    
344                  if ($parent_id > 0 && isOrphan($con, $element_id, $element_order, $page_id, $parent_id)) {                  if ($parent_id > 0 && isOrphan($element_id, $element_order, $page_id, $parent_id)) {
345    
346                          $sub_sql = "DELETE FROM element                          $sub_sql = "DELETE FROM element
347                                  WHERE page_id = "                                  WHERE page_id = "
# Line 350  function purgeOrphans($con, $page_id) { Line 350  function purgeOrphans($con, $page_id) {
350                                  . $element_id                                  . $element_id
351                                  . " AND parent_id = "                                  . " AND parent_id = "
352                                  . $parent_id;                                  . $parent_id;
353                            if (xx_tryquery ($sub_sql)) printf("Element %d was an orphan.  Deleted it.<br>\n", $element_id);                        
                         // printf("delete sql wasd: %s<BR>", $sql);  
   
                         if (!xx_query ($sub_sql, $con)){  
                                 sql_err($sub_sql);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         }  
                         else {  
                   
                                 // Output  
                                 printf("Element %d was an orphan.  Deleted it.<br>\n", $element_id);  
                           
                                 xx_query ("UNLOCK TABLES", $con);  
                         } // deleted this element                                
354    
355                  } // delete all elements which are orphaned                  } // delete all elements which are orphaned
356    
# Line 376  function purgeOrphans($con, $page_id) { Line 362  function purgeOrphans($con, $page_id) {
362  /**********************************************************  /**********************************************************
363  Function: purgeRelationships  Function: purgeRelationships
364  Author: Paul Bramscher  Author: Paul Bramscher
365  Last Modified: 10.28.2003  Last Modified: 03.04.2004
366  ***********************************************************  ***********************************************************
367  Purpose:  Purpose:
368  Purges all parent-child relationships on the page, and  Purges all parent-child relationships on the page, and
# Line 384  reduces all elements to root-level eleme Line 370  reduces all elements to root-level eleme
370  destructive, but virtually guaranteed to fix a page.  destructive, but virtually guaranteed to fix a page.
371  **********************************************************/  **********************************************************/
372    
373  function purgeRelationships($con, $page_id) {  function purgeRelationships($page_id) {
374    
375          printf("<b>Method #3 Purge all parent-child relationships!</b><br><br>\n");          printf("<b>Method #3 Purge all parent-child relationships!</b><br><br>\n");
376          printf("<b>Messages:</b><br>\n");          printf("<b>Messages:</b><br>\n");
# Line 393  function purgeRelationships($con, $page_ Line 379  function purgeRelationships($con, $page_
379                  SET parent_id = 0, indent_level = 0                  SET parent_id = 0, indent_level = 0
380                  WHERE page_id = "                  WHERE page_id = "
381                  . $page_id;                  . $page_id;
382            if (xx_tryquery ($sql)) printf("Purged all!<br>\n");
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
         else {  
           
                 printf("Purged all!<br>\n");  
                 xx_query ("UNLOCK TABLES", $con);  
         } // purged all!  
   
383    
384  } // end purgeRelationships  } // end purgeRelationships
385    
# Line 428  Required steps, automatically followed a Line 403  Required steps, automatically followed a
403  (b) Fill in any "holes" in the element order.  (b) Fill in any "holes" in the element order.
404  (c) Clean up all indent levels.  (c) Clean up all indent levels.
405  **********************************************************/  **********************************************************/
406  function scribeFix($con, $method, $page_id){  function scribeFix($method, $page_id){
407    
408          printf("<center>\n");          printf("<center>\n");
409          printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n");          printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n");
410          printf("<tr><td class=\"cellPlain\">Page Fix Dialog (#%d)</td></tr>\n", $page_id);          printf("<tr><td class=\"cellPlain\">Page Fix Dialog (ID# %d)</td></tr>\n", $page_id);
411          printf("<tr><td><br>\n");          printf("<tr><td><br>\n");
412    
413          switch ($method) {          switch ($method) {
414                    
415                  // Update orphans                  // Update orphans
416                  case 1: updateOrphans($con, $page_id);                  case 1: updateOrphans($page_id);
417                          break;                          break;
418                                                    
419                  // Purge orphans                  // Purge orphans
420                  case 2: purgeOrphans($con, $page_id);                  case 2: purgeOrphans($page_id);
421                          break;                          break;
422                                                    
423                  // Purge all parent-child relationships                  // Purge all parent-child relationships
424                  case 3: purgeRelationships($con, $page_id);                  case 3: purgeRelationships($page_id);
425                          break;                          break;
426                    
427                  default:                  default:
# Line 455  function scribeFix($con, $method, $page_ Line 430  function scribeFix($con, $method, $page_
430          }          }
431    
432          // Required cleanup, regardless of fix methodology          // Required cleanup, regardless of fix methodology
433          updateOrders($con, $page_id);          updateOrders($page_id);
434          updateGenerations($con, $page_id);          updateGenerations($page_id);
435    
436          printf("<br>Done.  Re-run the debugger against this page to determine success: <a href=\"scribe_debug.phtml?page_id=%d\">Debug Page ID#%d</a><br><br>", $page_id, $page_id);          printf("<br>Done.  Re-run the debugger against this page to determine success: <a href=\"scribe_debug.phtml?page_id=%d\">Debug Page ID#%d</a><br><br>", $page_id, $page_id);
437          printf("</td></tr></table></center>\n");          printf("</td></tr></table></center>\n");
# Line 468  function scribeFix($con, $method, $page_ Line 443  function scribeFix($con, $method, $page_
443  /**********************************************************  /**********************************************************
444  Function: updateGenerations  Function: updateGenerations
445  Author: Paul Bramscher  Author: Paul Bramscher
446  Last Modified: 10.28.2003  Last Modified: 03.04.2004
447  ***********************************************************  ***********************************************************
448  Purpose:  Purpose:
449  Walks through a page and compares calculated generation with  Walks through a page and compares calculated generation with
450  reported indent level.  When a discrepancy is found, fix it  reported indent level.  When a discrepancy is found, fix it
451  according to the calculated generation.  according to the calculated generation.
452  **********************************************************/  **********************************************************/
453  function updateGenerations($con, $page_id) {  function updateGenerations($page_id) {
454    
455          printf("<br><b>Analyzing generational structure:</b><br>\n");          printf("<br><b>Analyzing generational structure:</b><br>\n");
456                    
# Line 494  function updateGenerations($con, $page_i Line 469  function updateGenerations($con, $page_i
469                  . $page_id                  . $page_id
470                  . " ORDER BY element_order";                  . " ORDER BY element_order";
471    
472          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
473    
474          while ($row = xx_fetch_array ($rs)) {          while ($row = xx_fetch_array ($rs, xx_ASSOC)) {
475                  $element_id = $row["element_id"];                  $element_id = $row["element_id"];
476                  $indent_level = $row["indent_level"];                  $indent_level = $row["indent_level"];
477                  $parent_id = $row["parent_id"];                  $parent_id = $row["parent_id"];
# Line 505  function updateGenerations($con, $page_i Line 480  function updateGenerations($con, $page_i
480                  $gen_level = 0;                  $gen_level = 0;
481    
482                  // Call the generational calculator for each element                  // Call the generational calculator for each element
483                  $gen_level = genCalc($con, $element_id, $gen_level, $page_id, $parent_id);                  $gen_level = genCalc($element_id, $gen_level, $page_id, $parent_id);
484    
485                  // A discrepancy was founnd                  // A discrepancy was founnd
486                  if ($gen_level != $indent_level) {                  if ($gen_level != $indent_level) {
# Line 521  function updateGenerations($con, $page_i Line 496  function updateGenerations($con, $page_i
496                                  . $page_id                                  . $page_id
497                                  . " AND element_id = "                                  . " AND element_id = "
498                                  . $element_id;                                  . $element_id;
499                            if (xx_tryquery ($sub_sql)) printf("Element #%d reported generation of %d, but calculated at %d.  Fixed.<br>\n", $element_id, $indent_level, $gen_level);
                         if (!xx_query ($sub_sql, $con)){  
                                 sql_err($sub_sql);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         }  
                         else {  
                                 // Output  
                                 printf("Element #%d reported generation of %d, but calculated at %d.  Fixed.<br>\n", $element_id, $indent_level, $gen_level);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                   
                         } // fixed this element's indent  
500    
501                  } // if there is a discrepancy with calculated generation level                  } // if there is a discrepancy with calculated generation level
502    
# Line 546  function updateGenerations($con, $page_i Line 510  function updateGenerations($con, $page_i
510  /**********************************************************  /**********************************************************
511  Function: updateOrders  Function: updateOrders
512  Author: Paul Bramscher  Author: Paul Bramscher
513  Last Modified: 10.28.2003  Last Modified: 03.04.2004
514  ***********************************************************  ***********************************************************
515  Purpose:  Purpose:
516  Walks through a page and compares calculated order with  Walks through a page and compares calculated order with
517  reported order.  When a discrepancy is found, fix it  reported order.  When a discrepancy is found, fix it
518  according to the calculated order.  according to the calculated order.
519  **********************************************************/  **********************************************************/
520  function updateOrders($con, $page_id) {  function updateOrders($page_id) {
521    
522          printf("<br><b>Analyzing cardinal orders:</b><br>\n");          printf("<br><b>Analyzing cardinal orders:</b><br>\n");
523                    
# Line 571  function updateOrders($con, $page_id) { Line 535  function updateOrders($con, $page_id) {
535                  . $page_id                  . $page_id
536                  . " ORDER BY element_order";                  . " ORDER BY element_order";
537    
538          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
539    
540          while ($row = xx_fetch_array ($rs)) {          while ($row = xx_fetch_array ($rs, xx_ASSOC)) {
541                  $element_id = $row["element_id"];                  $element_id = $row["element_id"];
542                  $element_order = $row["element_order"];                  $element_order = $row["element_order"];
543    
# Line 594  function updateOrders($con, $page_id) { Line 558  function updateOrders($con, $page_id) {
558                                  . $page_id                                  . $page_id
559                                  . " AND element_id = "                                  . " AND element_id = "
560                                  . $element_id;                                  . $element_id;
561                            if (xx_tryquery ($sub_sql)) printf("Row #%d reported cardinal order of %d, but calculated at %d.  Fixed.<br>\n", $element_count, $element_order, $element_count);
                         if (!xx_query ($sub_sql, $con)){  
                                 sql_err($sub_sql);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         }  
                         else {  
                           
                                 // Output  
                                 printf("Row #%d reported cardinal order of %d, but calculated at %d.  Fixed.<br>\n", $element_count, $element_order, $element_count);                    
                                 xx_query ("UNLOCK TABLES", $con);  
                         } // fixed this element's order  
562    
563                  } // if an order discrepancy was found                  } // if an order discrepancy was found
564    
# Line 620  function updateOrders($con, $page_id) { Line 573  function updateOrders($con, $page_id) {
573  /**********************************************************  /**********************************************************
574  Function: updateOrphans  Function: updateOrphans
575  Author: Paul Bramscher  Author: Paul Bramscher
576  Last Modified: 10.28.2003  Last Modified: 03.04.2004
577  ***********************************************************  ***********************************************************
578  Purpose:  Purpose:
579  Walks through a page and hunts for orphaned/bastard  Walks through a page and hunts for orphaned/bastard
580  children.  Hunts for most likely parent and attaches the  children.  Hunts for most likely parent and attaches the
581  child to it.  child to it.
582  **********************************************************/  **********************************************************/
583  function updateOrphans($con, $page_id) {  function updateOrphans($page_id) {
584    
585          // Initialize          // Initialize
586          $passed_orphan = 1;          $passed_orphan = 1;
# Line 645  function updateOrphans($con, $page_id) { Line 598  function updateOrphans($con, $page_id) {
598                  . $page_id                  . $page_id
599                  . " ORDER BY element_order";                  . " ORDER BY element_order";
600    
601          $rs = xx_query($sql, $con);          $rs = xx_tryquery($sql);
602    
603          while ($row = xx_fetch_array ($rs)) {          while ($row = xx_fetch_array ($rs, xx_ASSOC)) {
604                  $element_id = $row["element_id"];                  $element_id = $row["element_id"];
605                  $element_order = $row["element_order"];                  $element_order = $row["element_order"];
606                  $parent_id = $row["parent_id"];                  $parent_id = $row["parent_id"];
607                  $indent_level = $row["indent_level"];                  $indent_level = $row["indent_level"];
608    
609                  $new_parent_id = parentProbe($con, $page_id, $element_order, $indent_level);                  $new_parent_id = parentProbe($page_id, $element_order, $indent_level);
610                  $orphaned = 0;                  $orphaned = 0;
611                  $orphaned = isOrphan($con, $element_id, $element_order, $page_id, $parent_id);                  $orphaned = isOrphan($element_id, $element_order, $page_id, $parent_id);
612    
613                  // Hunt for most likely parent, and assign to it instead.                  // Hunt for most likely parent, and assign to it instead.
614                  if ($parent_id > 0 && $orphaned == 1) {                  if ($parent_id > 0 && $orphaned == 1) {
# Line 670  function updateOrphans($con, $page_id) { Line 623  function updateOrphans($con, $page_id) {
623                                  . $page_id                                  . $page_id
624                                  . " AND element_id = "                                  . " AND element_id = "
625                                  . $element_id;                                  . $element_id;
626                            if (xx_tryquery ($sub_sql)) printf("Element #%d orphaned.  Reassigned to parent #%d<br>\n", $element_id, $new_parent_id);
                         if (!xx_query ($sub_sql, $con)){  
                                 sql_err($sub_sql);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         }  
                         else {  
   
                                 // Output  
                                 printf("Element #%d orphaned.  Reassigned to parent #%d<br>\n", $element_id, $new_parent_id);  
   
                                 xx_query ("UNLOCK TABLES", $con);  
                         } // reassigned this element  
627    
628                  } // reassign problematic elements                  } // reassign problematic elements
629    
# Line 691  function updateOrphans($con, $page_id) { Line 632  function updateOrphans($con, $page_id) {
632          if ($passed_orphan == 1) printf("No orphans found.<br>\n");          if ($passed_orphan == 1) printf("No orphans found.<br>\n");
633    
634  } // end updateOrphans  } // end updateOrphans
635  ?>  ?>

Legend:
Removed from v.71  
changed lines
  Added in v.72

  ViewVC Help
Powered by ViewVC 1.1.26