page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // input var okay. } else { wp_die( __( 'ERROR: Wrong arguments', 'wp-data-access' ) ); } if ( isset( $_REQUEST['action'] ) ) { $this->action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); } if ( isset( $_REQUEST['action2'] ) ) { $this->action2 = sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) ); } if ( isset( $_REQUEST['wpda_table_name'] ) && ! is_array( $_REQUEST['wpda_table_name'] ) ) { $wpda_project_design_table_model = new WPDP_Project_Design_Table_Model(); if ( 'reconcile' === $this->action ) { $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); // input var okay. $wpda_reverse_engineering = new \WPDataAccess\Utilities\WPDA_Reverse_Engineering( $wpda_table_name_re ); $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' ); if ( isset( $_REQUEST['keep_options'] ) ) { $param_keep_options = sanitize_text_field( wp_unslash( $_REQUEST['keep_options'] ) ); } else { $param_keep_options = 'off'; } $result_update = $wpda_project_design_table_model->reconcile( $table_structure, $param_keep_options ); if ( false === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Update failed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } if ( 0 === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Nothing to save', 'wp-data-access' ), ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Succesfully saved changes to database', 'wp-data-access' ), ] ); $msg->box(); } } elseif ( 'reverse_engineering' === $this->action ) { if ( isset( $_REQUEST['wpda_table_name'] ) ) { $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); // input var okay. $wpda_reverse_engineering = new \WPDataAccess\Utilities\WPDA_Reverse_Engineering( $wpda_table_name_re ); $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' ); if ( count( $table_structure ) > 0 ) { $this->wpda_table_name = $wpda_table_name_re; $this->wpda_table_design = $table_structure; } else { wp_die( __( 'ERROR: Reverse engineering table failed', 'wp-data-access' ) ); } if ( ! WPDP_Project_Design_Table_Model::insert_reverse_engineered( $this->wpda_table_name, $this->wpda_table_design ) ) { wp_die( __( 'ERROR: Reverse engineering table failed', 'wp-data-access' ) ); } else { // Convert named array to object (needed to display structure). $this->wpda_table_design = json_decode( json_encode( $table_structure ) ); } $this->action2 = 'edit'; $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Table added to respository', 'wp-data-access' ), ] ); $msg->box(); } else { wp_die( __( 'ERROR: Wrong arguments', 'wp-data-access' ) ); } } elseif ( null !== $this->action2 ) { $result_update = $wpda_project_design_table_model->update(); if ( false === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Update failed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } if ( 0 === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Nothing to save', 'wp-data-access' ), ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Succesfully saved changes to database', 'wp-data-access' ), ] ); $msg->box(); } } $wpda_project_design_table_model->query(); $structure_messages = $wpda_project_design_table_model->validate(); foreach ( $structure_messages as $messages ) { if ( 'ERR' === $messages[0] ) { $msg = new WPDA_Message_Box( [ 'message_text' => $messages[1], 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => $messages[1], ] ); $msg->box(); } } $this->table_structure = $wpda_project_design_table_model->get_table_design(); $this->wpda_table_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); $this->wpda_data_dictionary = new WPDA_Dictionary_Exist( '', $this->wpda_table_name ); if ( $this->wpda_data_dictionary->table_exists() ) { $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( '', $this->wpda_table_name, 'tableform' ); if ( 0 === count( $this->wpda_list_columns->get_table_primary_key() ) ) { $this->has_primary_key = false; } else { $this->has_primary_key = true; } } else { wp_die( __( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) ); } } else { wp_die( __( 'ERROR: Argument wpda_table_name not found', 'wp-data-access' ) ); } } /** * */ public function show() { ?>
show_table_info(); if ( true === $this->has_primary_key ) { echo '