You are here

function organigrams_delete in Organigrams 7

Delete an organigram given the organigrams ID.

Parameters

int $oid: An integer representing an organigrams ID.

Return value

int The SAVED_DELETED if successful, otherwise NULL.

Throws

\Exception

1 call to organigrams_delete()
organigrams_form_confirm_delete_organigrams_submit in ./organigrams.admin.inc
Form submit handler for 'organigrams_form_confirm_delete_organigrams'.

File

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

Code

function organigrams_delete($oid) {

  // Retrieve the organigrams object.
  $organigrams = organigrams_load($oid);

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

    // Retrieve all the organigrams items assigned to the current organigrams.
    $result = db_query('SELECT iid FROM {organigrams_item_data} WHERE oid = :oid', array(
      ':oid' => $oid,
    ))
      ->fetchCol();

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

      // Remove the organigrams item.
      organigrams_item_delete($iid);
    }

    // Create delete statement.
    db_delete('organigrams_data')
      ->condition('oid', $oid)
      ->execute();

    // Remove the field bundle.
    field_attach_delete_bundle('organigrams_item', $organigrams->machine_name);

    // Allow modules to perform actions after deletion.
    module_invoke_all('organigrams_delete', $organigrams);
    module_invoke_all('entity_delete', $organigrams, 'organigrams');

    // Clear cache.
    cache_clear_all();

    // Request entity cache reset for the given oid.
    entity_get_controller('organigrams')
      ->resetCache();

    // Return status deleted.
    return SAVED_DELETED;
  } catch (Exception $ex) {

    // Rollback DB modifications.
    $transaction
      ->rollback();

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

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