Fix for fix non-sequential cck deltas

  1.   // Basically rewrite this to get an ordered list of nid, vid, delta from the content type or field that is insufficient.
  2.   $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");
  3.  
  4.   $nid = 0;
  5.   $delta = 0;
  6.   $items = array();
  7.   while ($row = db_fetch_object($deltas)) {
  8.     // Same nid, increment delta and update.
  9.     if ($row->nid == $nid) {
  10.       $delta += 1;
  11.       if ($delta != $row->delta) {
  12.         // Only update if they are different.
  13.         db_query("UPDATE content_field_gallery_item SET delta = %d WHERE vid = %d AND delta = %d", $delta, $row->vid, $row->delta);
  14.         // This is so we have some reporting.
  15.         $items[] = $row->nid .'|'. $row->delta;
  16.       }
  17.     }
  18.     else {
  19.       // New nid, set delta to 0.
  20.       if ($row->delta != 0) {
  21.         // Only update if they are different.
  22.         db_query("UPDATE content_field_gallery_item SET delta = %d WHERE vid = %d AND delta = %d", 0, $row->vid, $row->delta);
  23.         // This is so we have some reporting.
  24.         $items[] = $row->nid .'|'. $row->delta;
  25.       }
  26.       $delta = 0;
  27.       $nid = $row->nid;
  28.     }  
  29.   }
  30.   // show the rows that were updated.
  31.   return theme('item_list', $items);

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.