function _instagram_feeds_uninstall in Instagram Feeds 7
Helper function to run batch operations for removing all Instagram content.
1 call to _instagram_feeds_uninstall()
- instagram_feeds_uninstall in ./
instagram_feeds.install - Implements hook_uninstall().
File
- ./
instagram_feeds.install, line 73 - Instagram Feeds feature updates. Update hooks - enable modules, etc.
Code
function _instagram_feeds_uninstall() {
require_once drupal_get_path('module', 'instagram_feeds') . '/instagram_feeds.module';
$operations = array();
// Delete flags.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'delete_flags',
array(
'flag_as_inappropriate',
'image_archived',
),
),
);
// Delete Instagram blocks.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'blocks_delete',
array(),
),
);
// Delete Instagram settings.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'variables_delete',
array(),
),
);
// Delete Instagram Feeds Importer.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'feeds_importer_delete',
INSTAGRAM_FEEDS_FEED_ID,
),
);
// Delete fields for taxonomy.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'fields_delete',
array(
'entity_type' => 'taxonomy_term',
'bundle' => INSTAGRAM_FEEDS_USERS_VOCABULARY_NAME,
),
),
);
// Delete hashtags.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'taxonomy_delete',
INSTAGRAM_FEEDS_TAGS_VOCABULARY_NAME,
),
);
// Delete Instagram users.
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'taxonomy_delete',
INSTAGRAM_FEEDS_USERS_VOCABULARY_NAME,
),
);
// Delete nodes.
$node_types = array(
INSTAGRAM_FEEDS_IMAGE_NODE_TYPE,
INSTAGRAM_FEEDS_FEEDS_NODE_TYPE,
INSTAGRAM_FEEDS_SETTINGS_NODE_TYPE,
);
$nids = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('type', $node_types, 'IN')
->execute()
->fetchCol();
if (count($nids)) {
$nids_to_delete_chunks = array_chunk($nids, 50);
foreach ($nids_to_delete_chunks as $nids_to_delete) {
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'node_delete',
$nids_to_delete,
),
);
}
}
foreach ($node_types as $node_type) {
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'node_type_delete',
$node_type,
),
);
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'fields_delete',
array(
'entity_type' => 'node',
'bundle' => $node_type,
),
),
);
}
$operations[] = array(
'instagram_feeds_uninstall_process',
array(
'cache_clear',
array(),
),
);
// If run unistall with drush.
if (drupal_is_cli()) {
foreach ($operations as $operation) {
call_user_func_array($operation['0'], $operation[1]);
}
}
else {
$batch = array(
'operations' => $operations,
'title' => t('Uninstalling Instagram Feeds'),
'init_message' => t('Batch is starting...'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('Batch has encountered an error.'),
'file' => drupal_get_path('module', 'instagram_feeds') . '/instagram_feeds.install',
);
batch_set($batch);
}
}