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
37 changes: 37 additions & 0 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ public static function admin_init() {
FrmFormsController::duplicate();
}

if ( FrmAppHelper::is_admin_page( 'formidable' ) && FrmAppHelper::simple_get( 'frm_add_tables' ) ) {
self::add_missing_tables();
}

if ( FrmAppHelper::is_style_editor_page() && 'save' === FrmAppHelper::get_param( 'frm_action' ) ) {
// Hook in earlier than FrmStylesController::route so we can redirect before the headers have been sent.
FrmStylesController::save_style();
Expand Down Expand Up @@ -1382,4 +1386,37 @@ private static function is_our_callback_array( $callback ) {
! empty( $callback['function'][0] ) &&
self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] );
}

/**
* In some cases, the DB tables may fail to install.
* This function tries to add them again when the user clicks the link to try again
* from the given inbox notice.
*
* @since x.x
*/
private static function add_missing_tables() {
FrmAppHelper::permission_check( 'frm_view_forms' );

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

if ( ! $error || 'failed-to-create-tables' !== $error['key'] ) {
// Confirm the inbox item with this CTA exists.
wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
exit;
}

global $wpdb;
$exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'frm_forms' ) );

if ( $exists ) {
// Exit early if the table already exists.
wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
exit;
}

delete_option( 'frm_db_version' );
wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
exit;
}
}
6 changes: 6 additions & 0 deletions classes/controllers/FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ public static function display_forms_list( $params = array(), $message = '', $er
die();
}

$inbox = new FrmInbox();
$error = $inbox->check_for_error();
if ( $error ) {
$show_messages = array( $error['subject'] . '. ' . $error['message'] );
}

require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php';
}

Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmXMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ public static function import_xml_views( $views, $imported ) {
$post_id = false;
if ( $post['post_type'] === $form_action_type ) {
$action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
if ( $action_control && is_object( $action_control ) ) {
if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
}
unset( $action_control );
Expand Down
18 changes: 18 additions & 0 deletions classes/models/FrmInbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,22 @@ function ( $total, $key ) use ( $message ) {
public static function clear_cache() {
delete_option( 'frm_inbox' );
}

/**
* Check inbox for an "error" type. This is displayed on the form list page if one exists.
*
* @since x.x
*
* @return array|false
*/
public static function check_for_error() {
$inbox = new self();
$messages = $inbox->get_messages( 'filter' );
foreach ( $messages as $message ) {
if ( is_array( $message ) && isset( $message['type'] ) && 'error' === $message['type'] ) {
return $message;
}
}
return false;
}
}
35 changes: 35 additions & 0 deletions classes/models/FrmMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function upgrade() {

$this->create_tables();
$this->migrate_data( $old_db_version );
$this->check_that_tables_exist();

// SAVE DB VERSION.
update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
Expand All @@ -68,6 +69,40 @@ public function upgrade() {
}
}

/**
* If we fail to create the database tables, add an inbox notice.
* This informs the user that they need to correct the issue and try again.
*
* @since x.x
*
* @return void
*/
private function check_that_tables_exist() {
// Check the DB that the table $this->forms exists.
global $wpdb;
$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 );
}

/**
* @return string
*/
public function collation() {
global $wpdb;
if ( ! $wpdb->has_cap( 'collation' ) ) {
Expand Down