public function deleteExistingObject(NodeInterface $node, Context $context, $dirtyAllowed = false) { /* @var $node EntityNode */ $bundle = $node->getName(); $exists = (int) db_query("SELECT 1 FROM {node} WHERE type = :type", array(':type' => $bundle)); if ($exists) { $context->logDataloss(sprintf("%s: node type has nodes", $node->getPath())); } node_type_delete($bundle); }
<?php // Variable for the content type to delete. $machine_name = 'page'; // Get a list of all nodes for the given content type. $results = db_select('node', 'n')->fields('n', array('nid'))->condition('type', array($machine_name), 'IN')->execute(); foreach ($results as $result) { $nids[] = $result->nid; } // Delete all the nodes. if (!empty($nids)) { node_delete_multiple($nids); } // Delete content type. node_type_delete($machine_name);
function lms_clean_up_subject_structure($subject_type_name, $subject_display_name) { // 1. Clean up contnet types $course_type_machine_name = $subject_type_name. COURSE_SUBFIX; // machine name of course content type for the subject node_type_delete($course_type_machine_name); print "<h2>Content Type [$course_type_machine_name] has been deleted</h1>"; $capability_type_machine_name = $subject_type_name. CAPABILITY_SUBFIX; // machine name of course content type for the subject node_type_delete($capability_type_machine_name); print "<h2>Content Type [capability_type_machine_name] has been deleted</h1>"; $task_type_machine_name = $subject_type_name. TASK_SUBFIX; // machine name of course content type for the subject node_type_delete($task_type_machine_name); print "<h2>Content Type [$task_type_machine_name] has been deleted</h1>"; // 2. clean up vocabulary $course_vocab_display_name = $subject_display_name . t(' course vocabulary'); //dsiplayname of course content type $capability_vocab_display_name = $subject_display_name . t(' capability vocabulary'); //dsiplayname of course content type $task_vocab_display_name = $subject_display_name . t(' task vocabulary'); //dsiplayname of course content type $vocabs = taxonomy_get_vocabularies(); foreach ($vocabs as $vid => $vocab){ if ($vocab->name == $course_vocab_display_name || $vocab->name == $capability_vocab_display_name || $vocab->name == $task_vocab_display_name) { taxonomy_del_vocabulary($vid); print "<h2>Vocabulary [$vocab->name] has been deleted</h1>"; } } }
/** * tearDown implementation, setting back switched modules etc */ function tearDown() { if ($this->_modules != $this->_originalModules) { $form_state['values'] = array('status' => $this->_originalModules, 'op' => t('Save configuration')); drupal_execute('system_modules', $form_state); //rebuilding all caches drupal_rebuild_theme_registry(); node_types_rebuild(); menu_rebuild(); cache_clear_all('schema', 'cache'); module_rebuild_cache(); $this->_modules = $this->_originalModules; } foreach ($this->_cleanupVariables as $name => $value) { if (is_null($value)) { variable_del($name); } else { variable_set($name, $value); } } $this->_cleanupVariables = array(); //delete nodes foreach ($this->_cleanupNodes as $nid) { node_delete($nid); } $this->_cleanupNodes = array(); //delete roles while (sizeof($this->_cleanupRoles) > 0) { $rid = array_pop($this->_cleanupRoles); db_query("DELETE FROM {role} WHERE rid = %d", $rid); db_query("DELETE FROM {permission} WHERE rid = %d", $rid); } //delete users and their content while (sizeof($this->_cleanupUsers) > 0) { $uid = array_pop($this->_cleanupUsers); // cleanup nodes this user created $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid); while ($node = db_fetch_array($result)) { node_delete($node['nid']); } user_delete(array(), $uid); } //delete content types foreach ($this->_cleanupContentTypes as $type) { node_type_delete($type); } $this->_cleanupContentTypes = array(); //Output drupal warnings and messages into assert messages $drupal_msgs = drupal_get_messages(); foreach ($drupal_msgs as $type => $msgs) { foreach ($msgs as $msg) { $this->assertTrue(TRUE, "{$type}: {$msg}"); } } parent::tearDown(); }
/** * Delete text content type. */ protected static function deleteTestContentType() { node_type_delete(self::$contentType->type); }
/** * Deletes the current content type. * * @throws \Exception */ public function delete() { // Make sure the definition is valid. $validation = $this->validate(); if ($validation !== true) { throw new \Exception("The content type is invalid. Reason {$validation}. Cannot delete."); } // Delete the content type. node_type_delete($this->definition['type']); }
public function afterScenario($event) { foreach ($this->users as $user) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'commerce_order')->propertyCondition('uid', $user->uid); $result = $query->execute(); if (isset($result['commerce_order'])) { $order_ids = array_keys($result['commerce_order']); commerce_order_delete_multiple($order_ids); } $query2 = new EntityFieldQuery(); $query2->entityCondition('entity_type', 'rooms_booking')->propertyCondition('uid', $user->uid); $result = $query2->execute(); if (isset($result['rooms_booking'])) { $booking_ids = array_keys($result['rooms_booking']); rooms_booking_delete_multiple($booking_ids); } } parent::afterScenario($event); if (!empty($this->units)) { foreach ($this->units as $unit) { $unit->delete(); } } if (!empty($this->unitTypes)) { foreach ($this->unitTypes as $unit_type) { $unit_type->delete(); } } if (!empty($this->bookingTypes)) { foreach ($this->bookingTypes as $booking_type) { $booking_type->delete(); } } if (!empty($this->bookings)) { rooms_booking_delete_multiple($this->bookings); } if (!empty($this->customerProfiles)) { commerce_customer_profile_delete_multiple($this->customerProfiles); db_delete('rooms_customers')->condition('commerce_customer_id', $this->customerProfiles)->execute(); } if (!empty($this->products)) { $product_ids = array(); foreach ($this->products as $product) { $product_ids[] = $product->product_id; } commerce_product_delete_multiple($product_ids); } foreach ($this->content_types as $content_type) { node_type_delete($content_type); } foreach ($this->fields as $field) { field_delete_field($field); } }
/** * Reinitialize some Community environment settings. * * @AfterFeature @cleanCommunityEnvironment */ public static function cleanCommunityEnvironment() { // Delete 'community' node type. _node_types_build(TRUE); node_type_delete('community'); field_purge_batch(1); // Delete community's variables. $feature = features_load_feature('nexteuropa_communities'); if (isset($feature->info['features']['variable'])) { foreach ($feature->info['features']['variable'] as $varname) { variable_del($varname); } } // Delete community's menu_links. if (isset($feature->info['features']['menu_links'])) { foreach ($feature->info['features']['menu_links'] as $menulinks) { menu_link_delete(NULL, $menulinks); } } // Delete community's menu_custom. if (isset($feature->info['features']['menu_custom'])) { foreach ($feature->info['features']['menu_custom'] as $menucustom) { $menu = menu_load($menucustom); menu_delete($menu); } } drupal_flush_all_caches(); }