You are here

function radioactivity_arbitrary_target_cron in Radioactivity 5

File

plugins/radioactivity_arbitrary_target.module, line 39

Code

function radioactivity_arbitrary_target_cron() {

  // clean up radioactivity_arbitrary_target
  $result = db_query("SELECT at.rad_id\n                FROM {radioactivity_arbitrary_target} at\n                     LEFT JOIN {radioactivity} r ON (at.rad_id = r.id)\n               WHERE r.id IS NULL");
  $rad_ids = array();
  $count = 0;
  while ($rad_id = db_result($result)) {
    $rad_ids[] = $rad_id;
    $count++;
    if ($count == 500) {
      break;
    }

    // clean up at most 500 ids per cron run
  }
  if (count($rad_ids)) {
    db_query("DELETE FROM {radioactivity_arbitrary_target} WHERE rad_id IN (" . implode(',', $rad_ids) . ')');
  }
}