-
-
Notifications
You must be signed in to change notification settings - Fork 67
fix(domain): prevent multiple primary domains per site #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(domain): prevent multiple primary domains per site #278
Conversation
- Track original primary state in Domain model to detect changes - Unset other primary domains when setting a new primary - Ensure consistency across API, admin, and creation flows
WalkthroughThe Domain model is enhanced with change tracking for the primary_domain field. A new protected property Changes
Sequence DiagramsequenceDiagram
actor User
participant Domain Model
participant Save Logic
participant Async Queue
participant Cleanup Handler
participant Database
User->>Domain Model: Set primary_domain = true
Domain Model->>Domain Model: Initialize original_primary<br/>(if not already set)
User->>Domain Model: Call save()
Domain Model->>Save Logic: Compute was_new status
Save Logic->>Database: Persist domain record
Database-->>Save Logic: Success
alt Domain is primary AND (newly created OR promoted from non-primary)
Save Logic->>Async Queue: Dispatch wu_async_remove_old_primary_domains
Async Queue-->>Cleanup Handler: Execute async action
Cleanup Handler->>Database: Fetch old primary domains<br/>for same site
Database-->>Cleanup Handler: Return old primaries
Cleanup Handler->>Database: Unset primary status
Database-->>Cleanup Handler: Success
end
Cleanup Handler-->>User: Cleanup complete
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
inc/models/class-domain.php (1)
494-499: Consider clarifying variable naming for readability.The naming of
$new_domain(line 494) and$was_new(line 498) have opposite semantics:
$new_domain = $this->exists()— true when domain exists$was_new = ! $this->exists()— true when domain does not existThis can be confusing for future maintainers. Consider renaming
$new_domainto$existed_before_savefor consistency with$was_new.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
inc/models/class-domain.php(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
inc/models/class-domain.php (4)
inc/models/class-site.php (1)
exists(1243-1246)inc/database/engine/class-table.php (1)
exists(65-72)inc/objects/class-billing-address.php (1)
exists(95-98)inc/functions/domain.php (1)
wu_get_domains(35-38)
🪛 GitHub Check: Code Quality Checks
inc/models/class-domain.php
[failure] 307-307:
Expected 1 space after "!"; 0 found
[failure] 534-534:
Whitespace found at end of line
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cypress (8.1, chrome)
- GitHub Check: cypress (8.2, chrome)
🔇 Additional comments (2)
inc/models/class-domain.php (2)
57-64: LGTM!The new
$original_primaryproperty is well-documented and appropriately typed. It correctly enables change tracking for the primary domain state.
542-557: Verify the async action handler exists and handles empty arrays gracefully.The logic for detecting when a domain becomes primary is correct. However, ensure:
- The
wu_async_remove_old_primary_domainsaction handler is registered elsewhere.- The handler gracefully handles an empty array (when no other primaries exist).
| if ($this->id > 0 && !isset($this->original_primary)) { | ||
| $this->original_primary = $this->primary_domain; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix code style: add space after negation operator.
Static analysis flagged a missing space after !.
Apply this diff:
- if ($this->id > 0 && !isset($this->original_primary)) {
+ if ($this->id > 0 && ! isset($this->original_primary)) {🧰 Tools
🪛 GitHub Check: Code Quality Checks
[failure] 307-307:
Expected 1 space after "!"; 0 found
🤖 Prompt for AI Agents
In inc/models/class-domain.php around lines 307 to 309, the negation operator is
missing a space; change the conditional to add a space after the '!' so it reads
with '! isset(...)' (i.e. ensure there is a space between the '!' and the
following token) to satisfy the code style/static analysis.
| do_action_deprecated('mercator.mapping.updated', $deprecated_args, '2.0.0', 'wu_domain_post_save'); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove trailing whitespace.
Static analysis flagged trailing whitespace at this line.
🧰 Tools
🪛 GitHub Check: Code Quality Checks
[failure] 534-534:
Whitespace found at end of line
🤖 Prompt for AI Agents
In inc/models/class-domain.php at line 534, there is trailing whitespace at the
end of the line; remove any extra spaces or tabs after the code on that line so
the line ends immediately after the last visible character, then save the file
to eliminate the static-analysis warning.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.