You are here

private function flag_flag::flagging_delete in Flag 7.3

Unflag an entity by deleting a Flagging.

Parameters

$flagging: The flagging entity that is to be removed.

$entity_id: The entity ID of entity being unflagged.

$account: The account performing the unflagging.

1 call to flag_flag::flagging_delete()
flag_flag::flag in includes/flag/flag_flag.inc
Flags, or unflags, an item.

File

includes/flag/flag_flag.inc, line 896
Contains the flag_flag class. Flag type classes use an object oriented style inspired by that of Views 2.

Class

flag_flag
This abstract class represents a flag, or, in Views 2 terminology, "a handler".

Code

private function flagging_delete($flagging, $entity_id, $account) {
  if ($this
    ->uses_anonymous_cookies()) {
    $this
      ->_unflag_anonymous($entity_id);
  }
  $transaction = db_transaction();
  try {

    // Note the order: We decrease the count first so hooks have accurate
    // data, then invoke hooks, then delete the flagging entity.
    $this
      ->_decrease_count($entity_id);
    module_invoke_all('flag_unflag', $this, $entity_id, $account, $flagging);

    // Invoke Rules event.
    if (module_exists('rules')) {
      $this
        ->invoke_rules_event('unflag', $flagging, $entity_id, $account);
    }

    // Invoke hook_entity_delete().
    module_invoke_all('entity_delete', $flagging, 'flagging');

    // Delete field data.
    field_attach_delete('flagging', $flagging);

    // Delete the flagging entity.
    db_delete('flagging')
      ->condition('flagging_id', $flagging->flagging_id)
      ->execute();

    // Remove from the cache.
    entity_get_controller('flagging')
      ->resetCache();

    // Clear various caches; we don't want code running after us to report
    // wrong counts or false flaggings.
    drupal_static_reset('flag_get_user_flags');
    drupal_static_reset('flag_get_entity_flags');

    // Despite being named in the same pattern as the count API functions, these
    // query the {flagging} table, so are reset here.
    drupal_static_reset('flag_get_entity_flag_counts');
    drupal_static_reset('flag_get_user_flag_counts');
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception('flag', $e);
    throw $e;
  }
}