Automattic\WooCommerce\Database\Migrations
MetaToCustomTableMigrator::generate_column_clauses()
Generate values and columns clauses to be used in INSERT and INSERT..ON DUPLICATE KEY UPDATE statements.
Метод класса: MetaToCustomTableMigrator{}
Хуков нет.
Возвращает
Массив
. SQL clause for values, columns placeholders, and columns.
Использование
// private - только в коде основоного (родительского) класса $result = $this->generate_column_clauses( $columns_schema, $batch ): array;
- $columns_schema(массив) (обязательный)
- Columns config for destination table.
- $batch(массив) (обязательный)
- Actual data to migrate as returned by data in fetch_data_for_migration_for_ids method.
Код MetaToCustomTableMigrator::generate_column_clauses() MetaToCustomTableMigrator::generate column clauses WC 9.3.1
private function generate_column_clauses( array $columns_schema, array $batch ): array { global $wpdb; $columns = array(); $placeholders = array(); foreach ( $columns_schema as $prev_column => $schema ) { if ( in_array( $schema['destination'], $columns, true ) ) { continue; } $columns[] = $schema['destination']; $placeholders[] = MigrationHelper::get_wpdb_placeholder_for_type( $schema['type'] ); } $values = array(); foreach ( array_values( $batch ) as $row ) { $row_values = array(); foreach ( $columns as $index => $column ) { if ( ! isset( $row[ $column ] ) || is_null( $row[ $column ] ) ) { $row_values[] = 'NULL'; } else { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.NotPrepared -- $placeholders is a placeholder. $row_values[] = $wpdb->prepare( $placeholders[ $index ], $row[ $column ] ); } } $value_string = '(' . implode( ',', $row_values ) . ')'; $values[] = $value_string; } $value_sql = implode( ',', $values ); $column_sql = implode( '`, `', $columns ); return array( $value_sql, $column_sql, $columns ); }