← All changes
|
WPDataProjects/Project/WPDP_Project_Table_List.php
+69
-383
5.5.3
→
2.0.13
View file →
| @@ -1,27 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 | 4 | * |
| 6 | - * @package WPDataProjects\Project | |
| 5 | + * @package WPDataProjects | |
| 7 | 6 | */ |
| 8 | 7 | |
| 9 | 8 | namespace WPDataProjects\Project { |
| 10 | 9 | |
| 11 | - use WPDataAccess\Dashboard\WPDA_Dashboard; | |
| 12 | - use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist; | |
| 13 | - use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; | |
| 14 | 10 | use WPDataAccess\List_Table\WPDA_List_Table; |
| 15 | - use WPDataAccess\Plugin_Table_Models\WPDP_Project_Design_Table_Model; | |
| 16 | - use WPDataAccess\Utilities\WPDA_Message_Box; | |
| 17 | - use WPDataAccess\WPDA; | |
| 18 | 11 | |
| 19 | 12 | /** |
| 20 | - * Class WPDP_Project_Table_List extends WPDA_List_Table | |
| 13 | + * Class WPDP_Project_Table_List | |
| 21 | 14 | * |
| 22 | - * @see WPDA_List_Table | |
| 23 | - * | |
| 15 | + * @package WPDataProjects\Project | |
| 24 | 16 | * @author Peter Schulz |
| 25 | 17 | * @since 2.0.0 |
| 26 | 18 | */ |
| 27 | 19 | class WPDP_Project_Table_List extends WPDA_List_Table { |
| @@ -26,198 +18,110 @@ | ||
| 26 | 18 | */ |
| 27 | 19 | class WPDP_Project_Table_List extends WPDA_List_Table { |
| 28 | 20 | |
| 29 | 21 | /** |
| 30 | - * WPDP_Project_Table_List constructor | |
| 22 | + * @var array|null | |
| 23 | + */ | |
| 24 | + protected $all_tables = null; | |
| 25 | + /** | |
| 26 | + * @var null | |
| 27 | + */ | |
| 28 | + protected $sorted_tables = null; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * WPDP_Project_Table_List constructor. | |
| 31 | 32 | * |
| 32 | - * Get and sort list of all database tables | |
| 33 | - * | |
| 34 | 33 | * @param array $args |
| 35 | 34 | */ |
| 36 | - public function __construct( array $args = array() ) { | |
| 37 | - $args['column_headers'] = self::column_headers_labels(); | |
| 35 | + public function __construct( array $args = [] ) { | |
| 36 | + // Add column labels. | |
| 37 | + $args['column_headers'] = [ | |
| 38 | + 'wpda_table_name' => __( 'Table Name', 'wp-data-access' ), | |
| 39 | + 'table_found' => __( 'Table Created', 'wp-data-access' ), | |
| 40 | + 'table_has_relations' => __( 'Table Has Relations', 'wp-data-access' ), | |
| 41 | + 'table_rows' => __( '#Rows', 'wp-data-access' ), | |
| 42 | + ]; | |
| 38 | 43 | $args['title'] = ''; |
| 39 | 44 | $args['allow_import'] = 'off'; |
| 40 | 45 | $args['allow_insert'] = 'off'; |
| 41 | 46 | |
| 47 | + $this->all_tables = \WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists::get_tables( true ); // Get all tables first. | |
| 48 | + foreach ( $this->all_tables as $table) { // Sort tables for quick access to details. | |
| 49 | + $this->sorted_tables[$table['table_name']] = [ | |
| 50 | + 'create_time' => $table['create_time'], | |
| 51 | + 'table_rows' => $table['table_rows'], | |
| 52 | + ]; | |
| 53 | + } | |
| 54 | + | |
| 42 | 55 | parent::__construct( $args ); |
| 43 | 56 | } |
| 44 | 57 | |
| 45 | 58 | /** |
| 46 | - * Overwrite method add_header_button to add reverse engineering | |
| 59 | + * | |
| 47 | 60 | */ |
| 48 | - protected function add_header_button() { | |
| 49 | - global $wpdb; | |
| 50 | - | |
| 51 | - // Check table access to prepare table listbox content | |
| 52 | - $user_default_schema = WPDA::get_user_default_scheme(); | |
| 53 | - if ( $wpdb->dbname === $user_default_schema ) { | |
| 54 | - $table_access = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS ); | |
| 55 | - } else { | |
| 56 | - $table_access = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $user_default_schema ); | |
| 57 | - } | |
| 58 | - if ( false === $table_access ) { | |
| 59 | - $table_access = 'show'; | |
| 60 | - } | |
| 61 | - | |
| 62 | - // Get available databases | |
| 63 | - $schema_names = WPDA_Dictionary_Lists::get_db_schemas(); | |
| 64 | - switch ( $table_access ) { | |
| 65 | - case 'show': | |
| 66 | - $tables = $this->get_all_db_tables( $user_default_schema ); | |
| 67 | - break; | |
| 68 | - case 'hide': | |
| 69 | - $tables = $this->get_all_db_tables( $user_default_schema ); | |
| 70 | - // Remove WordPress tables from listbox content | |
| 71 | - $tables_named = array(); | |
| 72 | - foreach ( $tables as $table ) { | |
| 73 | - $tables_named[ $table ] = true; | |
| 74 | - } | |
| 75 | - foreach ( $wpdb->tables( 'all', true ) as $wp_table ) { | |
| 76 | - unset( $tables_named[ $wp_table ] ); | |
| 77 | - } | |
| 78 | - $tables = array(); | |
| 79 | - foreach ( $tables_named as $key => $value ) { | |
| 80 | - array_push( $tables, $key );//phpcs:ignore - 8.1 proof | |
| 81 | - } | |
| 82 | - break; | |
| 83 | - default: | |
| 84 | - // Show only selected tables and views | |
| 85 | - if ( $wpdb->dbname === $user_default_schema ) { | |
| 86 | - $tables = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED ); | |
| 87 | - } else { | |
| 88 | - $tables = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $user_default_schema ); | |
| 89 | - } | |
| 90 | - if ( false === $tables ) { | |
| 91 | - $tables = ''; | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - $wpnonce = wp_create_nonce( WPDP_Project_Table_Form::WPNONCE_SEED . WPDP_Project_Design_Table_Model::get_base_table_name() ); | |
| 61 | + protected function add_header_button( $add_param = '' ) { | |
| 96 | 62 | ?> |
| 97 | 63 | <form |
| 98 | - method="post" | |
| 99 | - action="?page=<?php echo esc_attr( $this->page ); ?>&tab=tables" | |
| 100 | - style="display: block" | |
| 64 | + method="post" | |
| 65 | + action="?page=<?php echo esc_attr( $this->page ); ?>&tab=tables" | |
| 66 | + style="display: inline-block; vertical-align: unset;" | |
| 101 | 67 | > |
| 102 | 68 | <input type="hidden" name="action" value="reverse_engineering"> |
| 69 | + <div id="no_repository_buttons" style="display:block"> | |
| 70 | + <button class="page-title-action" | |
| 71 | + onclick="jQuery('#no_repository_buttons').hide(); jQuery('#add_table_to_repository').show(); return false;"> | |
| 72 | + <?php echo esc_html__( 'Add Table To Repository', 'wp-data-access' ); ?> | |
| 73 | + </button> | |
| 74 | + </div> | |
| 103 | 75 | <div id="add_table_to_repository" style="display:none"> |
| 104 | - <select name="wpda_schema_name" id="wpda_schema_name"> | |
| 76 | + <select name="wpda_table_name"> | |
| 105 | 77 | <?php |
| 106 | - foreach ( $schema_names as $schema_name ) { | |
| 107 | - $selected = $user_default_schema === $schema_name['schema_name'] ? ' selected' : ''; | |
| 108 | - $database = $user_default_schema === $schema_name['schema_name'] ? "Wordpress database ({$schema_name['schema_name']})" : $schema_name['schema_name']; | |
| 109 | - echo "<option value='{$schema_name['schema_name']}'{$selected}>{$database}</option>"; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 78 | + foreach ( $this->all_tables as $key => $value ) { | |
| 79 | + ?> | |
| 80 | + <option value="<?php echo esc_attr( $value['table_name'] ); ?>"><?php echo esc_attr( $value['table_name'] ); ?></option> | |
| 81 | + <?php | |
| 110 | 82 | } |
| 111 | 83 | ?> |
| 112 | 84 | </select> |
| 113 | - <select name="wpda_table_name" id="wpda_table_name"> | |
| 114 | - <?php | |
| 115 | - if ( is_array( $tables ) ) { | |
| 116 | - foreach ( $tables as $table ) { | |
| 117 | - ?> | |
| 118 | - <option value="<?php echo esc_attr( $table ); ?>"><?php echo esc_attr( $table ); ?></option> | |
| 119 | - <?php | |
| 120 | - } | |
| 121 | - } | |
| 122 | - ?> | |
| 123 | - </select> | |
| 124 | - <input type="hidden" name="wpnonce" | |
| 125 | - value="<?php echo esc_attr( $wpnonce ); ?>"/> | |
| 126 | 85 | <input type="submit" |
| 127 | - value="<?php echo __( 'Add Template For Selected Table To Repository', 'wp-data-access' ); ?>" | |
| 86 | + value="<?php echo esc_html__( 'Add Selected Table To Repository', 'wp-data-access' ); ?>" | |
| 128 | 87 | class="button button-secondary"> |
| 129 | - <input type="button" | |
| 130 | - value="<?php echo __( 'Cancel', 'wp-data-access' ); ?>" | |
| 131 | - class="button button-secondary" | |
| 132 | - onclick="jQuery('#no_repository_buttons').show(); jQuery('#add_table_to_repository').hide(); return false;"> | |
| 88 | + <button class="button button-secondary" | |
| 89 | + onclick="jQuery('#no_repository_buttons').show(); jQuery('#add_table_to_repository').hide(); return false;"> | |
| 90 | + <?php echo esc_html__( 'Cancel', 'wp-data-access' ); ?> | |
| 91 | + </button> | |
| 133 | 92 | </div> |
| 134 | 93 | </form> |
| 135 | - <script type='text/javascript'> | |
| 136 | - function update_table_list(schema_name) { | |
| 137 | - var url = location.pathname + '?action=wpda_get_tables'; | |
| 138 | - var data = { | |
| 139 | - wpdaschema_name: schema_name, | |
| 140 | - wpda_wpnonce: '<?php echo esc_attr( wp_create_nonce( 'wpda-getdata-access-' . WPDA::get_current_user_login() ) ); ?>' | |
| 141 | - }; | |
| 142 | - jQuery.post( | |
| 143 | - url, | |
| 144 | - data, | |
| 145 | - function (data) { | |
| 146 | - jQuery('#wpda_table_name').empty(); | |
| 147 | - | |
| 148 | - var tables = JSON.parse(data); | |
| 149 | - for (var i = 0; i < tables.length; i++) { | |
| 150 | - jQuery('<option/>', { | |
| 151 | - value: tables[i].table_name, | |
| 152 | - html: tables[i].table_name | |
| 153 | - }).appendTo("#wpda_table_name"); | |
| 154 | - } | |
| 155 | - } | |
| 156 | - ); | |
| 157 | - } | |
| 158 | - jQuery(function () { | |
| 159 | - jQuery('#wpda_schema_name').on('change', function () { | |
| 160 | - update_table_list(jQuery('#wpda_schema_name').val()); | |
| 161 | - }); | |
| 162 | - }); | |
| 163 | - </script> | |
| 164 | 94 | <?php |
| 165 | 95 | } |
| 166 | 96 | |
| 167 | 97 | /** |
| 168 | - * Get all db tables and views | |
| 169 | - * | |
| 170 | - * @param string $database Database schema name | |
| 171 | - * | |
| 172 | 98 | * @return array |
| 173 | 99 | */ |
| 174 | - protected function get_all_db_tables( $database ) { | |
| 175 | - $tables = array(); | |
| 176 | - $db_tables = WPDA_Dictionary_Lists::get_tables( true, $database ); // select all db tables and views | |
| 177 | - foreach ( $db_tables as $db_table ) { | |
| 178 | - //phpcs:ignore - 8.1 proof | |
| 179 | - array_push( $tables, $db_table['table_name'] ); // add table or view to array | |
| 180 | - } | |
| 181 | - | |
| 182 | - return $tables; | |
| 183 | - } | |
| 184 | - | |
| 185 | - /** | |
| 186 | - * Overwrites method get_columns to add checkbox | |
| 187 | - * | |
| 188 | - * @return array | |
| 189 | - */ | |
| 190 | 100 | public function get_columns() { |
| 191 | - $columns = array(); | |
| 101 | + $columns = []; | |
| 192 | 102 | |
| 193 | 103 | if ( $this->bulk_actions_enabled ) { |
| 194 | - $columns = array( 'cb' => '<input type="checkbox" />' ); | |
| 104 | + $columns = [ 'cb' => '<input type="checkbox" />' ]; | |
| 195 | 105 | } |
| 196 | 106 | |
| 197 | - return array_merge( $columns, $this->column_headers );//phpcs:ignore - 8.1 proof | |
| 107 | + return array_merge( $columns, $this->column_headers ); | |
| 198 | 108 | } |
| 199 | 109 | |
| 200 | 110 | /** |
| 201 | - * Overwrites method column_default | |
| 202 | - * | |
| 203 | 111 | * @param array $item |
| 204 | 112 | * @param string $column_name |
| 205 | - * | |
| 206 | 113 | * @return mixed|string |
| 207 | 114 | */ |
| 208 | 115 | public function column_default( $item, $column_name ) { |
| 209 | 116 | switch ( $column_name ) { |
| 210 | 117 | case 'table_found': |
| 211 | - if ( 'rdb:' === substr( $item['wpda_schema_name'], 0, 4 ) ) { | |
| 212 | - return __( 'N/A', 'wp-data-access' ); | |
| 213 | - } | |
| 214 | - $wpda_dictionary_exist = new WPDA_Dictionary_Exist( $item['wpda_schema_name'], $item['wpda_table_name'] ); | |
| 215 | - if ( $wpda_dictionary_exist->table_exists() ) { | |
| 216 | - return __( 'Yes', 'wp-data-access' ); | |
| 118 | + if ( isset( $this->sorted_tables[ $item['wpda_table_name'] ] ) ) { | |
| 119 | + return $this->sorted_tables[ $item['wpda_table_name'] ]['create_time']; | |
| 217 | 120 | } else { |
| 218 | - return __( 'No', 'wp-data-access' ); | |
| 121 | + return esc_html__( '--- NOT FOUND ---', 'wp-data-access' ); | |
| 219 | 122 | } |
| 123 | + break; | |
| 220 | 124 | case 'table_has_relations': |
| 221 | 125 | $table_design = json_decode( $item['wpda_table_design'] ); |
| 222 | 126 | if ( isset( $table_design->relationships ) ) { |
| 223 | 127 | return 'Yes'; |
| @@ -223,47 +127,16 @@ | ||
| 223 | 127 | return 'Yes'; |
| 224 | 128 | } else { |
| 225 | 129 | return 'No'; |
| 226 | 130 | } |
| 131 | + break; | |
| 227 | 132 | case 'table_rows': |
| 228 | - if ( 'rdb:' === substr( $item['wpda_schema_name'], 0, 4 ) ) { | |
| 229 | - return __( 'N/A', 'wp-data-access' ); | |
| 230 | - } | |
| 231 | - global $wpdb; | |
| 232 | - $suppress = $wpdb->suppress_errors( true ); | |
| 233 | - if ( '' === $item['wpda_schema_name'] || null === $item['wpda_schema_name'] ) { | |
| 234 | - $query = $wpdb->prepare( | |
| 235 | - 'select count(*) from `%1s`', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 236 | - array( | |
| 237 | - WPDA::remove_backticks( $item['wpda_table_name'] ), | |
| 238 | - ) | |
| 239 | - ); | |
| 133 | + if ( isset( $this->sorted_tables[ $item['wpda_table_name'] ] ) ) { | |
| 134 | + return $this->sorted_tables[ $item['wpda_table_name'] ]['table_rows']; | |
| 240 | 135 | } else { |
| 241 | - $query = $wpdb->prepare( | |
| 242 | - 'select count(*) from `%1s`.`%1s`', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 243 | - array( | |
| 244 | - WPDA::remove_backticks( $item['wpda_schema_name'] ), | |
| 245 | - WPDA::remove_backticks( $item['wpda_table_name'] ), | |
| 246 | - ) | |
| 247 | - ); | |
| 136 | + return '-'; | |
| 248 | 137 | } |
| 249 | - $rows = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL | |
| 250 | - $wpdb->suppress_errors( $suppress ); | |
| 251 | - return null === $rows ? '-' : $rows; | |
| 252 | - case 'wpda_table_name': | |
| 253 | - // Validate schema, table and column names | |
| 254 | - $warning = WPDA::validate_names( $item['wpda_schema_name'], $item['wpda_table_name'] ); | |
| 255 | - if ( '' !== $warning ) { | |
| 256 | - $content = $item['wpda_table_name'] . $warning . | |
| 257 | - substr( parent::column_default( $item, $column_name ), strlen( $item['wpda_table_name'] ) ); | |
| 258 | - | |
| 259 | - return $content; | |
| 260 | - } | |
| 261 | - case 'wpda_schema_name': | |
| 262 | - global $wpdb; | |
| 263 | - if ( $wpdb->dbname === $item[ $column_name ] ) { | |
| 264 | - return "WordPress database ({$item[ $column_name ]})"; | |
| 265 | - } | |
| 138 | + break; | |
| 266 | 139 | default: |
| 267 | 140 | return parent::column_default( $item, $column_name ); |
| 268 | 141 | } |
| 269 | 142 | } |
| @@ -268,9 +141,9 @@ | ||
| 268 | 141 | } |
| 269 | 142 | } |
| 270 | 143 | |
| 271 | 144 | /** |
| 272 | - * Overwrite method column_default_add_action to add tab argument | |
| 145 | + * Overwrite method, add tab argument. | |
| 273 | 146 | * |
| 274 | 147 | * @param array $item |
| 275 | 148 | * @param string $column_name |
| 276 | 149 | * @param array $actions |
| @@ -276,215 +149,28 @@ | ||
| 276 | 149 | * @param array $actions |
| 277 | 150 | */ |
| 278 | 151 | protected function column_default_add_action( $item, $column_name, &$actions ) { |
| 279 | 152 | parent::column_default_add_action( $item, $column_name, $actions ); |
| 280 | - | |
| 281 | - // Add copy table options action. | |
| 282 | - $wp_nonce_action = "wpda-copy-{$this->table_name}"; | |
| 283 | - $wp_nonce = esc_attr( wp_create_nonce( $wp_nonce_action ) ); | |
| 284 | - $form_id = '_' . ( self::$list_number - 1 ); | |
| 285 | - $copy_form = | |
| 286 | - '<form' . | |
| 287 | - " id='copy_form$form_id'" . | |
| 288 | - " action='?page=" . esc_attr( $this->page ) . "'" . | |
| 289 | - " method='post'>" . | |
| 290 | - $this->get_key_input_fields( $item ) . | |
| 291 | - $this->add_parent_args_as_string( $item ) . | |
| 292 | - "<input type='hidden' name='wpdaschema_name' value='<?php echo esc_attr( $this->schema_name ); ?>' />" . | |
| 293 | - "<input type='hidden' name='table_name' value='<?php echo esc_attr( $this->table_name ); ?>' />" . | |
| 294 | - "<input type='hidden' name='action' value='copy' />" . | |
| 295 | - "<input type='hidden' name='_wpnonce' value='$wp_nonce'>" . | |
| 296 | - $this->page_number_item . | |
| 297 | - '</form>' | |
| 298 | 153 | ?> |
| 299 | - | |
| 300 | - <script type='text/javascript'> | |
| 301 | - jQuery("#wpda_invisible_container").append("<?php echo $copy_form; // phpcs:ignore WordPress.Security.EscapeOutput ?>"); | |
| 154 | + <script language="JavaScript"> | |
| 155 | + jQuery("#view_form_" + <?php echo( self::$list_number - 1 ) ?>).append('<input type="hidden" name="tab" value="tables">'); | |
| 156 | + jQuery("#edit_form_" + <?php echo( self::$list_number - 1 ) ?>).append('<input type="hidden" name="tab" value="tables">'); | |
| 157 | + jQuery("#delete_form_" + <?php echo( self::$list_number - 1 ) ?>).append('<input type="hidden" name="tab" value="tables">'); | |
| 302 | 158 | </script> |
| 303 | - | |
| 304 | 159 | <?php |
| 305 | - | |
| 306 | - // Add link to submit form. | |
| 307 | - $copy_warning = __( "Copy project template set?\\n\\'Cancel\\' to stop, \\'OK\\' to copy.", 'wp-data-access' ); | |
| 308 | - $actions['copy'] = sprintf( | |
| 309 | - '<a href="javascript:void(0)" | |
| 310 | - class="edit wpda_tooltip" | |
| 311 | - title="Copy template set" | |
| 312 | - onclick="if (confirm(\'%s\')) jQuery(\'#%s\').submit()"> | |
| 313 | - <span style="white-space:nowrap"> | |
| 314 | - <i class="fas fa-copy wpda_icon_on_button"></i> | |
| 315 | - %s | |
| 316 | - </span> | |
| 317 | - </a> | |
| 318 | - ', | |
| 319 | - $copy_warning, | |
| 320 | - "copy_form$form_id", | |
| 321 | - __( 'Copy', 'wp-data-access' ) | |
| 322 | - ); | |
| 323 | 160 | } |
| 324 | 161 | |
| 325 | 162 | /** |
| 326 | - * Overwrite method to implement copy action | |
| 327 | - * | |
| 328 | - * @return array|void | |
| 163 | + * Overwrite method, add tab argument. | |
| 329 | 164 | */ |
| 330 | - public function process_bulk_action() { | |
| 331 | - if ( 'copy' === $this->current_action() ) { | |
| 332 | - $wp_nonce_action = "wpda-copy-{$this->table_name}"; | |
| 333 | - $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. | |
| 334 | - if ( ! wp_verify_nonce( $wp_nonce, $wp_nonce_action ) ) { | |
| 335 | - die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 336 | - } | |
| 337 | - | |
| 338 | - if ( isset( $_REQUEST['wpda_schema_name'] ) ) { | |
| 339 | - $wpda_schema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_schema_name'] ) ); // input var okay. | |
| 340 | - } | |
| 341 | - if ( isset( $_REQUEST['wpda_table_name'] ) ) { | |
| 342 | - $wpda_table_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); // input var okay. | |
| 343 | - } | |
| 344 | - if ( isset( $_REQUEST['wpda_table_setname'] ) ) { | |
| 345 | - $wpda_table_setname = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_setname'] ) ); // input var okay. | |
| 346 | - } | |
| 347 | - | |
| 348 | - $unique_wpda_table_setname = $this->get_unique_setname( $wpda_schema_name, $wpda_table_name, $wpda_table_setname ); | |
| 349 | - | |
| 350 | - global $wpdb; | |
| 351 | - $wpda_table_design_raw = $wpdb->get_results( | |
| 352 | - $wpdb->prepare( | |
| 353 | - 'SELECT * FROM `%1s` WHERE wpda_schema_name = %s AND wpda_table_name = %s AND wpda_table_setname = %s', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 354 | - array( | |
| 355 | - WPDA::remove_backticks( $this->table_name ), | |
| 356 | - $wpda_schema_name, | |
| 357 | - $wpda_table_name, | |
| 358 | - $wpda_table_setname, | |
| 359 | - ) | |
| 360 | - ), | |
| 361 | - 'ARRAY_A' | |
| 362 | - ); | |
| 363 | - if ( $wpdb->num_rows > 0 ) { | |
| 364 | - $wpda_table_design_raw[0]['wpda_table_setname'] = $unique_wpda_table_setname; | |
| 365 | - $rows_inserted = $wpdb->insert( | |
| 366 | - $this->table_name, | |
| 367 | - $wpda_table_design_raw[0] | |
| 368 | - ); | |
| 369 | - switch ( $rows_inserted ) { | |
| 370 | - case 0: | |
| 371 | - $msg = new WPDA_Message_Box( | |
| 372 | - array( | |
| 373 | - 'message_text' => __( 'Could not copy table options [source not found]', 'wp-data-access' ), | |
| 374 | - 'message_type' => 'error', | |
| 375 | - 'message_is_dismissible' => false, | |
| 376 | - ) | |
| 377 | - ); | |
| 378 | - $msg->box(); | |
| 379 | - break; | |
| 380 | - case 1: | |
| 381 | - $msg = new WPDA_Message_Box( | |
| 382 | - array( | |
| 383 | - 'message_text' => __( 'Table options copied', 'wp-data-access' ), | |
| 384 | - ) | |
| 385 | - ); | |
| 386 | - $msg->box(); | |
| 387 | - break; | |
| 388 | - default: | |
| 389 | - $msg = new WPDA_Message_Box( | |
| 390 | - array( | |
| 391 | - 'message_text' => __( 'Could not copy table options [too many rows]', 'wp-data-access' ), | |
| 392 | - 'message_type' => 'error', | |
| 393 | - 'message_is_dismissible' => false, | |
| 394 | - ) | |
| 395 | - ); | |
| 396 | - $msg->box(); | |
| 397 | - } | |
| 398 | - } | |
| 399 | - } else { | |
| 400 | - parent::process_bulk_action(); | |
| 401 | - } | |
| 402 | - } | |
| 403 | - | |
| 404 | - /** | |
| 405 | - * Create a unique setname for this table | |
| 406 | - * | |
| 407 | - * @param $wpda_schema_name | |
| 408 | - * @param $wpda_table_name | |
| 409 | - * @param $wpda_table_setname | |
| 410 | - * | |
| 411 | - * @return string | |
| 412 | - */ | |
| 413 | - protected function get_unique_setname( $wpda_schema_name, $wpda_table_name, $wpda_table_setname ) { | |
| 414 | - global $wpdb; | |
| 415 | - | |
| 416 | - $i = 2; | |
| 417 | - $query = "select 'x' from `%1s` where wpda_schema_name = %s and wpda_table_name = %s and wpda_table_setname = %s"; | |
| 418 | - | |
| 419 | - $unique_wpda_table_setname = "{$wpda_table_setname}_$i"; | |
| 420 | - $wpdb->get_results( | |
| 421 | - $wpdb->prepare( | |
| 422 | - $query, // phpcs:ignore WordPress.DB.PreparedSQL | |
| 423 | - array( | |
| 424 | - WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ), | |
| 425 | - $wpda_schema_name, | |
| 426 | - $wpda_table_name, | |
| 427 | - $unique_wpda_table_setname, | |
| 428 | - ) | |
| 429 | - ) | |
| 430 | - ); | |
| 431 | - while ( $wpdb->num_rows > 0 ) { | |
| 432 | - // Search until a free options set is found | |
| 433 | - $i ++; | |
| 434 | - $unique_wpda_table_setname = "{$wpda_table_setname}_$i"; | |
| 435 | - $wpdb->get_results( | |
| 436 | - $wpdb->prepare( | |
| 437 | - $query, // phpcs:ignore WordPress.DB.PreparedSQL | |
| 438 | - array( | |
| 439 | - WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ), | |
| 440 | - $wpda_schema_name, | |
| 441 | - $wpda_table_name, | |
| 442 | - $unique_wpda_table_setname, | |
| 443 | - ) | |
| 444 | - ) | |
| 445 | - ); | |
| 446 | - } | |
| 447 | - | |
| 448 | - return $unique_wpda_table_setname; | |
| 449 | - } | |
| 450 | - | |
| 451 | - /** | |
| 452 | - * Overwrite method show to add tab argument | |
| 453 | - */ | |
| 454 | 165 | public function show() { |
| 455 | 166 | parent::show(); |
| 456 | 167 | ?> |
| 457 | - <script type='text/javascript'> | |
| 168 | + <script language="JavaScript"> | |
| 458 | 169 | var wpda_main_form_action = jQuery('#wpda_main_form').attr('action') + '&tab=tables'; |
| 459 | 170 | jQuery('#wpda_main_form').attr('action', wpda_main_form_action); |
| 460 | 171 | </script> |
| 461 | 172 | <?php |
| 462 | - } | |
| 463 | - | |
| 464 | - public static function column_headers_labels() { | |
| 465 | - return array( | |
| 466 | - 'wpda_table_name' => __( 'Table/View Name', 'wp-data-access' ), | |
| 467 | - 'wpda_schema_name' => __( 'Database', 'wp-data-access' ), | |
| 468 | - 'wpda_table_setname' => __( 'Template Set Name', 'wp-data-access' ), | |
| 469 | - 'table_found' => __( 'Exists in DB?', 'wp-data-access' ), | |
| 470 | - 'table_has_relations' => __( 'Has Relationships?', 'wp-data-access' ), | |
| 471 | - 'table_rows' => __( '#Rows', 'wp-data-access' ), | |
| 472 | - ); | |
| 473 | - } | |
| 474 | - | |
| 475 | - public function get_bulk_actions() { | |
| 476 | - $actions = parent::get_bulk_actions(); | |
| 477 | - | |
| 478 | - unset( | |
| 479 | - $actions['bulk-export'], | |
| 480 | - $actions['bulk-export-xml'], | |
| 481 | - $actions['bulk-export-json'], | |
| 482 | - $actions['bulk-export-excel'], | |
| 483 | - $actions['bulk-export-csv'] | |
| 484 | - ); | |
| 485 | - | |
| 486 | - return $actions; | |
| 487 | 173 | } |
| 488 | 174 | |
| 489 | 175 | } |
| 490 | 176 | |