Automattic\WooCommerce\Database\Migrations
MetaToCustomTableMigrator::build_entity_table_query()
Helper method to build query used to fetch data from core source table.
Метод класса: MetaToCustomTableMigrator{}
Хуков нет.
Возвращает
Строку
. Query that can be used to fetch data.
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_entity_table_query( $entity_ids ): string;
- $entity_ids(массив) (обязательный)
- List of entity IDs to fetch.
Код MetaToCustomTableMigrator::build_entity_table_query() MetaToCustomTableMigrator::build entity table query WC 9.2.3
private function build_entity_table_query( array $entity_ids ): string { global $wpdb; $source_entity_table = $this->schema_config['source']['entity']['table_name']; $source_meta_rel_id_column = "`$source_entity_table`.`{$this->schema_config['source']['entity']['meta_rel_column']}`"; $source_primary_key_column = "`$source_entity_table`.`{$this->schema_config['source']['entity']['primary_key']}`"; $where_clause = "$source_primary_key_column IN (" . implode( ',', array_fill( 0, count( $entity_ids ), '%d' ) ) . ')'; $entity_keys = array(); foreach ( $this->core_column_mapping as $column_name => $column_schema ) { if ( isset( $column_schema['select_clause'] ) ) { $select_clause = $column_schema['select_clause']; $entity_keys[] = "$select_clause AS $column_name"; } else { $entity_keys[] = "$source_entity_table.$column_name"; } } $entity_column_string = implode( ', ', $entity_keys ); // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $source_meta_rel_id_column, $source_destination_rel_id_column etc is escaped for backticks. $where clause and $order_by should already be escaped. $query = $wpdb->prepare( " SELECT $source_meta_rel_id_column as entity_meta_rel_id, $source_primary_key_column as primary_key_id, $entity_column_string FROM `$source_entity_table` WHERE $where_clause; ", $entity_ids ); // phpcs:enable return $query; }