Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions inc/admin-pages/class-domain-list-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,6 @@ public function handle_add_new_domain_modal(): void {
wp_send_json_error($domain);
}

if (wu_request('primary_domain')) {
$old_primary_domains = wu_get_domains(
[
'primary_domain' => true,
'blog_id' => wu_request('blog_id'),
'id__not_in' => [$domain->get_id()],
'fields' => 'ids',
]
);

/*
* Trigger async action to update the old primary domains.
*/
do_action('wu_async_remove_old_primary_domains', [$old_primary_domains]);
}

wu_enqueue_async_action('wu_async_process_domain_stage', ['domain_id' => $domain->get_id()], 'domain');

wp_send_json_success(
Expand Down
20 changes: 19 additions & 1 deletion inc/models/class-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace WP_Ultimo\Models;

use stdClass;
use WP_Ultimo\Domain_Mapping\Helper;
use WP_Ultimo\Database\Domains\Domain_Stage;

Expand Down Expand Up @@ -295,7 +296,6 @@ public function is_primary_domain() {
* @return void
*/
public function set_primary_domain($primary_domain): void {

$this->primary_domain = $primary_domain;
}

Expand Down Expand Up @@ -483,6 +483,8 @@ public function save() {

$before_changes = clone $this;

$was_new = ! $this->exists();

$results = parent::save();

if (is_wp_error($results) === false) {
Expand Down Expand Up @@ -525,6 +527,22 @@ public function save() {
* after a change is made.
*/
wp_cache_flush();

/*
* If this domain was just set as primary, unset other primaries for this site.
*/
if ($this->primary_domain && ($was_new || (isset($this->_original['primary_domain']) && ! $this->_original['primary_domain']))) {
$old_primary_domains = wu_get_domains(
[
'primary_domain' => true,
'blog_id' => $this->blog_id,
'id__not_in' => [$this->id],
'fields' => 'ids',
]
);

do_action('wu_async_remove_old_primary_domains', $old_primary_domains);
}
Comment on lines +531 to +545
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's check the actual code at the specified lines to understand the current state
sed -n '531,545p' inc/models/class-domain.php | cat -n

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 706


🏁 Script executed:

# Check line 429 for the wu_enqueue_async_action reference mentioned in the review
sed -n '425,435p' inc/models/class-domain.php | cat -n

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 503


🏁 Script executed:

# Search for listeners that handle wu_async_remove_old_primary_domains action
rg -n "add_action.*wu_async_remove_old_primary_domains|wu_async_remove_old_primary_domains" --type php -B 2 -A 10

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 1732


🏁 Script executed:

# Check if wu_enqueue_async_action is used with this action elsewhere
rg -n "wu_enqueue_async_action.*wu_async_remove_old_primary_domains|wu_async_remove_old_primary_domains.*wu_enqueue_async_action" --type php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 63


🏁 Script executed:

# Search for how _original array is populated in base model
rg -n "class Domain|_original|populate.*original" inc/models/class-domain.php -B 2 -A 5 | head -50

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 659


🏁 Script executed:

# Check the parent class/base model to understand _original initialization
find . -name "*.php" -type f | xargs grep -l "class.*Domain.*extends" | grep -v node_modules

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 828


🏁 Script executed:

# Find the async_remove_old_primary_domains method implementation
rg -n "function async_remove_old_primary_domains" --type php -A 20

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 1338


🏁 Script executed:

# Search for Base_Model class to understand _original initialization
fd "class-base-model.php" --type f

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 112


🏁 Script executed:

# Check if there's any initialization of _original in Domain model
rg -n "class Domain|_original\s*=" inc/models/class-domain.php -B 2 -A 3 | head -40

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 211


🏁 Script executed:

# Look for where wu_enqueue_async_action is actually used in the codebase for comparison
rg -n "wu_enqueue_async_action" --type php -B 2 -A 5 | head -40

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2433


🏁 Script executed:

# Examine the actual line 534 more carefully for whitespace/formatting
sed -n '534p' inc/models/class-domain.php | cat -A

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 217


🏁 Script executed:

# Check Base_Model to understand how _original is populated during initialization
head -100 inc/models/class-base-model.php | cat -n

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2350


🏁 Script executed:

# Look for _original initialization in Base_Model
rg -n "_original\s*=" inc/models/class-base-model.php -B 3 -A 3

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 319


🏁 Script executed:

# Check how _original is set when a model is created/loaded
rg -n "public function __construct|function get_original|_original" inc/models/class-base-model.php -B 2 -A 5 | head -80

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 1622


🏁 Script executed:

# Check if the diff provided in review makes sense by comparing whitespace carefully
sed -n '534p' inc/models/class-domain.php | od -c | head -30

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 121


Consider renaming the action or implementing true async queueing for primary domain updates.

The wu_async_remove_old_primary_domains action at line 544 executes synchronously via do_action(), but its name suggests asynchronous processing. The registered listener in inc/managers/class-domain-manager.php (line 895) directly updates domains without queueing async work. To match the naming convention used elsewhere (e.g., wu_enqueue_async_action() at line 210), either rename the action to reflect synchronous execution or use wu_enqueue_async_action() for truly deferred processing.

}

return $results;
Expand Down
21 changes: 1 addition & 20 deletions inc/ui/class-domain-mapping-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,22 +426,6 @@ public function handle_user_add_new_domain_modal(): void {
wp_send_json_error($domain);
}

if (wu_request('primary_domain')) {
$old_primary_domains = wu_get_domains(
[
'primary_domain' => true,
'blog_id' => $current_site_id,
'id__not_in' => [$domain->get_id()],
'fields' => 'ids',
]
);

/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', [$old_primary_domains]);
}

wu_enqueue_async_action('wu_async_process_domain_stage', ['domain_id' => $domain->get_id()], 'domain');

/**
Expand Down Expand Up @@ -629,10 +613,7 @@ public function handle_user_make_domain_primary_modal(): void {
]
);

/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', [$old_primary_domains]);
// Updating the old primaries now happens in the save method.

wp_send_json_success(
[
Expand Down
Loading