You are here

function uc_attribute_subject_delete in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_attribute/uc_attribute.module \uc_attribute_subject_delete()
  2. 6.2 uc_attribute/uc_attribute.module \uc_attribute_subject_delete()

Deletes an attribute and all options associated with it.

Parameters

int $aid: The base attribute ID.

string $type: Is this a product or a class?

$id: The product/class ID.

Return value

int The Drupal SAVED_DELETED flag.

2 calls to uc_attribute_subject_delete()
UbercartAttributeTestCase::testAttributeAPI in uc_attribute/tests/uc_attribute.test
Tests the basic attribute API.
uc_attribute_delete in uc_attribute/uc_attribute.module
Deletes an attribute from the database.

File

uc_attribute/uc_attribute.module, line 914
Ubercart Attribute module.

Code

function uc_attribute_subject_delete($aid, $type, $id = NULL) {
  $sql = uc_attribute_type_info($type);
  $query = db_select('uc_attribute_options', 'a')
    ->fields('a', array(
    'oid',
  ));
  $query
    ->join($sql['opt_table'], 'subject', 'a.oid = subject.oid');

  // Base conditions, and an ID check if necessary.
  $conditions = db_and()
    ->condition('aid', $aid);
  if ($id) {
    $conditions
      ->condition($sql['id'], $id);
  }
  $query
    ->condition($conditions);
  $result = $query
    ->execute();
  while ($oid = $result
    ->fetchField()) {

    // Don't delete the adjustments one at a time. We'll do it in bulk soon for
    // efficiency.
    uc_attribute_subject_option_delete($oid, $type, $id, FALSE);
  }
  db_delete($sql['attr_table'])
    ->condition($conditions)
    ->execute();

  // If this is a product attribute, wipe any associated adjustments.
  if ($type == 'product') {
    uc_attribute_adjustments_delete(array(
      'aid' => $aid,
      'nid' => $id,
    ));
  }
  return SAVED_DELETED;
}