Skip to content

Add inbox item to try setting up db again#2263

Merged
Crabcyborg merged 10 commits into
masterfrom
add_inbox_item_to_try_setting_up_db_again
Feb 28, 2025
Merged

Add inbox item to try setting up db again#2263
Crabcyborg merged 10 commits into
masterfrom
add_inbox_item_to_try_setting_up_db_again

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Feb 28, 2025

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 28, 2025

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3ced3f2 and 54a0830.

📒 Files selected for processing (1)
  • classes/models/FrmMigrate.php (2 hunks)

Walkthrough

This pull request introduces new functionality for handling missing database tables and improving error reporting. A new condition in the admin controller now triggers a missing tables recovery flow via a static method in the forms controller. Additionally, error detection has been enhanced by instantiating an inbox checker in form listings and adding dedicated methods in both the inbox and migration models to verify table existence and report issues. The XML import process also now requires a specific flag to proceed.

Changes

File(s) Change Summary
classes/controllers/FrmAppController.php
classes/controllers/FrmFormsController.php
Added missing tables recovery logic: FrmAppController now checks for a specific admin page and request parameter to trigger FrmFormsController’s new static method add_missing_tables. Additionally, FrmFormsController’s display_forms_list now instantiates a FrmInbox for error checking.
classes/models/FrmInbox.php
classes/models/FrmMigrate.php
Introduced error handling and validation methods: FrmInbox gains a new static method check_for_error() to scan for error messages, and FrmMigrate implements check_that_tables_exist() in its upgrade process to verify the existence of necessary database tables and report issues if absent.
classes/helpers/FrmXMLHelper.php Refined the conditional check in import_xml_views by requiring that the form_status key is set in the imported array before processing further actions.

Sequence Diagram(s)

sequenceDiagram
    participant UA as User/Admin
    participant AC as FrmAppController
    participant FC as FrmFormsController
    participant DB as Database

    UA->>AC: Load admin page with frm_add_tables parameter
    AC->>AC: Check if page is 'formidable' and parameter present
    AC->>FC: Call add_missing_tables()
    FC->>FC: Verify permissions and table creation error state
    alt Tables Missing
        FC->>DB: Attempt to create missing tables
        DB-->>FC: Return table creation status
        FC->>UA: Redirect or update status based on result
    else
        FC->>UA: Proceed without table creation
    end
Loading
sequenceDiagram
    participant Up as FrmMigrate
    participant DB as Database
    participant FI as FrmInbox

    Up->>DB: Execute SQL query to check tables
    alt Tables Exist
        Up->>FI: Dismiss table error message
    else
        Up->>FI: Add error message with documentation link
    end
Loading

Suggested labels

action: needs qa

Suggested reviewers

  • lauramekaj1

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
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

🧹 Nitpick comments (3)
classes/controllers/FrmFormsController.php (3)

3304-3304: Update the @SInCE version tag.

The @SInCE tag mentions "x.x" which appears to be a placeholder that needs to be updated with the actual version number where this functionality is being introduced.

-	 * @since x.x
+	 * @since 6.x

3297-3327: Consider adding a nonce check for the table recovery process.

The table recovery process performs sensitive operations but lacks a nonce check to verify the request origin.

A nonce check would provide additional security for this operation. Consider adding one like this:

public static function add_missing_tables() {
	FrmAppHelper::permission_check( 'frm_view_forms' );

+	// Verify nonce
+	check_admin_referer( 'frm_fix_tables_nonce', 'frm_fix_tables' );

	$inbox = new FrmInbox();
	$error = $inbox->check_for_error();

3317-3318: Improve database table check logic.

The current code only checks for the existence of the forms table, but there might be other required tables that could also be missing.

Consider using a more comprehensive check for all required tables or let FrmMigrate handle the table existence check:

-global $wpdb;
-$exists = $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->prefix . 'frm_forms''" );
-if ( $exists ) {
+$migrator = new FrmMigrate();
+if ( $migrator->table_exists('frm_forms') ) {
	// Exit early if the table already exists.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c799b35 and 7c674a3.

📒 Files selected for processing (5)
  • classes/controllers/FrmAppController.php (1 hunks)
  • classes/controllers/FrmFormsController.php (2 hunks)
  • classes/helpers/FrmXMLHelper.php (1 hunks)
  • classes/models/FrmInbox.php (1 hunks)
  • classes/models/FrmMigrate.php (2 hunks)
🔇 Additional comments (6)
classes/controllers/FrmAppController.php (1)

569-571: Good addition for database table recovery

This code nicely implements a recovery path for missing database tables. When a user visits the Formidable admin page with the frm_add_tables parameter, it will attempt to recreate any missing tables through the FrmFormsController::add_missing_tables() method.

classes/models/FrmInbox.php (1)

520-536: New error checking method looks good

This method provides a clean way to check for error messages in the inbox, which will be used to display critical issues on the form list page.

Consider updating the @since x.x tag with the actual version number before final release.

classes/models/FrmMigrate.php (2)

45-45: Good integration of table existence check

Adding this check after creating tables and migrating data is an appropriate placement to ensure proper error reporting.


77-98: Well-structured table existence verification

This method provides a robust way to check for missing database tables and notify users through the inbox system. The error message includes helpful documentation links and a clear path to recovery.

Some observations:

  1. The error message is clear and actionable
  2. The "click here" link properly includes the frm_add_tables parameter to trigger the recovery
  3. The method properly dismisses any existing error message if the tables exist

Consider updating the @since x.x tag with the actual version number before final release.

classes/helpers/FrmXMLHelper.php (1)

937-937: Good defensive programming to prevent action creation with incomplete data.

Adding this check ensures that form actions are only created when $imported['form_status'] exists, preventing potential issues when importing XML content with database table problems. This aligns well with the PR's goal of improving database table recovery functionality.

classes/controllers/FrmFormsController.php (1)

1080-1085: Added inbox error checking.

This addition enhances error handling in the form listing page, where errors detected by the FrmInbox system will be displayed to the user.

Comment thread classes/controllers/FrmFormsController.php Outdated
Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
classes/models/FrmMigrate.php (2)

72-76: Update version placeholder in documentation.

The @since x.x should be updated with the actual version number before release.

-	 * @since x.x
+	 * @since 6.x.x

77-98: Consider optimizing the FrmInbox instantiation.

The code instantiates the FrmInbox class twice. It would be more efficient to instantiate it once at the beginning of the method.

 public function check_that_tables_exist() {
 	// Check the DB that the table $this->forms exists.
 	global $wpdb;
+	$inbox = new FrmInbox();
 	$exists = $wpdb->get_results( $wpdb->prepare( "SHOW TABLES LIKE %s", $this->forms ) );
 
 	if ( $exists ) {
-		$inbox = new FrmInbox();
 		$inbox->dismiss( 'failed-to-create-tables' );
 		return;
 	}
 
 	$message = array(
 		'key'     => 'failed-to-create-tables',
 		'subject' => 'Something went wrong setting up the database',
 		'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">documentation</a>. If you need assistance, we recommend that you reach out to your hosting provider. Then <a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_add_tables=1' ) ) . '">click here</a> to try again.',
 		'cta'     => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
 		'type'    => 'error',
 	);
 
-	$inbox = new FrmInbox();
 	$inbox->add_message( $message );
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c674a3 and a8accbb.

📒 Files selected for processing (1)
  • classes/models/FrmMigrate.php (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress
🔇 Additional comments (2)
classes/models/FrmMigrate.php (2)

45-45: Good addition to the upgrade process.

Adding a database table verification step after creation attempts is a good defensive programming practice. This ensures that if tables fail to create, users get actionable feedback.


100-104: Documentation improvement for collation method.

Good addition of PHPDoc to the existing collation() method, improving code readability.

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
classes/controllers/FrmAppController.php (1)

1390-1421: Comprehensive implementation for handling missing database tables.

The implementation properly handles permissions, checks if the error notification exists, verifies if tables already exist to prevent redundant operations, and triggers the necessary database setup.

A few minor suggestions:

  1. Replace the x.x placeholder in the version documentation with the actual version number:
-/**
- * @since x.x
+ /**
+ * @since 6.x
  1. Consider adding a more descriptive comment about what this method does and why it's needed:
-// Check the DB that the table $this->forms exists.
+// Check if the forms table exists. If not, we'll attempt a recovery process
+// by clearing the DB version, which will trigger a fresh table creation.
classes/models/FrmMigrate.php (1)

77-98: Well-implemented error detection and reporting mechanism.

This method effectively checks for the existence of database tables and either dismisses stale error messages or adds helpful guidance when tables are missing.

Suggestions for improvements:

  1. Update the version placeholder in the documentation:
-/**
- * @since x.x
+ /**
+ * @since 6.x
  1. Consider adding a more informative error type to the message array. While "error" correctly identifies the severity, having a more specific identifier might help with programmatic filtering later:
-			'type'    => 'error',
+			'type'    => 'error',
+			'error_type' => 'database_tables_missing',
  1. Add a comment explaining the importance of checking if the tables exist after the migration process has completed, as this helps explain the purpose of this method to other developers.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8accbb and 3ced3f2.

📒 Files selected for processing (3)
  • classes/controllers/FrmAppController.php (2 hunks)
  • classes/controllers/FrmFormsController.php (1 hunks)
  • classes/models/FrmMigrate.php (2 hunks)
🔇 Additional comments (3)
classes/controllers/FrmFormsController.php (1)

1080-1084: Good addition for database error detection.

This code introduces error checking through the FrmInbox class, allowing the system to detect potential database table issues and display them in the forms list. This improves system diagnostics and helps administrators identify missing tables early.

classes/controllers/FrmAppController.php (1)

569-571: Good addition of a retry mechanism for table creation.

This adds a feature to handle missing database tables by allowing users to retry the table creation process from an inbox notification.

classes/models/FrmMigrate.php (1)

45-45: Good placement for table verification.

This call to check_that_tables_exist() is strategically placed after the tables creation and data migration steps, ensuring the system can detect and handle cases where tables failed to create properly.

@Crabcyborg Crabcyborg added this to the 6.19 milestone Feb 28, 2025
@Crabcyborg Crabcyborg merged commit 9d4ff29 into master Feb 28, 2025
@Crabcyborg Crabcyborg deleted the add_inbox_item_to_try_setting_up_db_again branch February 28, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant