You are here

public function DurationFieldCommand::prepareModuleUninstall in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x src/Drush/DurationFieldCommand.php \Drupal\duration_field\Drush\DurationFieldCommand::prepareModuleUninstall()

Prepares the Duration Field module for uninstall.

Deletes all data and field instances.

@command duration_field:prepare_uninstall @aliases df-pu @usage duration_field:prepare_uninstall Deletes all duration field data and duration field fields from the system.

File

src/Drush/DurationFieldCommand.php, line 69

Class

DurationFieldCommand
Drush commands for the Duration Field module.

Namespace

Drupal\duration_field\Drush

Code

public function prepareModuleUninstall() {
  if ($this
    ->confirm('This will delete all duration field in the database, with no means to retrieve it. Do you wish to continue?')) {
    $this
      ->output()
      ->writeln("The following fields have been deleted:");
    $fields = duration_field_get_duration_fields();
    foreach ($fields as $field) {
      $this->output
        ->writeln($field['entity_type'] . ':' . $field['bundle'] . ':' . $field['field']
        ->getName());

      // Delete field.
      $config = FieldConfig::loadByName($field['entity_type'], $field['bundle'], $field['field']
        ->getName());
      if ($config) {
        $config
          ->delete();
      }

      // Delete field storage.
      $storage = FieldStorageConfig::loadByName($field['entity_type'], $field['field']
        ->getName());
      if ($storage) {
        $storage
          ->delete();
      }
    }
  }
  else {
    $this
      ->output()
      ->writeln("No loss of duration for you");
  }
}