You are here

function metatag_metatags_delete_multiple in Metatag 7

Delete multiple entities' tags.

Parameters

string $entity_type: The entity type.

array $entity_ids: The list of IDs.

array $revision_ids: An optional list of revision IDs; if omitted all revisions will be deleted.

string $langcode: The language ID of the entities to delete. If left blank, all language entries for the enities will be deleted.

Return value

bool If any problems were encountered will return FALSE, otherwise TRUE.

1 call to metatag_metatags_delete_multiple()
metatag_metatags_delete in ./metatag.module
Delete an entity's tags.

File

./metatag.module, line 865
Primary hook implementations for Metatag.

Code

function metatag_metatags_delete_multiple($entity_type, array $entity_ids, array $revision_ids = array(), $langcode = NULL) {

  // Double check entity IDs and revision IDs are numeric.
  $entity_ids = array_filter($entity_ids, 'is_numeric');
  $revision_ids = array_filter($revision_ids, 'is_numeric');
  if (!empty($entity_ids) || !empty($revision_ids)) {
    $transaction = db_transaction();
    try {

      // Let other modules know about the records being deleted using
      // hook_metatag_metatags_delete().
      module_invoke_all('metatag_metatags_delete', $entity_type, $entity_ids, $revision_ids, $langcode);

      // Set the entity to delete.
      $query = db_delete('metatag')
        ->condition('entity_type', $entity_type);

      // If revision IDs were specified then just use those in the query.
      if (!empty($revision_ids)) {
        $query
          ->condition('revision_id', $revision_ids, 'IN');
      }
      else {
        $query
          ->condition('entity_id', $entity_ids, 'IN');
      }

      // Limit to a language if one was specified.
      if (!empty($langcode)) {
        $query
          ->condition('language', $langcode);
      }

      // Perform the deletion(s).
      $query
        ->execute();

      // Clear cached data.
      metatag_metatags_cache_clear($entity_type, $entity_ids);

      // Clear the caches for these entities.
      entity_get_controller($entity_type)
        ->resetCache($entity_ids);
      return TRUE;
    } catch (Exception $e) {
      $transaction
        ->rollback();
      watchdog_exception('metatag', $e);
      throw $e;
    }
  }
  else {
    watchdog('metatag', 'No entity IDs or revision IDs were submitted to metatag_metatags_delete_multiple().');
  }
  return FALSE;
}