Automattic\WooCommerce\Internal\CLI\Migrator\Lib
ImportSession::bump_imported_entities_counts
Updates the progress information.
Method of the class: ImportSession{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ImportSession = new ImportSession(); $ImportSession->bump_imported_entities_counts( $newly_imported_entities );
- $newly_imported_entities(array) (required)
- The new progress data with keys: posts, comments, terms, attachments, users.
ImportSession::bump_imported_entities_counts() ImportSession::bump imported entities counts code WC 10.8.1
public function bump_imported_entities_counts( $newly_imported_entities ) {
foreach ( $newly_imported_entities as $field => $count ) {
if ( ! in_array( $field, static::PROGRESS_ENTITIES, true ) ) {
_doing_it_wrong(
__METHOD__,
'Cannot bump imported entities count for unknown entity type: ' . $field,
'1.0.0'
);
continue;
}
// Get current count from cache or database
if ( ! isset( $this->cached_imported_counts[ $field ] ) ) {
$this->cached_imported_counts[ $field ] = (int) get_post_meta( $this->post_id, 'imported_' . $field, true );
}
// Add new count to total
$new_count = $this->cached_imported_counts[ $field ] + $count;
// Update database and cache
update_post_meta( $this->post_id, 'imported_' . $field, $new_count );
$this->cached_imported_counts[ $field ] = $new_count;
/*
@TODO run an atomic query instead:
$sql = $wpdb->prepare(
"INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value)
VALUES (%d, %s, %d)
ON DUPLICATE KEY UPDATE meta_value = meta_value + %d",
$this->post_id,
'imported_' . $field,
$count,
$count
);
$wpdb->query($sql);
*/
}
}