class-adbc-automation-validator.php
7 months ago
class-adbc-common-validator.php
2 days ago
class-adbc-selected-items-validator.php
3 months ago
class-adbc-settings-validator.php
2 days ago
class-adbc-tables-validator.php
7 months ago
class-adbc-tables-validator.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | /** |
| 8 | * ADBC Tables validator class. |
| 9 | * |
| 10 | * This class provides functions to validate and sanitize the tables data used in the plugin. |
| 11 | */ |
| 12 | class ADBC_Tables_Validator { |
| 13 | |
| 14 | /** |
| 15 | * Validate the selected tables names list sent by the user against the existing tables and return the valid ones. |
| 16 | * |
| 17 | * @param array $tables_names The tables names to validate. |
| 18 | * |
| 19 | * @return array The validated tables names, empty array if invalid. |
| 20 | */ |
| 21 | public static function validate_tables_names_list( $tables_names ) { |
| 22 | |
| 23 | $validated_tables = []; |
| 24 | |
| 25 | if ( ! is_array( $tables_names ) ) |
| 26 | return $validated_tables; |
| 27 | |
| 28 | $batch_size = ADBC_Settings::instance()->get_setting( 'database_rows_batch' ); |
| 29 | $offset = 0; |
| 30 | $valid_tables = []; |
| 31 | |
| 32 | // loop through the tables in batches and check the selected tables against the existing tables |
| 33 | while ( $tables_names_batch = ADBC_Tables::get_tables_names( $batch_size, $offset ) ) { |
| 34 | |
| 35 | foreach ( $tables_names as $table_name ) { |
| 36 | |
| 37 | // if the table exists, add it to the valid tables |
| 38 | if ( key_exists( $table_name, $tables_names_batch ) ) |
| 39 | $valid_tables[] = $table_name; |
| 40 | |
| 41 | } |
| 42 | |
| 43 | $offset += $batch_size; |
| 44 | |
| 45 | } |
| 46 | |
| 47 | return $valid_tables; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | } |