<?php
/**
 * Scheduled local maintenance.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Infrastructure\WordPress;

use LocalGuardScanner\Application\Maintenance\RetentionCleaner;

/**
 * Runs a single bounded cleanup batch each day.
 */
final class MaintenanceRunner {
	/** @var RetentionCleaner */
	private $cleaner;

	public function __construct( RetentionCleaner $cleaner ) {
		$this->cleaner = $cleaner;
	}

	/** @return void */
	public function register() {
		add_action( CronScheduler::CLEANUP_HOOK, array( $this, 'run' ) );
	}

	/** @return void */
	public function run() {
		$this->cleaner->run( gmdate( 'Y-m-d H:i:s', time() - 30 * DAY_IN_SECONDS ) );
	}
}
