Automattic\WooCommerce\Database\Migrations
MetaToCustomTableMigrator::get_already_existing_records
Fetch id mappings for records that are already inserted in the destination table.
Метод класса: MetaToCustomTableMigrator{}
Хуков нет.
Возвращает
Массив. Already migrated entities, would be of the form array(
'$source_id1' => array( 'source_id' => $source_id1, 'destination_id' => $destination_id1 'modified' => 0 if it can be determined that the row doesn't need update, 1 otherwise ), ...
)
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_already_existing_records( $entity_ids ): array;
- $entity_ids(массив) (обязательный)
- List of entity IDs to verify.
Код MetaToCustomTableMigrator::get_already_existing_records() MetaToCustomTableMigrator::get already existing records WC 10.5.0
protected function get_already_existing_records( array $entity_ids ): array {
global $wpdb;
$source_table = $this->schema_config['source']['entity']['table_name'];
$source_destination_join_column = $this->schema_config['source']['entity']['destination_rel_column'];
$source_primary_key_column = $this->schema_config['source']['entity']['primary_key'];
$destination_table = $this->schema_config['destination']['table_name'];
$destination_source_join_column = $this->schema_config['destination']['source_rel_column'];
$destination_primary_key_column = $this->schema_config['destination']['primary_key'];
$entity_id_placeholder = implode( ',', array_fill( 0, count( $entity_ids ), '%d' ) );
$additional_where = $this->get_additional_where_clause_for_get_data_to_insert_or_update( $entity_ids );
$already_migrated_entity_ids = $this->db_get_results(
$wpdb->prepare(
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- All columns and table names are hardcoded.
"
SELECT source.`$source_primary_key_column` as source_id, destination.`$destination_primary_key_column` as destination_id
FROM `$destination_table` destination
JOIN `$source_table` source ON source.`$source_destination_join_column` = destination.`$destination_source_join_column`
WHERE source.`$source_primary_key_column` IN ( $entity_id_placeholder ) $additional_where
",
$entity_ids
)
// phpcs:enable
);
return array_column( $already_migrated_entity_ids, null, 'source_id' );
}