Problem/Motivation
Currently, the module allows enabling the "Do not delete users who posted comments." option even when the `comment` module is not installed.
If this option is enabled and the `comment` module is not installed, the cron process fails with an exception because it attempts to query the `comment` table, which does not exist.
This is risky because:
- `user_prune` does not declare `comment` as a dependency, so there is no guarantee that the `comment` module is installed.
- Users can enable the option without knowing it depends on `comment`, causing cron errors later.
Steps to reproduce
1. Install and enable `user_prune` on a site without the `comment` module installed.
2. Go to /admin/structure/user-prune/settings.
3. Enable the option "Do not delete users who posted comments.".
4. Run cron.
5. An error occurs because the module attempts to query the `comment` table, which does not exist.
Proposed resolution
Make the comment-related option safer by implementing two changes:
1. In the settings form (`UserPruneSettingsForm`):
Hide the field:
$form['user_with_comment'] = [
'#type' => 'checkbox',
'#title' => $this->t('Do not delete users who posted comments.'),
'#default_value' => $config->get('user_with_comment'),
];
// If the `comment` module is not installed:
if (!\Drupal::moduleHandler()->moduleExists('comment')) {
$form['user_with_comment']['#access'] = FALSE;
}
2. In the user deletion logic (where the `comment` table is queried):
- Check if the `comment` module is installed before running the comment-related logic.
- Ignore the `user_with_comment` setting if `comment` is not installed, even if it is set to `TRUE` in the configuration.
Example in `.module` file:
if ($config->get('user_with_comment') && \Drupal::moduleHandler()->moduleExists('comment')) {
// Logic to exclude users who posted comments.
}
Remaining tasks
- Implement the two proposed changes.
- Verify that cron works correctly with and without the `comment` module installed.
- Test the settings form with and without the `comment` module.
User interface changes
The "Do not delete users who posted comments." field will be hidden in the settings form if the `comment` module is not installed.
API changes
None.
Data model changes
None.