Fix for Fix for fix non-sequential cck deltas

  1. <?php  
  2.   // Basically rewrite this to get an ordered list of nid, vid, delta from the content type or field that is insufficient.
  3.   $deltas = db_query("SELECT cfgi.nid, cfgi.vid, cfgi.delta FROM content_field_gallery_item cfgi INNER JOIN node n ON cfgi.vid = n.vid WHERE AND cfgi.nid NOT IN (SELECT nid FROM og_ancestry WHERE group_nid IN (1020, 1552, 964)) ORDER BY cfgi.vid, cfgi.delta");
  4.  
  5.   $nid = 0;
  6.   $delta = 0;
  7.   $items = array();
  8.   while ($row = db_fetch_object($deltas)) {
  9.     // Same nid, increment delta and update.
  10.     if ($row->nid == $nid) {
  11.       $delta += 1;
  12.       if ($delta != $row->delta) {
  13.         // Only update if they are different.
  14.         db_query("UPDATE content_field_gallery_item SET delta = %d WHERE vid = %d AND delta = %d", $delta, $row->vid, $row->delta);
  15.         // This is so we have some reporting.
  16.         $items[] = $row->nid .'|'. $row->delta;
  17.       }
  18.       else {
  19.         /**
  20.          * I meant here.
  21.          */
  22.       }
  23.     }
  24.     else {
  25.       // New nid, set delta to 0.
  26.       if ($row->delta != 0) {
  27.         // Only update if they are different.
  28.         db_query("UPDATE content_field_gallery_item SET delta = %d WHERE vid = %d AND delta = %d", 0, $row->vid, $row->delta);
  29.         // This is so we have some reporting.
  30.         $items[] = $row->nid .'|'. $row->delta;
  31.       }
  32.       $delta = 0;
  33.       $nid = $row->nid;
  34.     }  
  35.   }
  36.   // show the rows that were updated.
  37.   return theme('item_list', $items);
  38. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.