VBO PHP удаление доступа по домену у ноды, если доступа нет у термина

$field_teplo_tax = get__und($entity, 'field_teplo_tax', 'tid');
$field_teplo_tax_term = taxonomy_term_load($field_teplo_tax);
$is_object__field_teplo_tax_term = is_object ($field_teplo_tax_term);


$tid = (int) $field_teplo_tax; // WARNING :)

$result = db_query("SELECT gid, realm FROM {domain_taxonomy_access} WHERE tid = :tid AND (realm = 'domain_id' OR realm = 'domain_site')",
  array(':tid' => $tid));
 
foreach ($result as $data) {
// Transform the 0 to -1, since {domain_access} is unsigned.
($data->gid == 0) ? $gid = -1 : $gid = $data->gid;
  $term_domains[] = $gid;
  
}
  
$domain_id = (int) domain_get_domain()['domain_id'];

$domain_ids[] = '1';
$domain_ids[] = '2';

foreach ($domain_ids as $domain_id){
    
    if(in_array($domain_id, $term_domains)){
        
        tele_n("Да. На домене $domain_id. $entity->nid");
    } else {
    
        unset($entity->domains[$domain_id]);
        tele_n("Нет. На домене $domain_id. $entity->nid");
    }
}

if(empty($entity->domains)){
    $entity->domains[3] = '3';
}

// pr($entity);
node_save ($entity);