| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | namespace WP_Defender\Component\Logger; |
| 9 | 9 | |
| 10 | 10 | use GlobIterator; |
| 11 | 11 | use WP_Defender\Traits\IO; |
| 12 | +use WP_Defender\Component\Network_Cron_Manager; | |
| 12 | 13 | |
| 13 | 14 | /** |
| 14 | 15 | * Deals rotation log file naming & purging old logs. |
| 15 | 16 | */ |
| @@ -46,9 +47,9 @@ | ||
| 46 | 47 | $file_name = $iterator->getBasename(); |
| 47 | 48 | } else { |
| 48 | 49 | $file_name = uniqid( $file_name . '-' ); |
| 49 | 50 | |
| 50 | - if ( ! empty( $file_parts['extension'] ) ) { | |
| 51 | + if ( isset( $file_parts['extension'] ) && '' !== $file_parts['extension'] ) { | |
| 51 | 52 | $file_name .= '.' . $file_parts['extension']; |
| 52 | 53 | } |
| 53 | 54 | } |
| 54 | 55 | |
| @@ -67,9 +68,9 @@ | ||
| 67 | 68 | $count = self::ROTATION_FREQUENCY, |
| 68 | 69 | $unit = self::ROTATION_UNIT |
| 69 | 70 | ) { |
| 70 | 71 | $threshold_timestamp = strtotime( '-' . $count . $unit ); |
| 71 | - if ( empty( $directory_path ) ) { | |
| 72 | + if ( '' === $directory_path ) { | |
| 72 | 73 | $directory_path = $this->get_tmp_path(); |
| 73 | 74 | } |
| 74 | 75 | $iterator = new GlobIterator( $directory_path . '/*.log' ); |
| 75 | 76 | |
| @@ -88,11 +89,15 @@ | ||
| 88 | 89 | */ |
| 89 | 90 | public function init() { |
| 90 | 91 | /** |
| 91 | 92 | * Delete old logs rotationally. |
| 93 | + * | |
| 94 | + * @var Network_Cron_Manager $network_cron_manager | |
| 92 | 95 | */ |
| 93 | - if ( ! wp_next_scheduled( 'wpdef_log_rotational_delete' ) ) { | |
| 94 | - wp_schedule_event( time(), 'daily', 'wpdef_log_rotational_delete' ); | |
| 95 | - } | |
| 96 | - add_action( 'wpdef_log_rotational_delete', array( $this, 'purge_old_log' ) ); | |
| 96 | + $network_cron_manager = wd_di()->get( Network_Cron_Manager::class ); | |
| 97 | + $network_cron_manager->register_callback( | |
| 98 | + 'wpdef_log_rotational_delete', | |
| 99 | + array( $this, 'purge_old_log' ), | |
| 100 | + DAY_IN_SECONDS | |
| 101 | + ); | |
| 97 | 102 | } |
| 98 | 103 | } |