All violations were present in v0.1.0 and hidden by continue-on-error. Now that PHPCS gates the build (P2-B), they must be fixed. - Add file-level @package doc comment to all PHP files (file doc requirement) - Add short descriptions to @var and constructor docblocks throughout - Fix @param type spacing throughout (PHPCS alignment rules) - Expand phpcs:ignore lines to include NoCaching where DirectQuery is already suppressed (uninstall.php, cost-ledger, table-manager, collector) - Suppress EscapeOutput.ExceptionNotEscaped on RuntimeException messages (exception strings are not HTML output) - Suppress error_log_error_log on the probe-runner failure log - Replace date() with gmdate() in panel (timezone-aware per WP standard) - Convert inline associative arrays to multi-line in config (WP array style) - Fix double-arrow alignment in probe-runner counts and insert arrays - Fix double-space before ?? in provider constructors - Expand phpcs:ignore for reads to include MissingUnslash - Fix $counts++ to ++$counts (prefix increment per WP standard) - Fix V1/v1 capitalisation in interface doc long description Agent-Session: pr-vision rename v0.1.1
84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
/** @package PrVision */
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* WP-Cron management for the weekly AI-visibility probe.
|
|
*
|
|
* Registers the prv_weekly_probe hook, schedules/clears the event, and
|
|
* dispatches to PRV_Probe_Runner on each tick.
|
|
*
|
|
* Who triggers: PRV_Plugin::init() (hook registration), PRV_Activator
|
|
* (schedule), PRV_Deactivator (clear).
|
|
* Dependencies: PRV_Probe_Runner.
|
|
*
|
|
* @see class-prv-probe-runner.php — Runner invoked on each cron tick.
|
|
* @see class-prv-activator.php — Calls schedule_weekly() on activation.
|
|
* @package PrVision
|
|
*/
|
|
class PRV_Cron {
|
|
|
|
/**
|
|
* Register WordPress action hooks.
|
|
*
|
|
* Side effects: Adds action for PRV_CRON_HOOK.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_hooks(): void {
|
|
add_action( PRV_CRON_HOOK, array( $this, 'handle_cron_tick' ) );
|
|
}
|
|
|
|
/**
|
|
* Callback fired by WP-Cron on the weekly schedule.
|
|
*
|
|
* Side effects: Instantiates and runs PRV_Probe_Runner.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle_cron_tick(): void {
|
|
$runner = new PRV_Probe_Runner();
|
|
$runner->run();
|
|
}
|
|
|
|
/**
|
|
* Schedule the weekly cron event if not already scheduled.
|
|
*
|
|
* Safe to call on re-activation — no-op when already scheduled.
|
|
*
|
|
* Side effects: Adds a WP-Cron event.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function schedule_weekly(): void {
|
|
if ( ! wp_next_scheduled( PRV_CRON_HOOK ) ) {
|
|
wp_schedule_event( time(), 'weekly', PRV_CRON_HOOK );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the weekly cron schedule.
|
|
*
|
|
* Called on deactivation. Does not purge data.
|
|
*
|
|
* Side effects: Removes the WP-Cron event.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function clear_schedule(): void {
|
|
$timestamp = wp_next_scheduled( PRV_CRON_HOOK );
|
|
if ( false !== $timestamp ) {
|
|
wp_unschedule_event( $timestamp, PRV_CRON_HOOK );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check whether the weekly event is currently scheduled.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function is_scheduled(): bool {
|
|
return false !== wp_next_scheduled( PRV_CRON_HOOK );
|
|
}
|
|
}
|