Automattic\WooCommerce\Internal\CLI\Migrator\Core
ProductsController::simulate_stats_increment
Simulate incrementing stats by using reflection to access private properties. This ensures dry-run stats match what the real import would show.
Method of the class: ProductsController{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->simulate_stats_increment( $stat_key ): void;
- $stat_key(string) (required)
- The stat key to increment.
ProductsController::simulate_stats_increment() ProductsController::simulate stats increment code WC 10.7.0
private function simulate_stats_increment( string $stat_key ): void {
try {
$reflection = new \ReflectionClass( $this->product_importer );
$stats_property = $reflection->getProperty( 'import_stats' );
$stats_property->setAccessible( true );
$current_stats = $stats_property->getValue( $this->product_importer );
if ( isset( $current_stats[ $stat_key ] ) ) {
++$current_stats[ $stat_key ];
$stats_property->setValue( $this->product_importer, $current_stats );
}
} catch ( \ReflectionException $e ) {
wc_get_logger()->warning(
"DRY RUN: Could not update import stats for '{$stat_key}': " . $e->getMessage(),
array( 'source' => 'wc-migrator' )
);
}
}