You are here

function image_attach_update_2 in Image 5.2

Same name and namespace in other branches
  1. 5 contrib/image_attach/image_attach.install \image_attach_update_2()
  2. 6 contrib/image_attach/image_attach.install \image_attach_update_2()

Remove attach records that point to a missing image.

File

contrib/image_attach/image_attach.install, line 62

Code

function image_attach_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("DELETE FROM {image_attach} USING {image_attach} LEFT JOIN {node} n ON {image_attach}.iid = n.nid WHERE n.nid IS NULL OR n.type != 'image'");
      break;
    case 'pgsql':
      $ret[] = update_sql("DELETE FROM {image_attach} USING {node} n WHERE {image_attach}.iid = n.nid AND (n.nid IS NULL OR n.type != 'image')");
      break;
  }
  return $ret;
}