Automattic\WooCommerce\Internal\Admin\Logging\FileV2

FileController::get_rotation_siblingsprivateWC 1.0

Get File instances for the existing rotations of a file.

Method of the class: FileController{}

No Hooks.

Returns

File[]. An associative array where the rotation integer of the file is the key, sorted by rotation.

Usage

// private - for code of main (parent) class only
$result = $this->get_rotation_siblings( $file ): array;
$file(File) (required)
Any iteration of a file, from which the source and creation date are taken.

FileController::get_rotation_siblings() code WC 11.0.1

private function get_rotation_siblings( File $file ): array {
	$source  = $file->get_source();
	$created = $this->get_filename_timestamp( $file );

	$rotations_pattern = sprintf(
		'.[%s]',
		implode(
			'',
			range( 0, self::MAX_FILE_ROTATIONS - 1 )
		)
	);

	$created_pattern = $created ? '-' . gmdate( 'Y-m-d', $created ) . '-' : '';

	$rotation_pattern = Settings::get_log_directory() . $source . $rotations_pattern . $created_pattern . '*.log';
	$rotation_paths   = glob( $rotation_pattern );
	$rotation_files   = $this->convert_paths_to_objects( $rotation_paths );

	$rotations = array();
	foreach ( $rotation_files as $rotation_file ) {
		if ( $rotation_file->is_readable() ) {
			$rotations[ $rotation_file->get_rotation() ] = $rotation_file;
		}
	}

	ksort( $rotations );

	return $rotations;
}