Uninstall, Install fails, dirty uninstall.

Created on 25 February 2025, about 2 months ago

Problem/Motivation

I uninstalled the ANU core module, it SHOULD uninstall everything. It doesn't. Leaves things quite the mess actually.

Please, when creating modules ensure that you create a clean uninstall. That is what sets you apart from the tinkering guy and the pro.
Running Drupal 11.1.3

Steps to reproduce

The attempt to reinstall:

Unable to install Anu LMS, core.entity_form_mode.node.embedded, eck.eck_entity_type.lesson_checklist_result, eck.eck_type.lesson_checklist_result.lesson_checklist_result, field.storage.node.field_course_finish_button, field.storage.node.field_course_image, field.storage.node.field_course_linear_progress, field.storage.node.field_no_multiple_submissions, image.style.course_preview, image.style.image_bullet_list_large, image.style.image_bullet_list_small, image.style.image_thumbnail_with_caption, image.style.image_wide_with_caption, image.style.image_with_caption, node.type.course already exist in active configuration.
Hide

Here is the anu_lms.uninstall
/**
* Implements hook_uninstall().
*/

function anu_lms_uninstall() {
  // Remove entity form modes.
  $config_names = [
    'core.entity_form_mode.node.embedded',

    // Remove ECK entity types.
    'eck.eck_entity_type.lesson_checklist_result',
    'eck.eck_type.lesson_checklist_result.lesson_checklist_result',

    // Remove field storage definitions.
    'field.storage.node.field_course_finish_button',
    'field.storage.node.field_course_image',
    'field.storage.node.field_course_linear_progress',
    'field.storage.node.field_no_multiple_submissions',

    // Remove image styles.
    'image.style.course_preview',
    'image.style.image_bullet_list_large',
    'image.style.image_bullet_list_small',
    'image.style.image_thumbnail_with_caption',
    'image.style.image_wide_with_caption',
    'image.style.image_with_caption',

    // Remove the "Course" content type.
    'node.type.course',
  ];

  foreach ($config_names as $config_name) {
    if (\Drupal::configFactory()->getEditable($config_name)->isNew() === FALSE) {
      \Drupal::configFactory()->getEditable($config_name)->delete();
    }
  }

  // Delete all "course" content type nodes.
  $storage = \Drupal::entityTypeManager()->getStorage('node');
  $nids = $storage->getQuery()
    ->condition('type', 'course')
    ->execute();

  if (!empty($nids)) {
    $nodes = $storage->loadMultiple($nids);
    $storage->delete($nodes);
  }

  // Clear cache to ensure changes take effect.
  drupal_flush_all_caches();
}

Make sure this is in the info.yml

dependencies:
  - drupal:node
  - drupal:image
  - drupal:field
  - drupal:eck

Something like this should work.

🐛 Bug report
Status

Needs work

Version

2.11

Component

Code

Created by

🇨🇦Canada netgeek123

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024