Skip to content

DGI9-617: Fix up logger of user switching.#31

Merged
nchiasson-dgi merged 3 commits intomainfrom
fix/logger
Oct 20, 2025
Merged

DGI9-617: Fix up logger of user switching.#31
nchiasson-dgi merged 3 commits intomainfrom
fix/logger

Conversation

@adam-vessey
Copy link
Contributor

@adam-vessey adam-vessey commented Feb 26, 2025

Summary by CodeRabbit

  • Chores
    • Added Drush service mapping for versions 11.6 and newer, including a compatibility file for 11.6–12.5.
  • Refactor
    • Migrated Drush command to modern dependency injection with a dedicated logger for clearer, more consistent logging.
    • Tightened type hints and batch hook signatures for safer, more predictable execution.
    • Simplified internal logic to improve maintainability without changing behavior.

@adam-vessey adam-vessey added the patch Backwards compatible bug fixes. label Feb 26, 2025
@adam-vessey adam-vessey changed the title SUP-1036: Fix up logger of user switching. DGI9-617: Fix up logger of user switching. Jun 12, 2025
@adam-vessey adam-vessey marked this pull request as ready for review October 14, 2025 14:51
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds Drush 11.6+ service mapping in composer; introduces a new drush.11.6-12.5.yml compatibility file; injects a dedicated logger service into the Drush command via services and constructor; tightens function signatures and simplifies batch op wrapping logic in the module.

Changes

Cohort / File(s) Summary of Changes
Drush version mapping & compatibility
composer.json, drush.11.6-12.5.yml
Added extra.drush.services entry mapping "drush.11.6-12.5.yml": ">=11.6". Introduced drush.11.6-12.5.yml with an empty services: {} and comments guiding instantiation for Drush 11.6+ and 12.5+.
Service wiring for logger (Drush 10)
drush.10.services.yml
Added @logger.islandora_drush_utils as an argument to islandora_drush_utils.command.user_wrapper.
Module typing and batch op wrap adjustments
islandora_drush_utils.module
Strengthened types: islandora_drush_utils_batch_alter(array &$batch): void; `_islandora_drush_utils_user_wrapped_batch_op(int
Drush command DI and logging
src/Drush/Commands/UserWrapperCommands.php
Switched from LoggerAware to autowiring/constructor DI. Implements ContainerInjectionInterface with AutowireTrait. Added protected LoggerInterface $logger and constructor param (autowired to logger.islandora_drush_utils). create() now fetches and passes the logger.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant D as Drush CLI
  participant C as Drupal Container
  participant UWC as UserWrapperCommands
  participant L as logger.islandora_drush_utils
  participant M as islandora_drush_utils.module

  U->>D: Invoke user-wrapper command
  D->>C: Resolve command service (Drush 11.6+ mapping)
  note right of C: drush.11.6-12.5.yml<br/>service compatibility
  C-->>L: Get logger service
  C-->>UWC: Instantiate with logger
  UWC->>M: Prepare batch ops (wrapped)
  M-->>UWC: Static-wrapped callable returned
  UWC->>D: Execute batch (logs via L)
  D-->>U: Output result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hopped through YAML fields with glee,
Wired a logger to sip debug tea. ☕️
Drush learned new tricks, 11 to 12’s door,
Batch ops typed neat—no mess on the floor.
With gentle thumps I signal: all set—
Ship it swift, no burrowed regret! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly references the associated ticket and clearly describes the primary change of improving logger behavior in the user-switching command, which aligns with the main modifications in this pull request. It avoids unnecessary detail and is specific enough for reviewers to understand the focus.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/logger

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 318d245 and fcc8ac1.

📒 Files selected for processing (5)
  • composer.json (1 hunks)
  • drush.10.services.yml (1 hunks)
  • drush.11.6-12.5.yml (1 hunks)
  • islandora_drush_utils.module (4 hunks)
  • src/Drush/Commands/UserWrapperCommands.php (4 hunks)
🔇 Additional comments (10)
drush.11.6-12.5.yml (1)

1-6: LGTM! Correct structure for Drush 11.6+ compatibility.

The empty services mapping aligns with the documented shift to create() and autowiring-based instantiation in newer Drush versions.

composer.json (1)

21-21: LGTM! Correct Drush service mapping.

The new entry properly registers the compatibility file for Drush 11.6+. Note that for Drush 11.6-11.x, both service files will be loaded (drush.10.services.yml and drush.11.6-12.5.yml), which is correct for the transition.

islandora_drush_utils.module (3)

11-11: LGTM! Improved type safety.

The explicit array type hint and void return type improve function contract clarity and enable better static analysis.


57-77: LGTM! Improved clarity with explicit conditionals.

The refactored namer logic uses separate if blocks instead of elseif chains, making each case more explicit and easier to maintain. The empty lines between cases enhance readability.


79-98: LGTM! Performance optimization with static closure.

Making wrap_op static and simplifying the return logic are both good optimizations. Static closures don't bind $this, which is appropriate here since only the use variables are needed.

src/Drush/Commands/UserWrapperCommands.php (4)

12-13: LGTM! Correct imports for explicit dependency injection.

The added imports support the transition from LoggerAwareTrait to explicit DI with AutowireTrait and the Autowire attribute, enabling better control over logger injection.

Also applies to: 16-16


27-29: LGTM! Appropriate DI approach for Drush compatibility.

The shift to ContainerInjectionInterface with AutowireTrait provides dual compatibility:

  • The create() method supports Drush 11.6+
  • The Autowire attribute supports Drush 12.5+ autowiring

This maintains backward compatibility while enabling newer instantiation patterns.


43-50: LGTM! Explicit logger injection.

The logger is properly injected via constructor with an Autowire attribute binding to the service. This replaces the previous LoggerAwareTrait magic with explicit, type-safe dependency injection.


55-62: LGTM! Consistent logger service retrieval.

The create() method correctly fetches the same logger service that the Autowire attribute references, ensuring consistency across both instantiation approaches.

drush.10.services.yml (1)

31-31: Custom logger service is correctly defined.
The service logger.islandora_drush_utils is declared in islandora_drush_utils.services.yml (parent: logger.channel_base), so using @logger.islandora_drush_utils is appropriate.

* Wrap batch op with user.
*/
function _islandora_drush_utils_user_wrapped_batch_op($id, $info, &$context) {
function _islandora_drush_utils_user_wrapped_batch_op(int|string $id, array $info, array &$context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify PHP version supports union types.

The union type int|string requires PHP 8.0+. Please confirm the project's minimum PHP version meets this requirement.

Run the following script to check the PHP version constraint:


🏁 Script executed:

#!/bin/bash
# Description: Check minimum PHP version in composer.json

# Check for PHP version requirement
rg -n '"php":\s*"[^"]*"' composer.json

# Also check for any platform requirements
rg -n -A 5 '"platform"' composer.json

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Locate composer.json files and check PHP version constraint
find . -type f -name 'composer.json' -print | while read file; do
  echo "File: $file"
  rg -n '"php":\s*"[^"]*"' "$file"
  rg -n -A 5 '"platform"' "$file"
done

Length of output: 21


🏁 Script executed:

#!/bin/bash
# Print the top of composer.json to locate PHP version requirement
head -n 200 composer.json

Length of output: 683


Declare PHP 8.0+ as a requirement
The int|string union type needs PHP 8.0 or newer—add "php": ">=8.0" to your composer.json (or confirm your Drupal core constraint already enforces ≥8.0).

🤖 Prompt for AI Agents
In islandora_drush_utils.module around line 110 the function uses the PHP 8.0+
union type "int|string", which requires your project to declare PHP >=8.0;
update composer.json to include "php": ">=8.0" in the "require" section (or
verify that your project's Drupal core or platform constraint already enforces
PHP >=8.0) and run composer update/composer validate to ensure constraints are
consistent; if you cannot raise the PHP requirement, replace the union type with
a compatible declaration (e.g., omit the typehint and validate inside the
function) instead.

@nchiasson-dgi nchiasson-dgi merged commit 52a51c3 into main Oct 20, 2025
2 checks passed
@nchiasson-dgi nchiasson-dgi deleted the fix/logger branch October 20, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Backwards compatible bug fixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants