Automattic\WooCommerce\Internal\CLI\Migrator\Lib
ImportSession::bump_frontloading_progress
Saves an array of [$url => ['received' => $downloaded_bytes, 'total' => $total_bytes | null]] of the currently fetched files. The list is ephemeral and changes as we stream the data. There will never be more than $concurrency_limit files in the list at any given time.
Method of the class: ImportSession{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ImportSession = new ImportSession(); $ImportSession->bump_frontloading_progress( $frontloading_progress, $events );
- $frontloading_progress(required)
- .
- $events
- .
Default:array()
ImportSession::bump_frontloading_progress() ImportSession::bump frontloading progress code WC 10.7.0
public function bump_frontloading_progress( $frontloading_progress, $events = array() ) {
update_post_meta( $this->post_id, 'frontloading_progress', $frontloading_progress );
foreach ( $events as $event ) {
$url = $event->resource_id;
$placeholder = $this->get_frontloading_stub( $url );
if ( ! $placeholder ) {
_doing_it_wrong(
__METHOD__,
'Frontloading placeholder post not found for URL: ' . $url,
'1.0.0'
);
continue;
}
update_post_meta( $placeholder->ID, 'last_error', $event->error );
$attempts = get_post_meta( $placeholder->ID, 'attempts', true );
$new_attempts = $attempts;
$new_status = $placeholder->post_status;
switch ( $event->type ) {
case self::EVENT_SUCCESS:
$new_status = self::FRONTLOAD_STATUS_SUCCEEDED;
$new_attempts = $attempts + 1;
break;
case self::EVENT_ALREADY_EXISTS:
$new_status = self::FRONTLOAD_STATUS_SUCCEEDED;
break;
case self::EVENT_FAILURE:
$new_status = self::FRONTLOAD_STATUS_ERROR;
$new_attempts = $attempts + 1;
break;
}
if ( $new_attempts !== $attempts ) {
update_post_meta( $placeholder->ID, 'attempts', $new_attempts );
}
if ( $new_status !== $placeholder->post_status ) {
wp_update_post(
array(
'ID' => $placeholder->ID,
'post_status' => $new_status,
)
);
}
}
}