PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / mcp-server / Cleanup / OAuthRecordsTask.php

OAuthRecordsTask.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/mcp-server/Cleanup/OAuthRecordsTask.php

69 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Reclaim expired delegated-approval records.
4 *
5 * @package Templately
6 */
7
8 namespace Templately\Modules\McpServer\Cleanup;
9
10 use Templately\Modules\McpServer\Auth\OAuth\RecordStore;
11 use Templately\Modules\Utilities\Cleanup\CleanupTask;
12 use Templately\Modules\Utilities\Cleanup\Context;
13 use Templately\Modules\Utilities\Cleanup\RetentionKind;
14 use Templately\Modules\Utilities\Cleanup\TaskRegistry;
15 use Templately\Modules\Utilities\Cleanup\TaskResult;
16
17 /**
18 * This module used to run its OWN daily WP-Cron sweep
19 * (`templately_mcp_oauth_sweep`). It now contributes to the one shared sweep
20 * instead — two cleaners on separate cadences with no shared run claim is
21 * exactly what spec 052 exists to end.
22 *
23 * INTRINSIC retention, not age: each record carries its own `expires_at`, and
24 * expiry is enforced on read as well. Applying the shared age window here would
25 * either be ignored or would reclaim credentials that are still valid.
26 *
27 * `RecordStore::sweep()` itself is unchanged and still lives in this module —
28 * only the scheduling moved.
29 */
30 class OAuthRecordsTask implements CleanupTask {
31
32 public static function register(): void {
33 add_action(
34 TaskRegistry::COLLECT_ACTION,
35 static function ( TaskRegistry $registry ) {
36 $registry->register_classes( [ self::class ] );
37 }
38 );
39 }
40
41 public function descriptor(): array {
42 return [
43 'id' => 'mcp-oauth-records',
44 'label' => __( 'Expired agent approvals', 'templately' ),
45 'group' => 'cache',
46 'scope' => 'records',
47 'retention_kind' => RetentionKind::INTRINSIC,
48 'destructive' => true,
49 'schedulable' => true,
50 ];
51 }
52
53 public function estimate( Context $context ): TaskResult {
54 return TaskResult::empty()->add( RecordStore::count_expired(), 0 );
55 }
56
57 public function run( Context $context ): TaskResult {
58 $expired = RecordStore::count_expired();
59
60 if ( $context->is_dry_run() ) {
61 return TaskResult::empty()->add( $expired, 0 );
62 }
63
64 RecordStore::sweep();
65
66 return TaskResult::empty()->add( $expired, 0 );
67 }
68 }
69