Skip to content

Instantly share code, notes, and snippets.

@JonMcL
Created April 13, 2014 16:33
Show Gist options
  • Select an option

  • Save JonMcL/10591338 to your computer and use it in GitHub Desktop.

Select an option

Save JonMcL/10591338 to your computer and use it in GitHub Desktop.
/**
* Delete fields no longer used by this module.
*/
function hook_update_N() {
$fields_to_delete = array(
'field_cost',
'field_construction_budget',
'field_construction_cost',
'field_total_budget',
);
foreach ($fields_to_delete as $field_name) {
field_delete_field($field_name);
watchdog('module_name', 'Deleted the :field_name field from all content type instances.', array(':field_name' => $field_name));
}
/**
* The fields aren't really deleted until the purge function runs, ordinarily
* during cron. Count the number of fields we need to purge, and add five in
* case a few other miscellaneous fields are in there somehow.
*/
field_purge_batch(count($fields_to_delete) + 5);
// THEN, in case of field type change, revert the feature
features_revert(array('module_name' => array('field')));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment