You are here

function filedepot_uninstall in filedepot 7

Same name and namespace in other branches
  1. 6 filedepot.install \filedepot_uninstall()

Implementation of hook_uninstall().

File

./filedepot.install, line 215
filedepot.install filedepot: File Management Module developed by Nextide www.nextide.ca

Code

function filedepot_uninstall() {
  global $base_path;
  include_once './' . drupal_get_path('module', 'filedepot') . '/filedepot.class.php';
  include_once './' . drupal_get_path('module', 'filedepot') . '/permissions.class.php';
  $filedepot = filedepot::getInstance();
  include_once './' . drupal_get_path('module', 'filedepot') . '/lib-common.php';

  // Gather all the example content that might have been created while this module was enabled.
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  $result = db_query($sql, array(
    ':type' => 'filedepot_folder',
  ));
  $nids = array();
  foreach ($result as $row) {
    $nids[] = $row->nid;
  }

  // Delete all the nodes at once
  // http://api.drupal.org/api/function/node_delete_multiple/7
  node_delete_multiple($nids);

  // Loop over each of the fields defined by this module and delete
  // all instances of the field, their data, and the field itself.
  // http://api.drupal.org/api/function/field_delete_field/7
  foreach (array_keys(_filedepot_installed_fields()) as $field) {
    field_delete_field($field);
  }

  // Loop over any remaining field instances attached to the node_example
  // content type (such as the body field) and delete them individually.
  // http://api.drupal.org/api/function/field_delete_field/7
  $instances = field_info_instances('node', 'filedepot_folder');
  foreach ($instances as $instance_name => $instance) {
    field_delete_instance($instance);
  }

  // Delete our content type
  // http://api.drupal.org/api/function/node_type_delete/7
  node_type_delete('filedepot_folder');
  node_type_cache_reset();

  // Purge all field infromation
  // http://api.drupal.org/api/function/field_purge_batch/7
  field_purge_batch(1000);
  $sitepath = dirname(realpath($_SERVER['SCRIPT_FILENAME']));
  $sitepath = str_replace('\\', '/', $sitepath);
  if (@is_dir($filedepot->tmp_incoming_path) === TRUE) {
    filedepot_delTree($filedepot->tmp_incoming_path);
  }
  if (@is_dir($filedepot->tmp_storage_path) === TRUE) {
    filedepot_delTree($filedepot->tmp_storage_path);
  }
  if (@is_dir($filedepot->root_storage_path) === TRUE) {
    filedepot_delTree($filedepot->root_storage_path);
  }
  variable_del('filedepot_override_folderorder');
  variable_del('filedepot_content_type_initialized');
  variable_del('filedepot_default_allow_broadcasts');
  variable_del('filedepot_default_notify_filechange');
  variable_del('filedepot_default_notify_newfile');
  variable_del('filedepot_notifications_enabled');
  variable_del('filedepot_pass1_recordcount');
  variable_del('filedepot_pass2_recordcount');
  variable_del('filedepot_yui_baseurl');
  variable_del('filedepot_filetype_filter');
  variable_del('filedepot_filetype_filterdata');
  variable_del('filedepot_default_owner');
  variable_del('filedepot_default_perms_data');
  variable_del('filedepot_default_roles');
  variable_del('filedepot_extensions');
  variable_del('filedepot_extension_data');
  variable_del('node_options_filedepot_folder');
  variable_del('comment_filedepot_folder');
  variable_del('filedepot_auto_create_group_rootfolder_enabled');
  variable_del('filedepot_organic_group_mode_enabled');
  variable_del('filedepot_displayorder_filesfirst');
  variable_del('filedepot_email_to');
}