| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Analytics\User_Interface; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 6 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 7 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 8 |
|
| 9 |
/** |
| 10 |
* Handles setting a timestamp when the indexation of a specific indexation action is completed. |
| 11 |
*/ |
| 12 |
class Last_Completed_Indexation_Integration implements Integration_Interface { |
| 13 |
|
| 14 |
use No_Conditionals; |
| 15 |
|
| 16 |
/** |
| 17 |
* The options helper. |
| 18 |
* |
| 19 |
* @var Options_Helper The options helper. |
| 20 |
*/ |
| 21 |
private $options_helper; |
| 22 |
|
| 23 |
/** |
| 24 |
* The constructor. |
| 25 |
* |
| 26 |
* @param Options_Helper $options_helper The options helper. |
| 27 |
*/ |
| 28 |
public function __construct( Options_Helper $options_helper ) { |
| 29 |
$this->options_helper = $options_helper; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Registers action hook to maybe save an option. |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function register_hooks(): void { |
| 38 |
\add_action( |
| 39 |
'wpseo_indexables_unindexed_calculated', |
| 40 |
[ |
| 41 |
$this, |
| 42 |
'maybe_set_indexables_unindexed_calculated', |
| 43 |
], |
| 44 |
10, |
| 45 |
2, |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Saves a timestamp option when there are no unindexed indexables. |
| 51 |
* |
| 52 |
* @param string $indexable_name The name of the indexable that is being checked. |
| 53 |
* @param int $count The amount of missing indexables. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function maybe_set_indexables_unindexed_calculated( string $indexable_name, int $count ): void { |
| 58 |
if ( $count === 0 ) { |
| 59 |
$no_index = $this->options_helper->get( 'last_known_no_unindexed', [] ); |
| 60 |
$no_index[ $indexable_name ] = \time(); |
| 61 |
|
| 62 |
\remove_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] ); |
| 63 |
$this->options_helper->set( 'last_known_no_unindexed', $no_index ); |
| 64 |
\add_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] ); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|