-
-
Save evancauwenberg/9681983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable and uninstall a feature module. | |
* | |
* Note: see some edge cases where some exported components like content types | |
* need to be removed manually. | |
*/ | |
function mymodule_update_7100() { | |
// Note that this does not take care of disabling modules that depend | |
// on this one. | |
module_disable(array('some_module')); | |
drupal_uninstall_modules(array('some_module)); | |
} | |
/** | |
* Delete a field definition and all of its instances. | |
*/ | |
function mymodule_update_7100(&$sandbox) { | |
field_delete_field('field_name'); | |
field_purge_batch(1000); | |
} | |
/** | |
* Delete a content type and taxonomy contained in a feature before disabling it. | |
* | |
* Based on http://drupal.stackexchange.com/questions/44547/unable-to-delete-feature-content-type-after-uninstalling-feature/. | |
*/ | |
function mymodule_update_7100(&$sandbox) { | |
$content_type = 'content_type_to_delete'; | |
$module = 'feature_module_where_its_exported'; | |
// Make content type's fields deletable. | |
db_query("UPDATE {node_type} SET custom = 1, locked = 0 WHERE type = :ctype", array(':ctype' => $content_type)); | |
// Clean Drupal cache; this is necessary for the content type too be 'deletable'. | |
drupal_flush_all_caches(); | |
node_type_delete($content_type); | |
module_disable(array($module)); | |
drupal_uninstall_modules(array($module)); | |
// Delete taxonomies. | |
$machine_names = array('exported_taxonomy1', 'exported_taxonomy2'); | |
foreach ($machine_names as $machine_name) { | |
$taxonomy = taxonomy_vocabulary_machine_name_load($machine_name); | |
taxonomy_vocabulary_delete($taxonomy->vid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment