Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog
AsyncGenerator::feed_generation_action
Action scheduler callback for the feed generation.
Метод класса: AsyncGenerator{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$AsyncGenerator = new AsyncGenerator(); $AsyncGenerator->feed_generation_action( $option_key );
- $option_key(строка) (обязательный)
- The option key for the feed generation status.
Список изменений
| С версии 10.5.0 | Введена. |
Код AsyncGenerator::feed_generation_action() AsyncGenerator::feed generation action WC 10.5.2
public function feed_generation_action( string $option_key ) {
$status = get_option( $option_key );
if ( ! is_array( $status ) || ! isset( $status['state'] ) || self::STATE_SCHEDULED !== $status['state'] ) {
wc_get_logger()->error( 'Invalid feed generation status', array( 'status' => $status ) );
return;
}
$status['state'] = self::STATE_IN_PROGRESS;
update_option( $option_key, $status );
try {
$feed = $this->integration->create_feed();
$walker = ProductWalker::from_integration( $this->integration, $feed );
// Add dynamic args to the mapper.
$args = $status['args'] ?? array();
if (
isset( $args['_product_fields'] )
&& is_string( $args['_product_fields'] ) &&
! empty( $args['_product_fields'] )
) {
$this->integration->get_product_mapper()->set_fields( $args['_product_fields'] );
}
if (
isset( $args['_variation_fields'] )
&& is_string( $args['_variation_fields'] ) &&
! empty( $args['_variation_fields'] )
) {
$this->integration->get_product_mapper()->set_variation_fields( $args['_variation_fields'] );
}
$walker->walk(
function ( WalkerProgress $progress ) use ( &$status, $option_key ) {
$status = $this->update_feed_progress( $status, $progress );
update_option( $option_key, $status );
}
);
// Store the final details.
$status['state'] = self::STATE_COMPLETED;
$status['url'] = $feed->get_file_url();
$status['path'] = $feed->get_file_path();
$status['completed_at'] = time();
update_option( $option_key, $status );
// Schedule another action to delete the file after the expiry time.
// @phpstan-ignore-next-line function.notFound -- Action Scheduler.
as_schedule_single_action(
time() + self::FEED_EXPIRY,
self::FEED_DELETION_ACTION,
array(
$option_key,
$feed->get_file_path(),
),
'woo-product-feed',
true
);
} catch ( \Throwable $e ) {
wc_get_logger()->error(
'Feed generation failed',
array(
'error' => $e->getMessage(),
'option_key' => $option_key,
)
);
$status['state'] = self::STATE_FAILED;
$status['error'] = $e->getMessage();
$status['failed_at'] = time();
update_option( $option_key, $status );
}
}