You are here

function organigrams_item_delete in Organigrams 7

Delete an organigrams item.

Parameters

object $iid: An organigrams item.

Throws

\Exception

3 calls to organigrams_item_delete()
organigrams_delete in ./organigrams.module
Delete an organigram given the organigrams ID.
organigrams_form_confirm_delete_organigrams_item_submit in ./organigrams_item.admin.inc
Form submit handler for 'organigrams_form_confirm_delete_organigrams_item'.
organigrams_import_items in ./organigrams.module
Import organigram items in an existing organigram.
1 string reference to 'organigrams_item_delete'
organigrams_entity_delete in ./organigrams.module
Implements hook_entity_delete().

File

./organigrams.module, line 1767
Defines the organigrams functions and entity types.

Code

function organigrams_item_delete($iid) {

  // Start a transaction.
  $transaction = db_transaction();
  try {

    // Create iid collection.
    $iids = array(
      $iid,
    );
    while (!empty($iids)) {

      // Initialize orphans list.
      $orphans = array();

      // Iterate through the iids.
      foreach ($iids as $iid) {

        // Retrieve children for the current iid.
        $orphans = array_keys(organigrams_item_get_children($iid));

        // Check if the organigrams item exists.
        if (($organigrams_item = organigrams_item_load($iid)) !== NULL) {

          // Remove the organigrams item.
          db_delete('organigrams_item_data')
            ->condition('iid', $iid)
            ->execute();

          // Remove the bundled data for the specified entity.
          field_attach_delete('organigrams_item', $organigrams_item);

          // Allow modules to act upon the delete action.
          module_invoke_all('organigrams_item_delete', $organigrams_item);
          module_invoke_all('entity_delete', $organigrams_item, 'organigrams_item');

          // Reset the organigrams item cache.
          organigrams_items_static_reset();
        }
      }

      // Assign the orphans list to the iids list.
      $iids = $orphans;
    }
  } catch (Exception $ex) {

    // Undo DB changes.
    $transaction
      ->rollback();

    // Log exception.
    watchdog_exception('organigrams', $ex);

    // Rethrow the exception.
    throw $ex;
  }
}