Skip to content

Fix: Theme ZIP install debug warnings in MainWP Child Reports / Child#17

Open
phuochoit wants to merge 3 commits intomainfrom
phuochoit/mwp-1477
Open

Fix: Theme ZIP install debug warnings in MainWP Child Reports / Child#17
phuochoit wants to merge 3 commits intomainfrom
phuochoit/mwp-1477

Conversation

@phuochoit
Copy link
Copy Markdown

@phuochoit phuochoit commented Mar 25, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Prevented null metadata from being written during record insertion, improving data integrity and avoiding invalid entries.
    • Improved automatic-update logging to avoid recording empty or missing identifiers and to ensure log entries only include valid fields.
    • Accept theme references in multiple formats when resolving theme identifiers, preventing empty or invalid slugs from being recorded.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b8b1871-cc4e-4fb9-9686-32d8f8c0f60f

📥 Commits

Reviewing files that changed from the base of the PR and between 90b95a3 and 4c8250b.

📒 Files selected for processing (1)
  • connectors/class-connector-installer.php

Walkthrough

Normalize and skip null meta values before WPDB meta insertion; add theme-slug normalization and safer log-arg construction in the Connector Installer, updating theme-slug extraction sites to use the normalizer and removing empty slug from logged args.

Changes

Cohort / File(s) Summary
Database Meta Insertion
classes/class-db-driver-wpdb.php
Added private normalize_meta_value(); insert_record() now normalizes each meta value, skips entries when normalization returns null, and avoids calling insert_meta() with null/unusable values.
Installer Theme Slug & Log Args
connectors/class-connector-installer.php
Added private normalize_theme_slug($theme) to convert WP_Theme or scalar to a normalized stylesheet slug or null. Updated calls in callback_upgrader_process_complete() and callback_mainwp_child_install_plugin_theme() to use the normalizer. Refactored $log_args construction and conditionally removed slug when empty before logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ 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 accurately describes the main purpose of the pull request: fixing theme ZIP install debug warnings in MainWP Child Reports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phuochoit/mwp-1477

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

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
connectors/class-connector-installer.php (2)

662-668: Pre-existing issue: undefined $success and $error variables.

The compact() call at line 664 references $success and $error, but these variables are not defined in automatic_updates_complete_plugin_theme(). This triggers PHP warnings in 7.3+. Since the PR is refactoring this method, consider fixing this as well.

🔧 Suggested fix to define missing variables
 			if ( ! empty( $type ) ) {
 				$context     = $type . 's';
 				$name        = isset( $log['name'] ) ? $log['name'] : null;
 				$version     = isset( $log['version'] ) ? $log['version'] : null;
 				$slug        = isset( $log['slug'] ) ? $log['slug'] : null;
 				$old_version = isset( $log['old_version'] ) ? $log['old_version'] : null;
 				$message     = isset( $log['message'] ) ? $log['message'] : null;
 				$action      = isset( $log['action'] ) ? $log['action'] : null;
+				$success     = true; // Auto-updates in this method are already validated as successful
+				$error       = null;

 				$this->log(
 					$message,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@connectors/class-connector-installer.php` around lines 662 - 668, The
compact() call passed to $this->log references undefined $success and $error in
automatic_updates_complete_plugin_theme(), causing PHP warnings; either
initialize those variables (e.g., set $success = false; $error = null; or
populate them from the function's update result/error variables used earlier)
before the $this->log(...) call, or remove 'success' and 'error' from the
compact() list so only defined variables (type, name, version, slug,
old_version) are passed.

565-581: Consider adding a guard for empty old_version.

If callback_pre_auto_update fails to execute for any reason, $old_version would be an empty string, resulting in a log message like "WordPress auto-updated from to 6.5". While WordPress core should always fire pre_auto_update before automatic_updates_complete, a defensive check could improve robustness.

🔧 Optional defensive check
 		$old_version  = $this->current_wordpress_version;
 		$new_version  = $info->item->version;
 		$auto_updated = true;

-		$message = esc_html__( 'WordPress auto-updated from %1$s to %2$s', 'mainwp-child-reports' );
+		if ( ! empty( $old_version ) ) {
+			$message = esc_html__( 'WordPress auto-updated from %1$s to %2$s', 'mainwp-child-reports' );
+		} else {
+			$message = esc_html__( 'WordPress auto-updated to %1$s', 'mainwp-child-reports' );
+			$old_version = $new_version; // Use new_version as placeholder for %1$s
+		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@connectors/class-connector-installer.php` around lines 565 - 581, The log can
show an empty "from" when $this->current_wordpress_version was never set; before
creating $old_version (and before calling $this->log), add a guard that checks
$this->current_wordpress_version and either (a) set $old_version to a sensible
placeholder like 'unknown' when empty or (b) skip/abort the log entirely if old
version is missing. Update the code paths around $old_version, $new_version and
the $this->log call (referencing $this->current_wordpress_version, $old_version
and the log invocation) so the resulting message never reads "from to X" and
consistently conveys a valid source version or omits the log.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@connectors/class-connector-installer.php`:
- Around line 662-668: The compact() call passed to $this->log references
undefined $success and $error in automatic_updates_complete_plugin_theme(),
causing PHP warnings; either initialize those variables (e.g., set $success =
false; $error = null; or populate them from the function's update result/error
variables used earlier) before the $this->log(...) call, or remove 'success' and
'error' from the compact() list so only defined variables (type, name, version,
slug, old_version) are passed.
- Around line 565-581: The log can show an empty "from" when
$this->current_wordpress_version was never set; before creating $old_version
(and before calling $this->log), add a guard that checks
$this->current_wordpress_version and either (a) set $old_version to a sensible
placeholder like 'unknown' when empty or (b) skip/abort the log entirely if old
version is missing. Update the code paths around $old_version, $new_version and
the $this->log call (referencing $this->current_wordpress_version, $old_version
and the log invocation) so the resulting message never reads "from to X" and
consistently conveys a valid source version or omits the log.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 273dbe00-458b-419e-b47f-69c51b5c091a

📥 Commits

Reviewing files that changed from the base of the PR and between 364efcb and cab3b5a.

📒 Files selected for processing (1)
  • connectors/class-connector-installer.php

@phuochoit phuochoit force-pushed the phuochoit/mwp-1477 branch from cab3b5a to 364efcb Compare March 30, 2026 17:39
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
connectors/class-connector-installer.php (1)

91-112: Normalize whitespace-only theme slugs to null.

Line 107 only rejects ''. A whitespace-only value can still pass and later cause invalid theme resolution.

Proposed fix
 private function normalize_theme_slug( $theme ) {
 	if ( $theme instanceof \WP_Theme ) {
 		$theme = $theme->get_stylesheet();
 	}

 	if ( is_scalar( $theme ) ) {
-		$theme = (string) $theme;
+		$theme = trim( (string) $theme );
 	}

 	if ( ! is_string( $theme ) || '' === $theme ) {
 		return null;
 	}

 	return $theme;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@connectors/class-connector-installer.php` around lines 91 - 112, The
normalize_theme_slug method currently only rejects the empty string but accepts
whitespace-only slugs; update normalize_theme_slug to trim whitespace after
casting scalars to string (e.g., $theme = trim($theme)); if the trimmed string
is empty return null; otherwise return the trimmed slug. Ensure this change is
applied in the private function normalize_theme_slug (handle the WP_Theme branch
first, then cast and trim the scalar).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@connectors/class-connector-installer.php`:
- Around line 734-735: The code indexes $args['slug'] directly before passing it
to normalize_theme_slug which can raise "undefined array key" notices; guard the
access by checking for the key first (e.g. use isset($args['slug']) or
array_key_exists('slug', $args)) and handle the missing case (early return,
default value, or set $slug = null) before calling
$this->normalize_theme_slug($args['slug']) so normalize_theme_slug is never
called with an undefined index.

---

Nitpick comments:
In `@connectors/class-connector-installer.php`:
- Around line 91-112: The normalize_theme_slug method currently only rejects the
empty string but accepts whitespace-only slugs; update normalize_theme_slug to
trim whitespace after casting scalars to string (e.g., $theme = trim($theme));
if the trimmed string is empty return null; otherwise return the trimmed slug.
Ensure this change is applied in the private function normalize_theme_slug
(handle the WP_Theme branch first, then cast and trim the scalar).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 290664ce-83b5-4e33-b525-92a756350388

📥 Commits

Reviewing files that changed from the base of the PR and between cab3b5a and 90b95a3.

📒 Files selected for processing (2)
  • classes/class-db-driver-wpdb.php
  • connectors/class-connector-installer.php

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants