Aggregator Feed Fixer

global $user;
if ($user->uid != 1) { drupal_access_denied(); exit(); }
?>

ERROR\n";
    echo "   ## $newurl is not installed. ##";
    if (! $feedname){
      echo "Horrible nasty error. Lost the name I was working on.\n";
      exit;
    }

    //mysql_query("UPDATE aggregator_feed SET url='$newurl' WHERE title='$feedname'");
    mysql_query("INSERT INTO aggregator_feed SET url='$newurl', title='$feedname', refresh='3600', block='5'");
    if (mysql_error()){
      echo " Oops, had a problem fixing this: ".mysql_error()."\n";
    } else {
      echo " FIXED!!\n";
    }
    continue;
  }

  if ($oldurl != $newurl){
    echo "ERROR\n";
    echo "   ## $oldurl should be $newurl ##";
    if (! $feedname){
      echo "Horrible nasty error. Lost the name I was working on.\n";
      exit;
    }
    mysql_query("UPDATE aggregator_feed SET url='$newurl' WHERE title='$feedname'");
    if (mysql_error()){
      echo " Oops, had a problem fixing this: ".mysql_error()."\n";
    } else {
      echo " FIXED!!\n";
    }
  } else {
    echo "OK\n";
  }
}

echo "\n== Checking for items to delete. ==\n";
$result = mysql_query("SELECT * FROM aggregator_feed");
while ($row = mysql_fetch_assoc($result)){
  $url = $row['url'];
  $res2 = mysql_query("SELECT value FROM profile_values WHERE value = '$url'");
  $numrows = mysql_num_rows($res2);
  if ($numrows < 1){
    echo "".$row['title']." was not found in a user profile.\n";
  }
}
echo "You may want to delete these entries manually if they appear to be user related.\n";
?>