WC_Log_Handler_File::increment_log_infix( string $handle, null|int $number = null )

Increment a log file suffix.


Description Description


Parameters Parameters

$handle

(Required) Log handle.

$number

(Optional) Log suffix number to be incremented.

Default value: null


Top ↑

Return Return

(bool) True if increment was successful, otherwise false.


Top ↑

Source Source

File: includes/log-handlers/class-wc-log-handler-file.php

	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;
		}

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.