You are here

function configuration_delete_multiple in Configuration Management 7

Delete a specific configuration from being tracked.

2 calls to configuration_delete_multiple()
configuration_confirm_delete_submit in ./configuration.admin.inc
Submit handler for deleting configs.
configuration_delete in ./configuration.module
Delete a specific configuration from being tracked.

File

./configuration.module, line 612
Module file for the configuration module, which enables the capture and management of configuration in Drupal.

Code

function configuration_delete_multiple($cids) {
  module_load_include('inc', 'configuration', 'configuration.export');
  $transaction = db_transaction();
  try {

    // Build an array of configs to exclude when writing to file.  Even though
    // we deleted the tracking row in the config_export table, configuration
    // module looks through all the config files and will build an $export
    // array which is used to generate the configs again in rebuilt files.  By
    // passing in an exclude array we can ensure these configs do not get
    // exported again.
    $names = db_query("SELECT name, owner FROM {config_export} WHERE cid IN (" . join(',', $cids) . ")")
      ->fetchAll();
    foreach ($names as $name) {
      $exclude[$name->name] = $name->owner;
      $config[$name->owner] = array(
        $name->name => array(),
      );
    }

    // Pass the configuration I want to disable into the populate functions to
    // see what dependencies this component has.  Then check status of
    // dependencies to make sure they are in sync before rewriting the files.
    $config_populate = configuration_populate_sanitize($config);
    $export = configuration_populate($config_populate, array());

    // Track dependencies on config_export table
    _configuration_track_dependencies($export);
    $config = array_key_exists('configuration_dependency', $export) ? array_merge($config, $export['configuration_dependency']['configuration']) : $config;
    if (array_key_exists('configuration_dependency', $export) && !configuration_check_changed(CONFIGURATION_ACTIVESTORE_OVERRIDDEN, array_keys($export['configuration_dependency']['configuration']))) {
      drupal_get_messages();
      drupal_set_message(t('Unable to stop tracking. Dependent configurations that are overridden in the activestore would be written to file. Write configurations in %component component(s) first, then try again.', array(
        '%component' => join(', ', array_keys($export['configuration_dependency']['configuration'])),
      )), 'error');
      return FALSE;
    }
    if (!configuration_check_changed(CONFIGURATION_DATASTORE_ONLY | CONFIGURATION_DATASTORE_OVERRIDDEN, array_keys($config))) {
      drupal_get_messages();
      drupal_set_message(t('Unable to stop tracking. Configs would be lost when rewriting %component config file. Activate configurations in %component component(s) first, then try again.', array(
        '%component' => join(', ', array_keys($config)),
      )), 'error');
      return FALSE;
    }
    $files = configuration_export_render($export);
    foreach (array_keys($files) as $filename) {
      unlink("config://" . $filename . '.inc');
      watchdog('configuration', 'Deleted %file for rewrite.', array(
        '%file' => $filename . '.inc',
      ));
    }

    // Queue the configuration up for deletion.
    db_update('config_export')
      ->fields(array(
      'status' => CONFIGURATION_DELETE,
    ))
      ->condition('cid', $cids, 'IN')
      ->execute();
    cache_clear_all('config_export', 'cache');

    // Write the new configuration to disk.
    configuration_write_exports(array_keys($config), $exclude);

    // Delete the configuration.
    db_delete('config_export')
      ->condition('cid', $cids, 'IN')
      ->execute();
    db_update('config_export')
      ->fields(array(
      'parent' => '',
    ))
      ->condition('parent', array_keys($exclude), 'IN')
      ->execute();
    cache_clear_all('config_export', 'cache');
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception('configuration', $e);
    throw $e;
  }
  return TRUE;
}