Automattic\WooCommerce\Internal\Admin\Logging\FileV2

FileController::get_file_rotationspublicWC 1.0

Get File instances for a given file ID and all of its related rotations.

Method of the class: FileController{}

No Hooks.

Returns

File[]|WP_Error. An associative array where the rotation integer of the file is the key, and a "current" key for the iteration of the file that hasn't been rotated (if it exists).

Usage

$FileController = new FileController();
$FileController->get_file_rotations( $file_id );
$file_id(string) (required)
A file ID (file basename without the hash).

FileController::get_file_rotations() code WC 11.0.1

public function get_file_rotations( string $file_id ) {
	$file = $this->get_file_by_id( $file_id );

	if ( is_wp_error( $file ) ) {
		return $file;
	}

	$current = array();

	if ( is_null( $file->get_rotation() ) ) {
		$current['current'] = $file;
	} else {
		$current_file_id = File::generate_file_id( $file->get_source(), null, $this->get_filename_timestamp( $file ) );
		$result          = $this->get_file_by_id( $current_file_id );
		if ( ! is_wp_error( $result ) ) {
			$current['current'] = $result;
		}
	}

	return array_merge( $current, $this->get_rotation_siblings( $file ) );
}