Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused methods from ProductMetaQueryHelper. #2370

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions src/DB/ProductMetaQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,75 +76,6 @@ public function delete_all_values( string $meta_key ) {
$this->wpdb->query( $this->wpdb->prepare( $query, $meta_key ) );
}

/**
* Insert a meta value for multiple posts.
*
* @param string $meta_key The meta value to insert.
* @param array $meta_values Array of [post_id=>meta_value,…].
*
* @throws InvalidMeta If the meta key isn't valid.
*/
public function batch_insert_values( string $meta_key, array $meta_values ) {
if ( empty( $meta_values ) ) {
return;
}

self::validate_meta_key( $meta_key );
$meta_key = $this->prefix_meta_key( $meta_key );

foreach ( array_chunk( $meta_values, self::BATCH_SIZE, true ) as $meta_values_chunk ) {
$values = [];
$place_holders = [];
foreach ( $meta_values_chunk as $post_id => $meta_value ) {
$place_holders[] = '(%s, %s, %s)';
$values[] = $meta_key;
$values[] = $post_id;
$values[] = $meta_value;
}
$query = "INSERT INTO {$this->wpdb->postmeta} (`meta_key`, `post_id`, `meta_value` ) VALUES ";
$query .= implode( ', ', $place_holders );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( false === $this->wpdb->query( $this->wpdb->prepare( $query, $values ) ) ) {
do_action(
'woocommerce_gla_debug_message',
sprintf( 'Error batch inserting "%s" meta values.', $meta_key ),
__METHOD__
);
}
}
}

/**
* Update a meta value for multiple posts.
*
* @param string $meta_key The meta value to update.
* @param mixed $meta_value The new meta value.
* @param array $post_ids Post IDs to update.
*
* @throws InvalidMeta If the meta key isn't valid.
*/
public function batch_update_values( string $meta_key, $meta_value, array $post_ids ) {
if ( empty( $post_ids ) ) {
return;
}

self::validate_meta_key( $meta_key );
$meta_key = $this->prefix_meta_key( $meta_key );

foreach ( array_chunk( $post_ids, self::BATCH_SIZE ) as $post_ids_chunk ) {
$query = "UPDATE {$this->wpdb->postmeta} SET `meta_value` = %s WHERE `meta_key` = %s AND `post_id` IN (%d" . str_repeat( ', %d', count( $post_ids_chunk ) - 1 ) . ')';
array_unshift( $post_ids_chunk, $meta_value, $meta_key );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( false === $this->wpdb->query( $this->wpdb->prepare( $query, $post_ids_chunk ) ) ) {
do_action(
'woocommerce_gla_debug_message',
sprintf( 'Error batch updating "%s" meta values.', $meta_key ),
__METHOD__
);
}
}
}

/**
* @param string $meta_key The meta key to validate
*
Expand Down
Loading