Skip to content

Instantly share code, notes, and snippets.

@andyg5000
Created October 16, 2015 20:57
Show Gist options
  • Save andyg5000/c09d6fc713a4b44a3d9b to your computer and use it in GitHub Desktop.
Save andyg5000/c09d6fc713a4b44a3d9b to your computer and use it in GitHub Desktop.
<?php
$entity_types = array(
'commerce_order' => array(
'entity_type' => 'commerce_order',
'id_field' => 'order_id',
),
'commerce_line_item' => array(
'entity_type' => 'commerce_line_item',
'id_field' => 'line_item_id',
),
'commerce_customer_profile' => array(
'entity_type' => 'commerce_customer_profile',
'id_field' => 'profile_id',
),
'commerce_payment_transaction' => array(
'entity_type' => 'commerce_payment_transaction',
'id_field' => 'transaction_id',
),
'commerce_product' => array(
'entity_type' => 'commerce_product',
'id_field' => 'product_id',
),
'node' => array(
'entity_type' => 'node',
'id_field' => 'nid',
'bundle' => array(
'name' => 'type',
'value' => 'product',
),
),
);
foreach($entity_types as $entity_type) {
$efq = new EntityFieldQuery();
$efq->entityCondition('entity_type', $entity_type['entity_type']);
// Append budle information to the EFQ if provided.
if (!empty($entity_type['bundle'])) {
$efq->propertyCondition($entity_type['bundle']['name'], $entity_type['bundle']['value']);
};
$results = $efq->execute();
foreach ($results[$entity_type['entity_type']] as $result) {
entity_delete($entity_type['entity_type'], $result->{$entity_type['id_field']});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment