MetaToCustomTableMigrator::generate_update_sql_for_batch()privateWC 1.0

Generate SQL for data updating.

Метод класса: MetaToCustomTableMigrator{}

No Hooks.


String. Generated queries for batch update. Would be of the form: INSERT INTO $table ( $columns ) VALUES ($value for row 1) ($valye for row 2) ... ON DUPLICATE KEY UPDATE $column1 = VALUES($column1) $column2 = VALUES($column2) ...


// private - for code of main (parent) class only
$result = $this->generate_update_sql_for_batch( $batch, $entity_row_mapping ): string;
$batch(array) (required)
Data to generate queries for. Will be data array returned by fetch_data_for_migration_for_ids() method.
$entity_row_mapping(array) (required)
Maps rows to update data with their original IDs. Will be returned by generate_update_sql_for_batch.

Code of MetaToCustomTableMigrator::generate_update_sql_for_batch() WC 7.1.0

private function generate_update_sql_for_batch( array $batch, array $entity_row_mapping ): string {
	$table = $this->schema_config['destination']['table_name'];

	$destination_primary_id_schema = $this->get_destination_table_primary_id_schema();
	foreach ( $batch as $entity_id => $row ) {
		$batch[ $entity_id ][ $destination_primary_id_schema['destination_primary_key']['destination'] ] = $entity_row_mapping[ $entity_id ]->destination_id;

	list( $value_sql, $column_sql, $columns ) = $this->generate_column_clauses(
		array_merge( $destination_primary_id_schema, $this->core_column_mapping, $this->meta_column_mapping ),

	$duplicate_update_key_statement = MigrationHelper::generate_on_duplicate_statement_clause( $columns );

	return "INSERT INTO $table (`$column_sql`) VALUES $value_sql $duplicate_update_key_statement;";