You are here

function uc_attribute_subject_delete in Ubercart 6.2

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

Deletes an attribute and all options associated with it.

Parameters

$aid: The base attribute ID.

$type: Is this a product or a class?

$id: The product/class ID.

Return value

The Drupal SAVED_DELETED flag.

3 calls to uc_attribute_subject_delete()
UbercartAttributeTestCase::testAttributeAPI in uc_attribute/uc_attribute.test
Tests the basic attribute API.
UbercartAttributeTestCase::testAttributeUIProductAttributeOverview in uc_attribute/uc_attribute.test
Tests the product node attribute user interface.
uc_attribute_delete in uc_attribute/uc_attribute.module
Deletes an attribute from the database.

File

uc_attribute/uc_attribute.module, line 950

Code

function uc_attribute_subject_delete($aid, $type, $id = NULL) {
  $sql = uc_attribute_type_info($type);

  // Base conditions, and an ID check if necessary.
  $conditions[] = "aid = %d";
  if ($id) {
    $conditions[] = "{$sql['id']} = {$sql['placeholder']}";
  }
  $conditions = implode(" AND ", $conditions);
  $result = db_query("SELECT a.oid FROM {uc_attribute_options} AS a JOIN {$sql['opt_table']} AS subject ON a.oid = subject.oid WHERE {$conditions}", $aid, $id);
  while ($oid = db_result($result)) {

    // 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_query("DELETE FROM {$sql['attr_table']} WHERE {$conditions}", $aid, $id);

  // 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;
}