WC_Log_Handler_File::increment_log_infix()protectedWC 1.0

Increment a log file suffix.

Method of the class: WC_Log_Handler_File{}

No Hooks.

Return

true|false. True if increment was successful, otherwise false.

Usage

// protected - for code of main (parent) or child class
$result = $this->increment_log_infix( $handle, $number );
$handle(string) (required)
Log handle.
$number(null|int)
Log suffix number to be incremented.
Default: null

WC_Log_Handler_File::increment_log_infix() code WC 9.3.3

protected function increment_log_infix( $handle, $number = null ) {
	if ( null === $number ) {
		$suffix      = '';
		$next_suffix = '.0';
	} else {
		$suffix      = '.' . $number;
		$next_suffix = '.' . ( $number + 1 );
	}

	$rename_from = self::get_log_file_path( "{$handle}{$suffix}" );
	$rename_to   = self::get_log_file_path( "{$handle}{$next_suffix}" );

	if ( $this->is_open( $rename_from ) ) {
		$this->close( $rename_from );
	}

	if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable
		return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename
	} else {
		return false;
	}

}