PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / myyoast-client / application / myyoast-client-cleanup.php

myyoast-client-cleanup.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.0, at src/myyoast-client/application/myyoast-client-cleanup.php

81 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
4 namespace Yoast\WP\SEO\MyYoast_Client\Application;
5
6 use Exception;
7 use Yoast\WP\SEO\MyYoast_Client\Application\Ports\Client_Registration_Interface;
8 use Yoast\WP\SEO\MyYoast_Client\Application\Ports\Token_Storage_Interface;
9 use Yoast\WP\SEO\MyYoast_Client\Application\Ports\User_Token_Storage_Interface;
10 use YoastSEO_Vendor\Psr\Log\LoggerAwareInterface;
11 use YoastSEO_Vendor\Psr\Log\LoggerAwareTrait;
12 use YoastSEO_Vendor\Psr\Log\NullLogger;
13
14 /**
15 * Application service for cleaning up all MyYoast client data.
16 *
17 * Orchestrates deregistration, token deletion, and local data cleanup.
18 * Used by the uninstall integration to cleanly remove all plugin state.
19 */
20 class MyYoast_Client_Cleanup implements LoggerAwareInterface {
21 use LoggerAwareTrait;
22
23 /**
24 * The client registration port.
25 *
26 * @var Client_Registration_Interface
27 */
28 private $client_registration;
29
30 /**
31 * The site-level token storage port.
32 *
33 * @var Token_Storage_Interface
34 */
35 private $token_storage;
36
37 /**
38 * The user-level token storage port.
39 *
40 * @var User_Token_Storage_Interface
41 */
42 private $user_token_storage;
43
44 /**
45 * MyYoast_Client_Cleanup constructor.
46 *
47 * @param Client_Registration_Interface $client_registration The client registration port.
48 * @param Token_Storage_Interface $token_storage The site-level token storage port.
49 * @param User_Token_Storage_Interface $user_token_storage The user-level token storage port.
50 */
51 public function __construct(
52 Client_Registration_Interface $client_registration,
53 Token_Storage_Interface $token_storage,
54 User_Token_Storage_Interface $user_token_storage
55 ) {
56 $this->client_registration = $client_registration;
57 $this->token_storage = $token_storage;
58 $this->user_token_storage = $user_token_storage;
59 $this->logger = new NullLogger();
60 }
61
62 /**
63 * Executes the full cleanup: deregister, delete tokens, delete local data.
64 *
65 * @return void
66 */
67 public function execute(): void {
68 // Best-effort server-side deregistration.
69 try {
70 $this->client_registration->deregister();
71 }
72 catch ( Exception $e ) {
73 $this->logger->warning( 'MyYoast client deregistration failed during cleanup: {error}', [ 'error' => $e->getMessage() ] );
74 }
75
76 $this->user_token_storage->delete_all_issuers();
77 $this->token_storage->delete_all_issuers();
78 $this->client_registration->delete_local_data();
79 }
80 }
81