From 10b894974cd2e946b1f7c7d099c5c82dc7f520bf Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 30 May 2023 15:58:36 +0200 Subject: [PATCH 01/41] Sets a timestamp whenever the plugin is deactivated. --- .../mark-deactivation-integration.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/indexables/user-interface/mark-deactivation-integration.php diff --git a/src/indexables/user-interface/mark-deactivation-integration.php b/src/indexables/user-interface/mark-deactivation-integration.php new file mode 100644 index 00000000000..b7d280eaf6c --- /dev/null +++ b/src/indexables/user-interface/mark-deactivation-integration.php @@ -0,0 +1,49 @@ +options_helper = $options_helper; + } + + /** + * Registers a deactivation action. + */ + public function register_hooks() { + \add_action( 'wpseo_deactivate', [ $this, 'register_deactivation' ] ); + } + + /** + * Sets a timestamp for the moment the plugin was deactivated. + * + * @return void + */ + public function register_deactivation(): void { + $this->options_helper->set( 'plugin_deactivated_at', time() ); + } +} From d0cfb1fd6fafcd570ab56be2b8f69dd6f85440e9 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 31 May 2023 08:23:51 +0200 Subject: [PATCH 02/41] Start implementing cron system. --- .../application/cron-verfication-gate.php | 41 +++++++++++++ .../verification-cron-schedule-handler.php | 31 ++++++++++ ...schedule-verification-cron-integration.php | 38 ++++++++++++ ...verification-cron-callback-integration.php | 59 +++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 src/indexables/application/cron-verfication-gate.php create mode 100644 src/indexables/application/verification-cron-schedule-handler.php create mode 100644 src/indexables/user-interface/schedule-verification-cron-integration.php create mode 100644 src/indexables/user-interface/verification-cron-callback-integration.php diff --git a/src/indexables/application/cron-verfication-gate.php b/src/indexables/application/cron-verfication-gate.php new file mode 100644 index 00000000000..9cb32a9b7b3 --- /dev/null +++ b/src/indexables/application/cron-verfication-gate.php @@ -0,0 +1,41 @@ +indexable_helper = $indexable_helper; + } + + /** + * Determine whether cron verification of indexables should be performed. + * + * @return bool Should cron verification be performed. + */ + public function should_verify_on_cron() { + if ( ! $this->indexable_helper->should_index_indexables() ) { + return false; + } + + // The filter supersedes everything when preventing cron verification. + if ( \apply_filters( 'Yoast\WP\SEO\enable_cron_verification', true ) !== true ) { + return false; + } + + return true; + } +} diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php new file mode 100644 index 00000000000..227cfd57563 --- /dev/null +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -0,0 +1,31 @@ +cron_verification_gate = $cron_verification_gate; + } + + + public function schedule_indexable_verification(): void { + if ( ! \wp_next_scheduled( 'wpseo_indexable_verify_post_indexables' ) && $this->cron_verification_gate->should_verify_on_cron() ) { + \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', 'wpseo_indexable_verify_post_indexables' ); + } + + if ( ! \wp_next_scheduled( 'wpseo_indexable_verify_non_timestamped_indexables' ) && $this->cron_verification_gate->should_verify_on_cron() ) { + \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', 'wpseo_indexable_verify_non_timestamped_indexables' ); + } + } + + +} diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php new file mode 100644 index 00000000000..ed2a9b952d3 --- /dev/null +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -0,0 +1,38 @@ +options_helper = $options_helper; + } + + + /** + * @inheritDoc + */ + public function register_hooks() { + if ( $this->options_helper->get( 'first_time_install', false ) !== false ) { + \add_action( 'wpseo_activate', [ Verification_Cron_Schedule_Handler::class, 'schedule_indexable_verification' ] ); + } + } +} diff --git a/src/indexables/user-interface/verification-cron-callback-integration.php b/src/indexables/user-interface/verification-cron-callback-integration.php new file mode 100644 index 00000000000..492607ebbd8 --- /dev/null +++ b/src/indexables/user-interface/verification-cron-callback-integration.php @@ -0,0 +1,59 @@ +cron_verification_gate = $cron_verification_gate; + } + /** + * @inheritDoc + */ + public function register_hooks() { + \add_action( 'wpseo_indexable_verify_post_indexables', [ $this, 'start_verify_posts' ] ); + \add_action( 'wpseo_indexable_verify_non_timestamped_indexables', [ $this, 'start_verify_non_timestamped_indexables' ] ); + } + + public function start_verify_posts( ) { + if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { + $scheduled = \wp_next_scheduled( 'wpseo_indexable_verify_post_indexables' ); + if ( $scheduled ) { + \wp_unschedule_event( $scheduled, 'wpseo_indexable_verify_post_indexables' ); + } + return; + } + + + + + + + } + public function start_verify_non_timestamped_indexables( ) { + if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { + $scheduled = \wp_next_scheduled( 'wpseo_indexable_verify_non_timestamped_indexables' ); + if ( $scheduled ) { + \wp_unschedule_event( $scheduled, 'wpseo_indexable_verify_non_timestamped_indexables' ); + } + return; + } + + + + } + + +} From 4caadb2d6f4e736c1ea8aaa489cec343dd367f38 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Fri, 2 Jun 2023 16:03:52 +0200 Subject: [PATCH 03/41] Start implementing handling of the crons --- ...d_post_indexables_repository_interface.php | 27 +++++++ .../verification-cron-batch-handler.php | 26 ++++++ .../verification-cron-schedule-handler.php | 24 ++++-- ...erify-non-timestamp-indexables-command.php | 13 +++ ...verify-post-indexables-command-handler.php | 63 +++++++++++++++ .../verify-post-indexables-command.php | 12 +++ .../domain/abstract-indexables-command.php | 35 ++++++++ .../no-outdated-posts-found-exception.php | 19 +++++ src/indexables/domain/last-batch-count.php | 34 ++++++++ .../domain/outdated-post-indexables-list.php | 49 ++++++++++++ .../domain/plugin-deactivated-timestamp.php | 22 +++++ .../Outdated_Post_Indexables_Repository.php | 26 ++++++ .../mark-deactivation-integration.php | 4 +- ...schedule-verification-cron-integration.php | 5 +- ...verification-cron-callback-integration.php | 80 +++++++++++++------ 15 files changed, 406 insertions(+), 33 deletions(-) create mode 100644 src/indexables/application/ports/outdated_post_indexables_repository_interface.php create mode 100644 src/indexables/application/verification-cron-batch-handler.php create mode 100644 src/indexables/application/verify-non-timestamp-indexables-command.php create mode 100644 src/indexables/application/verify-post-indexables-command-handler.php create mode 100644 src/indexables/application/verify-post-indexables-command.php create mode 100644 src/indexables/domain/abstract-indexables-command.php create mode 100644 src/indexables/domain/exceptions/no-outdated-posts-found-exception.php create mode 100644 src/indexables/domain/last-batch-count.php create mode 100644 src/indexables/domain/outdated-post-indexables-list.php create mode 100644 src/indexables/domain/plugin-deactivated-timestamp.php create mode 100644 src/indexables/infrastructure/Outdated_Post_Indexables_Repository.php diff --git a/src/indexables/application/ports/outdated_post_indexables_repository_interface.php b/src/indexables/application/ports/outdated_post_indexables_repository_interface.php new file mode 100644 index 00000000000..06973cb5450 --- /dev/null +++ b/src/indexables/application/ports/outdated_post_indexables_repository_interface.php @@ -0,0 +1,27 @@ +options_helper = $options_helper; + } + + public function get_current_post_indexables_batch( ):int { + return $this->options_helper->get( 'cron_verify_post_indexables_last_batch', 0 ); + } + + public function set_current_post_indexables_batch( int $batch_count ) { + $this->options_helper->set('cron_verify_post_indexables_last_batch',$batch_count); + } +} diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 227cfd57563..d3d53d27550 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -4,6 +4,9 @@ class Verification_Cron_Schedule_Handler { + public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables'; + public const INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME = 'wpseo_indexable_verify_non_timestamped_indexables'; + /** * @var Cron_Verification_Gate */ @@ -16,16 +19,27 @@ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { $this->cron_verification_gate = $cron_verification_gate; } - public function schedule_indexable_verification(): void { - if ( ! \wp_next_scheduled( 'wpseo_indexable_verify_post_indexables' ) && $this->cron_verification_gate->should_verify_on_cron() ) { - \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', 'wpseo_indexable_verify_post_indexables' ); + if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { + \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); } - if ( ! \wp_next_scheduled( 'wpseo_indexable_verify_non_timestamped_indexables' ) && $this->cron_verification_gate->should_verify_on_cron() ) { - \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', 'wpseo_indexable_verify_non_timestamped_indexables' ); + if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { + \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); } } + public function unschedule_verify_post_indexables_cron() { + $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + if ( $scheduled ) { + \wp_unschedule_event( $scheduled, self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + } + } + public function unschedule_verify_non_timestamped_indexables_cron() { + $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + if ( $scheduled ) { + \wp_unschedule_event( $scheduled, self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + } + } } diff --git a/src/indexables/application/verify-non-timestamp-indexables-command.php b/src/indexables/application/verify-non-timestamp-indexables-command.php new file mode 100644 index 00000000000..ad872014aee --- /dev/null +++ b/src/indexables/application/verify-non-timestamp-indexables-command.php @@ -0,0 +1,13 @@ +last_batch_count; + } +} diff --git a/src/indexables/application/verify-post-indexables-command-handler.php b/src/indexables/application/verify-post-indexables-command-handler.php new file mode 100644 index 00000000000..057dc6db6e7 --- /dev/null +++ b/src/indexables/application/verify-post-indexables-command-handler.php @@ -0,0 +1,63 @@ +outdated_post_indexables_repository = $outdated_post_indexables_repository; + $this->cron_schedule_handler = $cron_schedule_handler; + $this->indexable_post_builder = $indexable_post_builder; + } + + /** + * @param Verify_Post_Indexables_Command $verify_post_indexables_command + */ + public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ) { + + // Need to do something with this. + $batch_size = 10; + + + try { + $outdated_post_indexables_list = $this->outdated_post_indexables_repository->get_outdated_post_indexables( $verify_post_indexables_command->get_last_batch_count(), $verify_post_indexables_command->get_plugin_deactivated_at() ); + } catch ( No_Outdated_Posts_Found_Exception $exception ) { + $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); + + return; + } + + foreach ( $outdated_post_indexables_list as $post_indexable ) { + $this->indexable_post_builder->build( $post_indexable->object_id, $post_indexable ); + } + + if ( $outdated_post_indexables_list->count() < $batch_size ) { + + } + } +} diff --git a/src/indexables/application/verify-post-indexables-command.php b/src/indexables/application/verify-post-indexables-command.php new file mode 100644 index 00000000000..3b5ad4676f7 --- /dev/null +++ b/src/indexables/application/verify-post-indexables-command.php @@ -0,0 +1,12 @@ +last_batch_count = new Last_Batch_Count( $last_batch ); + $this->plugin_deactivated_at = new Plugin_Deactivated_Timestamp( $plugin_deactivated_at ); + } + + /** + * @return Last_Batch_Count + */ + public function get_last_batch_count(): Last_Batch_Count { + return $this->last_batch_count; + } + + /** + * @return Plugin_Deactivated_Timestamp + */ + public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { + return $this->plugin_deactivated_at; + } +} diff --git a/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php new file mode 100644 index 00000000000..004a71eaa2f --- /dev/null +++ b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php @@ -0,0 +1,19 @@ +last_batch = $last_batch; + } + + /** + * Returns the last Batch count. + * + * @return int + */ + public function get_last_batch(): int { + return $this->last_batch; + } +} diff --git a/src/indexables/domain/outdated-post-indexables-list.php b/src/indexables/domain/outdated-post-indexables-list.php new file mode 100644 index 00000000000..344f12c66be --- /dev/null +++ b/src/indexables/domain/outdated-post-indexables-list.php @@ -0,0 +1,49 @@ + $post_indexables_list + */ + private $post_indexables_list; + + private $position = 0; + + public function __construct() { + $this->post_indexables_list = []; + } + + public function add_post_indexable( Indexable $post ) { + $this->post_indexables_list[] = $post; + } + + public function rewind(): void { + $this->position = 0; + } + + public function current(): Indexable { + + return $this->post_indexables_list[ $this->position ]; + } + + public function key(): int { + return $this->position; + } + + public function next(): void { + ++$this->position; + } + + public function valid(): bool { + return isset( $this->post_indexables_list[ $this->position ] ); + } + + public function count():int { + return \count( $this->post_indexables_list ); + } +} diff --git a/src/indexables/domain/plugin-deactivated-timestamp.php b/src/indexables/domain/plugin-deactivated-timestamp.php new file mode 100644 index 00000000000..908c316ab92 --- /dev/null +++ b/src/indexables/domain/plugin-deactivated-timestamp.php @@ -0,0 +1,22 @@ +timestamp = $timestamp; + } +} diff --git a/src/indexables/infrastructure/Outdated_Post_Indexables_Repository.php b/src/indexables/infrastructure/Outdated_Post_Indexables_Repository.php new file mode 100644 index 00000000000..07ec0289928 --- /dev/null +++ b/src/indexables/infrastructure/Outdated_Post_Indexables_Repository.php @@ -0,0 +1,26 @@ +options_helper->set( 'plugin_deactivated_at', time() ); + $this->options_helper->set( self::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); } } diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index ed2a9b952d3..4832ce6b92b 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -15,18 +15,17 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { use Admin_Conditional_Trait; - private $options_helper; /** * The constructor. + * * @param Options_Helper $options_helper The options helper. */ - public function __construct(Options_Helper $options_helper) { + public function __construct( Options_Helper $options_helper ) { $this->options_helper = $options_helper; } - /** * @inheritDoc */ diff --git a/src/indexables/user-interface/verification-cron-callback-integration.php b/src/indexables/user-interface/verification-cron-callback-integration.php index 492607ebbd8..f3b58917d93 100644 --- a/src/indexables/user-interface/verification-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-cron-callback-integration.php @@ -2,11 +2,31 @@ namespace Yoast\WP\SEO\Indexables\User_Interface; +use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; +use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; +use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; +use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; +use Yoast\WP\Test_Helper\Option; class Verification_Cron_Callback_Integration implements Integration_Interface { + use Admin_Conditional_Trait; + + /** + * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + */ + protected $cron_schedule_handler; + + /** + * @var \Yoast\WP\SEO\Helpers\Options_Helper + */ + protected $options_helper; + /** + * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + */ + protected $cron_batch_handler; /** * @var Cron_Verification_Gate @@ -14,46 +34,58 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { private $cron_verification_gate; /** - * @param \Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate $cron_verification_gate + * @param Cron_Verification_Gate $cron_verification_gate + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler */ - public function __construct( Cron_Verification_Gate $cron_verification_gate ) { + public function __construct( + Cron_Verification_Gate $cron_verification_gate, + Verification_Cron_Schedule_Handler $cron_schedule_handler, + Options_Helper $options_helper, + Verification_Cron_Batch_Handler $cron_batch_handler + ) { $this->cron_verification_gate = $cron_verification_gate; + $this->cron_schedule_handler = $cron_schedule_handler; + $this->options_helper = $options_helper; + $this->cron_batch_handler = $cron_batch_handler; } + /** * @inheritDoc */ public function register_hooks() { - \add_action( 'wpseo_indexable_verify_post_indexables', [ $this, 'start_verify_posts' ] ); - \add_action( 'wpseo_indexable_verify_non_timestamped_indexables', [ $this, 'start_verify_non_timestamped_indexables' ] ); + \add_action( + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, + [ + $this, + 'start_verify_posts', + ] + ); + \add_action( + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, + [ + $this, + 'start_verify_non_timestamped_indexables', + ] + ); } - public function start_verify_posts( ) { + public function start_verify_posts(): void { if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { - $scheduled = \wp_next_scheduled( 'wpseo_indexable_verify_post_indexables' ); - if ( $scheduled ) { - \wp_unschedule_event( $scheduled, 'wpseo_indexable_verify_post_indexables' ); - } + $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); + return; } - - - - - - + $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); + $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); } - public function start_verify_non_timestamped_indexables( ) { + + public function start_verify_non_timestamped_indexables() { if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { - $scheduled = \wp_next_scheduled( 'wpseo_indexable_verify_non_timestamped_indexables' ); - if ( $scheduled ) { - \wp_unschedule_event( $scheduled, 'wpseo_indexable_verify_non_timestamped_indexables' ); - } + $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + return; } - - + // Start cron process } - - } From c6683bcba7e4122d039b75b94fd24160c9e40457 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 5 Jun 2023 14:02:48 +0200 Subject: [PATCH 04/41] Start setup of non timestamp handling. --- ...on-timestamp-indexables-command-hander.php | 39 +++++++++ ...verify-post-indexables-command-handler.php | 11 +-- ...on-timestamped-objects-found-exception.php | 17 ++++ ...o-timestamp-cron-callback-integration.php} | 28 ++---- ...cation-posts-cron-callback-integration.php | 87 +++++++++++++++++++ 5 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 src/indexables/application/verify-non-timestamp-indexables-command-hander.php create mode 100644 src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php rename src/indexables/user-interface/{verification-cron-callback-integration.php => verification-no-timestamp-cron-callback-integration.php} (67%) create mode 100644 src/indexables/user-interface/verification-posts-cron-callback-integration.php diff --git a/src/indexables/application/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/verify-non-timestamp-indexables-command-hander.php new file mode 100644 index 00000000000..dc3697a7471 --- /dev/null +++ b/src/indexables/application/verify-non-timestamp-indexables-command-hander.php @@ -0,0 +1,39 @@ +cron_schedule_handler = $cron_schedule_handler; + } + + /** + * @param Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command + * + * @return void + */ + public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { + // Need to do something with this. + $batch_size = 10; + + try { + // Bla + } catch ( No_Non_Timestamped_Objects_Found_Exception $exception ) { + $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + + return; + } + + } +} diff --git a/src/indexables/application/verify-post-indexables-command-handler.php b/src/indexables/application/verify-post-indexables-command-handler.php index 057dc6db6e7..9502fd8d7f9 100644 --- a/src/indexables/application/verify-post-indexables-command-handler.php +++ b/src/indexables/application/verify-post-indexables-command-handler.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Indexables\Application; use Yoast\WP\SEO\Builders\Indexable_Post_Builder; -use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; @@ -17,7 +16,7 @@ class Verify_Post_Indexables_Command_Handler { /** * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler */ - protected $cron_schedule_handler; + private $cron_schedule_handler; /** * @var \Yoast\WP\SEO\Builders\Indexable_Post_Builder @@ -27,7 +26,7 @@ class Verify_Post_Indexables_Command_Handler { public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, Verification_Cron_Schedule_Handler $cron_schedule_handler, - Indexable_Post_Builder $indexable_post_builder, + Indexable_Post_Builder $indexable_post_builder ) { $this->outdated_post_indexables_repository = $outdated_post_indexables_repository; @@ -38,12 +37,10 @@ public function __construct( /** * @param Verify_Post_Indexables_Command $verify_post_indexables_command */ - public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ) { - + public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ): void { // Need to do something with this. $batch_size = 10; - try { $outdated_post_indexables_list = $this->outdated_post_indexables_repository->get_outdated_post_indexables( $verify_post_indexables_command->get_last_batch_count(), $verify_post_indexables_command->get_plugin_deactivated_at() ); } catch ( No_Outdated_Posts_Found_Exception $exception ) { @@ -57,7 +54,7 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c } if ( $outdated_post_indexables_list->count() < $batch_size ) { - + $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); } } } diff --git a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php new file mode 100644 index 00000000000..93d27afe181 --- /dev/null +++ b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php @@ -0,0 +1,17 @@ +cron_verification_gate = $cron_verification_gate; $this->cron_schedule_handler = $cron_schedule_handler; $this->options_helper = $options_helper; - $this->cron_batch_handler = $cron_batch_handler; + $this->cron_batch_handler = $cron_batch_handler; } /** * @inheritDoc */ public function register_hooks() { - \add_action( - Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, - [ - $this, - 'start_verify_posts', - ] - ); \add_action( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, [ @@ -69,16 +63,6 @@ public function register_hooks() { ); } - public function start_verify_posts(): void { - if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { - $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); - - return; - } - $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); - $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); - } - public function start_verify_non_timestamped_indexables() { if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php new file mode 100644 index 00000000000..f2c9228b8b2 --- /dev/null +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -0,0 +1,87 @@ +cron_verification_gate = $cron_verification_gate; + $this->cron_schedule_handler = $cron_schedule_handler; + $this->options_helper = $options_helper; + $this->cron_batch_handler = $cron_batch_handler; + $this->verify_post_indexables_command_handler = $verify_post_indexables_command_handler; + } + + /** + * @inheritDoc + */ + public function register_hooks() { + \add_action( + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, + [ + $this, + 'start_verify_posts', + ] + ); + } + + public function start_verify_posts(): void { + if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { + $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); + + return; + } + $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); + $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); + + $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $last_batch, $plugin_deactivated ) ); + } + +} From 2120c435bcd683002644a10a5d250073fd319468 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 8 Jun 2023 09:29:40 +0200 Subject: [PATCH 05/41] Progress on creating cron system. --- .../verify-indexable-action-factory.php | 58 +++++++++++++++++++ ...on-timestamp-indexables-command-hander.php | 26 +++++++-- ...erify-non-timestamp-indexables-command.php | 28 ++++++++- .../domain/abstract-indexables-command.php | 4 ++ ...fy-indexables-action-factory-interface.php | 14 +++++ .../verify-indexables-action-interface.php | 18 ++++++ .../domain/current-verification-action.php | 25 ++++++++ .../no-verification-action-left-exception.php | 30 ++++++++++ .../verify-action-not-found-exception.php | 7 +++ .../actions/verify-term-indexables-action.php | 16 +++++ ...> outdated-post-indexables-repository.php} | 0 11 files changed, 217 insertions(+), 9 deletions(-) create mode 100644 src/indexables/application/actions/verify-indexable-action-factory.php create mode 100644 src/indexables/domain/actions/verify-indexables-action-factory-interface.php create mode 100644 src/indexables/domain/actions/verify-indexables-action-interface.php create mode 100644 src/indexables/domain/current-verification-action.php create mode 100644 src/indexables/domain/exceptions/no-verification-action-left-exception.php create mode 100644 src/indexables/domain/exceptions/verify-action-not-found-exception.php create mode 100644 src/indexables/infrastructure/actions/verify-term-indexables-action.php rename src/indexables/infrastructure/{Outdated_Post_Indexables_Repository.php => outdated-post-indexables-repository.php} (100%) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php new file mode 100644 index 00000000000..0ee5515afc9 --- /dev/null +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -0,0 +1,58 @@ +get_action() ) { + case "terms": + return new Verify_Term_Indexables_Action(); + case"general": + break; + default: + throw new Verify_Action_Not_Found_Exception(); + } + } + + /** + * @param Current_Verification_Action $current_verification_action_object + * + * @throws No_Verification_Action_Left_Exception + * @return string + */ + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ): string { + $current_verification_action = $current_verification_action_object->get_action(); + + if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING ) ) { + $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING ); + if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) { + return self::VERIFICATION_MAPPING[ ++$key ]; + } + + throw No_Verification_Action_Left_Exception::because_out_of_bounds(); + } + + throw No_Verification_Action_Left_Exception::because_unidentified_action_given( $current_verification_action ); + } + + +} diff --git a/src/indexables/application/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/verify-non-timestamp-indexables-command-hander.php index dc3697a7471..f661fc54c1e 100644 --- a/src/indexables/application/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/verify-non-timestamp-indexables-command-hander.php @@ -2,9 +2,15 @@ namespace Yoast\WP\SEO\Indexables\Application; +use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexable_Action_Factory_Interface; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Non_Timestamped_Objects_Found_Exception; +use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; class Verify_Non_Timestamp_Indexables_Command_Handler { + /** + * @var Verify_Indexable_Action_Factory_Interface + */ + protected $verify_indexable_action_factory; /** * @var Verification_Cron_Schedule_Handler @@ -13,9 +19,11 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { public function __construct( - Verification_Cron_Schedule_Handler $cron_schedule_handler + Verification_Cron_Schedule_Handler $cron_schedule_handler, + Verify_Indexable_Action_Factory_Interface $verify_indexable_action_factory ) { $this->cron_schedule_handler = $cron_schedule_handler; + $this->verify_indexable_action_factory = $verify_indexable_action_factory; } /** @@ -27,13 +35,19 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time // Need to do something with this. $batch_size = 10; - try { - // Bla - } catch ( No_Non_Timestamped_Objects_Found_Exception $exception ) { - $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + $verification_action = $this->verify_indexable_action_factory->get($verify_non_timestamp_indexables_command->get_current_action()); + $has_more_to_index = $verification_action->re_build_indexables($verify_non_timestamp_indexables_command->get_last_batch_count()); + // for each fix + if($has_more_to_index){ + //option + batch size return; } - + try { + $next_action = $this->verify_indexable_action_factory->determine_next_verify_action($verify_non_timestamp_indexables_command->get_current_action()); + // update option. + }catch (No_Verification_Action_Left_Exception $exception){ + $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + } } } diff --git a/src/indexables/application/verify-non-timestamp-indexables-command.php b/src/indexables/application/verify-non-timestamp-indexables-command.php index ad872014aee..7d4f89e6a32 100644 --- a/src/indexables/application/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/verify-non-timestamp-indexables-command.php @@ -3,11 +3,33 @@ namespace Yoast\WP\SEO\Indexables\Application; use Yoast\WP\SEO\Indexables\Domain\Abstract_Indexables_Command; -use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; +use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Command { - public function get_last_batch(): Last_Batch_Count { - return $this->last_batch_count; + /** + * @var Current_Verification_Action $current_action The current verification action in progress. + */ + private $current_action; + + + /** + * @param int $last_batch The last batch count. + * @param string $plugin_deactivated_at The plugin deactivated at timestamp. + * @param string $current_action The current verification action. + */ + public function __construct( int $last_batch, string $plugin_deactivated_at, string $current_action ) { + $this->current_action = new Current_Verification_Action( $current_action ); + parent::__construct( $last_batch, $plugin_deactivated_at ); } + + + /** + * @return Current_Verification_Action + */ + public function get_current_action(): Current_Verification_Action { + return $this->current_action; + } + + } diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index f39abff7040..6e33d9d3870 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -14,6 +14,10 @@ abstract class Abstract_Indexables_Command { */ protected $plugin_deactivated_at; + /** + * @param int $last_batch The last batch count. + * @param string $plugin_deactivated_at The plugin deactivated at timestamp. + */ public function __construct( int $last_batch, string $plugin_deactivated_at ) { $this->last_batch_count = new Last_Batch_Count( $last_batch ); $this->plugin_deactivated_at = new Plugin_Deactivated_Timestamp( $plugin_deactivated_at ); diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php new file mode 100644 index 00000000000..00fac59737d --- /dev/null +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -0,0 +1,14 @@ +action = $action; + } + + /** + * @return string + */ + public function get_action(): string { + return $this->action; + } +} diff --git a/src/indexables/domain/exceptions/no-verification-action-left-exception.php b/src/indexables/domain/exceptions/no-verification-action-left-exception.php new file mode 100644 index 00000000000..5be6647dc58 --- /dev/null +++ b/src/indexables/domain/exceptions/no-verification-action-left-exception.php @@ -0,0 +1,30 @@ + Date: Thu, 8 Jun 2023 12:08:05 +0200 Subject: [PATCH 06/41] Progress on indexing. --- ...=> outdated-post-indexables-repository-interface.php} | 0 .../actions/verify-indexables-action-interface.php | 9 ++++++++- 2 files changed, 8 insertions(+), 1 deletion(-) rename src/indexables/application/ports/{outdated_post_indexables_repository_interface.php => outdated-post-indexables-repository-interface.php} (100%) diff --git a/src/indexables/application/ports/outdated_post_indexables_repository_interface.php b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php similarity index 100% rename from src/indexables/application/ports/outdated_post_indexables_repository_interface.php rename to src/indexables/application/ports/outdated-post-indexables-repository-interface.php diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 0001d9d145a..75c1c70a401 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -7,7 +7,6 @@ interface Verify_Indexables_Action_Interface { - /** * @param Last_Batch_Count $last_batch_count * @@ -15,4 +14,12 @@ interface Verify_Indexables_Action_Interface { */ public function re_build_indexables( Last_Batch_Count $last_batch_count):bool; + + /** + * @param \wpdb $wpdb + * + * @return mixed + * @required + */ + public function setWpdb( \wpdb $wpdb); } From 6fa5a941a0bce58b356f0bd10c4f0475a909d987 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 12 Jun 2023 08:53:37 +0200 Subject: [PATCH 07/41] Implement term verification. --- config/dependency-injection/loader-pass.php | 3 + .../verify-indexable-action-factory.php | 15 ++-- ...on-timestamp-indexables-command-hander.php | 66 ++++++++++++++++++ ...erify-non-timestamp-indexables-command.php | 20 ++++-- ...verify-post-indexables-command-handler.php | 4 +- .../verify-post-indexables-command.php | 3 +- .../next-verification-action-handler.php | 27 ++++++++ .../verification-cron-batch-handler.php | 18 +++-- ...on-timestamp-indexables-command-hander.php | 53 -------------- ...fy-indexables-action-factory-interface.php | 4 +- .../verify-indexables-action-interface.php | 7 +- src/indexables/domain/batch-size.php | 29 ++++++++ .../no-verification-action-left-exception.php | 2 +- .../actions/verify-term-indexables-action.php | 69 ++++++++++++++++++- ...no-timestamp-cron-callback-integration.php | 45 +++++++++--- ...cation-posts-cron-callback-integration.php | 13 ++-- src/repositories/indexable-repository.php | 29 +++++++- 17 files changed, 309 insertions(+), 98 deletions(-) create mode 100644 src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php rename src/indexables/application/{ => commands}/verify-non-timestamp-indexables-command.php (58%) rename src/indexables/application/{ => commands}/verify-post-indexables-command-handler.php (93%) rename src/indexables/application/{ => commands}/verify-post-indexables-command.php (78%) create mode 100644 src/indexables/application/next-verification-action-handler.php delete mode 100644 src/indexables/application/verify-non-timestamp-indexables-command-hander.php create mode 100644 src/indexables/domain/batch-size.php diff --git a/config/dependency-injection/loader-pass.php b/config/dependency-injection/loader-pass.php index 526a430414e..e0598d5f7ca 100644 --- a/config/dependency-injection/loader-pass.php +++ b/config/dependency-injection/loader-pass.php @@ -60,6 +60,9 @@ private function process_definition( Definition $definition, Definition $loader_ ) { $definition->setPublic( false ); } + if ( \strpos( $path, 'src' . \DIRECTORY_SEPARATOR . 'indexables' ) ) { + $definition->setPublic( false ); + } } catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch // Catch all for non-existing classes. } diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 0ee5515afc9..6ce1362e701 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -24,9 +24,9 @@ class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory */ public function get( Current_Verification_Action $verification_action ): Verify_Indexables_Action_Interface { switch ( $verification_action->get_action() ) { - case "terms": + case 'terms': return new Verify_Term_Indexables_Action(); - case"general": + case 'general': break; default: throw new Verify_Action_Not_Found_Exception(); @@ -36,16 +36,17 @@ public function get( Current_Verification_Action $verification_action ): Verify_ /** * @param Current_Verification_Action $current_verification_action_object * - * @throws No_Verification_Action_Left_Exception - * @return string + * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @return \Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action */ - public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ): string { + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object + ): Current_Verification_Action { $current_verification_action = $current_verification_action_object->get_action(); if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING ) ) { $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING ); if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) { - return self::VERIFICATION_MAPPING[ ++$key ]; + return new Current_Verification_Action( self::VERIFICATION_MAPPING[ ++$key ] ); } throw No_Verification_Action_Left_Exception::because_out_of_bounds(); @@ -53,6 +54,4 @@ public function determine_next_verify_action( Current_Verification_Action $curre throw No_Verification_Action_Left_Exception::because_unidentified_action_given( $current_verification_action ); } - - } diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php new file mode 100644 index 00000000000..9bce1661fdc --- /dev/null +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php @@ -0,0 +1,66 @@ +cron_schedule_handler = $cron_schedule_handler; + $this->cron_batch_handler = $cron_batch_handler; + $this->verify_indexable_action_factory = $verify_indexable_action_factory; + $this->action_handler = $action_handler; + } + + /** + * @param Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command + * + * @return void + */ + public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { + + $verification_action = $this->verify_indexable_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); + $has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); + // for each fix + if ( $has_more_to_index ) { + $this->cron_batch_handler->set_current_non_timestamped_indexables_batch( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); + + return; + } + try { + $next_action = $this->verify_indexable_action_factory->determine_next_verify_action( $verify_non_timestamp_indexables_command->get_current_action() ); + $this->action_handler->set_current_verification_action( $next_action ); + } catch ( No_Verification_Action_Left_Exception $exception ) { + $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + } + } +} diff --git a/src/indexables/application/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php similarity index 58% rename from src/indexables/application/verify-non-timestamp-indexables-command.php rename to src/indexables/application/commands/verify-non-timestamp-indexables-command.php index 7d4f89e6a32..ef4fd1dddb1 100644 --- a/src/indexables/application/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -1,8 +1,9 @@ current_action = new Current_Verification_Action( $current_action ); + $this->batch_size = new Batch_Size( $batch_size ); parent::__construct( $last_batch, $plugin_deactivated_at ); } - /** * @return Current_Verification_Action */ @@ -31,5 +36,10 @@ public function get_current_action(): Current_Verification_Action { return $this->current_action; } - + /** + * @return \Yoast\WP\SEO\Indexables\Domain\Batch_Size + */ + public function get_batch_size(): Batch_Size { + return $this->batch_size; + } } diff --git a/src/indexables/application/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php similarity index 93% rename from src/indexables/application/verify-post-indexables-command-handler.php rename to src/indexables/application/commands/verify-post-indexables-command-handler.php index 9502fd8d7f9..ec1693ddb94 100644 --- a/src/indexables/application/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -1,9 +1,11 @@ options_helper = $options_helper; + } + + public function get_current_verification_action():int { + return $this->options_helper->get( 'cron_verify_current_action', 'term' ); + } + + public function set_current_verification_action( Current_Verification_Action $current_verification_action) { + $this->options_helper->set( 'cron_verify_current_action', $current_verification_action->get_action() ); + } +} diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index 9bab798189e..a6f276f4c58 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -3,24 +3,34 @@ namespace Yoast\WP\SEO\Indexables\Application; use Yoast\WP\SEO\Helpers\Options_Helper; +use Yoast\WP\SEO\Indexables\Domain\Batch_Size; +use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; class Verification_Cron_Batch_Handler { - /** * @var Options_Helper */ protected $options_helper; - public function __construct(Options_Helper $options_helper) { + public function __construct( Options_Helper $options_helper ) { $this->options_helper = $options_helper; } - public function get_current_post_indexables_batch( ):int { + public function get_current_post_indexables_batch():int { return $this->options_helper->get( 'cron_verify_post_indexables_last_batch', 0 ); } public function set_current_post_indexables_batch( int $batch_count ) { - $this->options_helper->set('cron_verify_post_indexables_last_batch',$batch_count); + $this->options_helper->set( 'cron_verify_post_indexables_last_batch', $batch_count ); + } + + public function get_current_non_timestamped_indexables_batch():int { + return $this->options_helper->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 ); + } + + public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size) { + $batch_count = $last_batch_count->get_last_batch() + $batch_size->get_batch_size(); + $this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count ); } } diff --git a/src/indexables/application/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/verify-non-timestamp-indexables-command-hander.php deleted file mode 100644 index f661fc54c1e..00000000000 --- a/src/indexables/application/verify-non-timestamp-indexables-command-hander.php +++ /dev/null @@ -1,53 +0,0 @@ -cron_schedule_handler = $cron_schedule_handler; - $this->verify_indexable_action_factory = $verify_indexable_action_factory; - } - - /** - * @param Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command - * - * @return void - */ - public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { - // Need to do something with this. - $batch_size = 10; - - $verification_action = $this->verify_indexable_action_factory->get($verify_non_timestamp_indexables_command->get_current_action()); - $has_more_to_index = $verification_action->re_build_indexables($verify_non_timestamp_indexables_command->get_last_batch_count()); - // for each fix - if($has_more_to_index){ - //option + batch size - - return; - } - try { - $next_action = $this->verify_indexable_action_factory->determine_next_verify_action($verify_non_timestamp_indexables_command->get_current_action()); - // update option. - }catch (No_Verification_Action_Left_Exception $exception){ - $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); - } - } -} diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index 00fac59737d..c21cdd48f9c 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -6,9 +6,7 @@ interface Verify_Indexable_Action_Factory_Interface { - public function get( Current_Verification_Action $verification_action ):Verify_Indexables_Action_Interface; - public function determine_next_verify_action( Current_Verification_Action $current_verification_action ):string; - + public function determine_next_verify_action( Current_Verification_Action $current_verification_action ):Current_Verification_Action; } diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 75c1c70a401..7cc243407eb 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -2,6 +2,7 @@ namespace Yoast\WP\SEO\Indexables\Domain\Actions; +use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Models\Indexable; @@ -9,11 +10,11 @@ interface Verify_Indexables_Action_Interface { /** * @param Last_Batch_Count $last_batch_count + * @param Batch_Size $batch_size * * @return bool return false if there are no objects left to re-build. */ - public function re_build_indexables( Last_Batch_Count $last_batch_count):bool; - + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size):bool; /** * @param \wpdb $wpdb @@ -21,5 +22,5 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count):bool; * @return mixed * @required */ - public function setWpdb( \wpdb $wpdb); + public function set_wpdb( \wpdb $wpdb); } diff --git a/src/indexables/domain/batch-size.php b/src/indexables/domain/batch-size.php new file mode 100644 index 00000000000..5515e320762 --- /dev/null +++ b/src/indexables/domain/batch-size.php @@ -0,0 +1,29 @@ +batch_size = $batch_size; + } + + /** + * @return int + */ + public function get_batch_size(): int { + return $this->batch_size; + } + + public function should_keep_going( ?int $count ): bool { + return $count >= $this->get_batch_size(); + } +} diff --git a/src/indexables/domain/exceptions/no-verification-action-left-exception.php b/src/indexables/domain/exceptions/no-verification-action-left-exception.php index 5be6647dc58..e1a67128069 100644 --- a/src/indexables/domain/exceptions/no-verification-action-left-exception.php +++ b/src/indexables/domain/exceptions/no-verification-action-left-exception.php @@ -22,7 +22,7 @@ public static function because_out_of_bounds() { * * @return No_Verification_Action_Left_Exception The exception. */ - public static function because_unidentified_action_given($verification_action) { + public static function because_unidentified_action_given( $verification_action ) { return new self( "The passed verification action $verification_action is not found" ); diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index a76e81f2d3d..bc5f8427bdf 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -2,15 +2,78 @@ namespace Yoast\WP\SEO\Indexables\Infrastructure\Actions; +use Yoast\WP\SEO\Helpers\Taxonomy_Helper; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Interface; +use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Models\Indexable; +use Yoast\WP\SEO\Repositories\Indexable_Repository; class Verify_Term_Indexables_Action implements Verify_Indexables_Action_Interface { - public function re_build_indexables( Last_Batch_Count $last_batch_count ): bool { - // TODO: Implement re_build_indexables() method. + /** + * @var \Yoast\WP\SEO\Helpers\Taxonomy_Helper + */ + protected $taxonomy; + + /** + * @var \Yoast\WP\SEO\Repositories\Indexable_Repository + */ + protected $repository; + + public function __construct( Taxonomy_Helper $taxonomy, Indexable_Repository $repository ) { + $this->taxonomy = $taxonomy; + $this->repository = $repository; + } + + /** + * @var \wpdb $wpdb The wp query. + */ + private $wpdb; + + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { + $query = $this->get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. + $term_ids = $this->wpdb->get_col( $query ); + + foreach ( $term_ids as $term_id ) { + $this->repository->build_by_id_and_type( (int) $term_id, 'term' ); + } + + + return $batch_size->should_keep_going( \count( $term_ids ) ); + } + + /** + * @param \wpdb $wpdb + * + * @return void + * @required + */ + public function set_wpdb( \wpdb $wpdb ) { + $this->wpdb = $wpdb; } + private function get_query( $limit, $batch_size ) { + $taxonomy_table = $this->wpdb->term_taxonomy; + $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); + $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); + $replacements = []; + \array_push( $replacements, ...$public_taxonomies ); + + $limit_query = 'LIMIT %d'; + $replacements[] = $limit; + $offset_query = 'OFFSET %d'; + $replacements[] = ( $limit + $batch_size ); + + return $this->wpdb->prepare( + " + SELECT term_id + FROM {$taxonomy_table} AS T + WHERE taxonomy IN ($placeholders) + $limit_query $offset_query", + $replacements + ); + } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index be32b2e5939..9831560484e 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -4,7 +4,10 @@ use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; use Yoast\WP\SEO\Helpers\Options_Helper; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; +use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; @@ -22,10 +25,19 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { * @var Options_Helper */ protected $options_helper; + /** * @var Verification_Cron_Batch_Handler */ protected $cron_batch_handler; + /** + * @var \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler + */ + protected $non_timestamp_indexables_command_handler; + /** + * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler + */ + protected $verification_action_handler; /** * @var Cron_Verification_Gate @@ -33,21 +45,26 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { private $cron_verification_gate; /** - * @param Cron_Verification_Gate $cron_verification_gate - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param Options_Helper $options_helper - * @param Verification_Cron_Batch_Handler $cron_batch_handler + * @param Cron_Verification_Gate $cron_verification_gate + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param Options_Helper $options_helper + * @param Verification_Cron_Batch_Handler $cron_batch_handler + * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler */ public function __construct( Cron_Verification_Gate $cron_verification_gate, Verification_Cron_Schedule_Handler $cron_schedule_handler, Options_Helper $options_helper, - Verification_Cron_Batch_Handler $cron_batch_handler + Verification_Cron_Batch_Handler $cron_batch_handler, + Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler, + Next_Verification_Action_Handler $verification_action_handler ) { - $this->cron_verification_gate = $cron_verification_gate; - $this->cron_schedule_handler = $cron_schedule_handler; - $this->options_helper = $options_helper; - $this->cron_batch_handler = $cron_batch_handler; + $this->cron_verification_gate = $cron_verification_gate; + $this->cron_schedule_handler = $cron_schedule_handler; + $this->options_helper = $options_helper; + $this->cron_batch_handler = $cron_batch_handler; + $this->non_timestamp_indexables_command_handler = $non_timestamp_indexables_command_handler; + $this->verification_action_handler = $verification_action_handler; } /** @@ -70,6 +87,16 @@ public function start_verify_non_timestamped_indexables() { return; } + // @todo add filter here. + $batch_size = 10; + $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); + $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); + $action = $this->verification_action_handler->get_current_verification_action(); + $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $plugin_deactivated, $action ); + + $this->non_timestamp_indexables_command_handler->handle( $command ); + + // Start cron process } } diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index f2c9228b8b2..3295a425098 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -7,8 +7,8 @@ use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\Application\Verify_Post_Indexables_Command; -use Yoast\WP\SEO\Indexables\Application\Verify_Post_Indexables_Command_Handler; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; class Verification_Cron_Callback_Integration implements Integration_Interface { @@ -24,10 +24,12 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { * @var \Yoast\WP\SEO\Helpers\Options_Helper */ protected $options_helper; + /** * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler */ protected $cron_batch_handler; + /** * @var \Yoast\WP\SEO\Indexables\Application\Verify_Post_Indexables_Command_Handler */ @@ -39,9 +41,9 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { private $cron_verification_gate; /** - * @param Cron_Verification_Gate $cron_verification_gate - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param Options_Helper $options_helper + * @param Cron_Verification_Gate $cron_verification_gate + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param Options_Helper $options_helper * @param Verification_Cron_Batch_Handler $cron_batch_handler * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler */ @@ -83,5 +85,4 @@ public function start_verify_posts(): void { $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $last_batch, $plugin_deactivated ) ); } - } diff --git a/src/repositories/indexable-repository.php b/src/repositories/indexable-repository.php index b3ad81bc33e..f731ff012c6 100644 --- a/src/repositories/indexable-repository.php +++ b/src/repositories/indexable-repository.php @@ -107,7 +107,8 @@ public function query() { * This may be the result of the indexable not existing or of being unable to determine what type of page the * current page is. * - * @return bool|Indexable The indexable. If no indexable is found returns an empty indexable. Returns false if there is a database error. + * @return bool|Indexable The indexable. If no indexable is found returns an empty indexable. Returns false if + * there is a database error. */ public function for_current_page() { $indexable = false; @@ -344,6 +345,30 @@ public function find_by_id_and_type( $object_id, $object_type, $auto_create = tr return $indexable; } + /** + * Builds an indexable by its ID and type. + * + * @param int $object_id The indexable object ID. + * @param string $object_type The indexable object type. + * + * @return bool|Indexable Instance of indexable. + */ + public function build_by_id_and_type( $object_id, $object_type ) { + $indexable = $this->query() + ->where( 'object_id', $object_id ) + ->where( 'object_type', $object_type ) + ->find_one(); + + if ( ! $indexable ) { + $indexable = $this->builder->build_for_id_and_type( $object_id, $object_type ); + } + else { + $indexable = $this->builder->build_for_id_and_type( $object_id, $object_type, $indexable ); + } + + return $indexable; + } + /** * Retrieves multiple indexables at once by their id's and type. * @@ -457,6 +482,7 @@ public function get_subpages_by_post_parent( $post_parent, $exclude_ids = [] ) { if ( ! empty( $exclude_ids ) ) { $query->where_not_in( 'object_id', $exclude_ids ); } + return $query->find_many(); } @@ -505,6 +531,7 @@ public function upgrade_indexable( $indexable ) { if ( $this->version_manager->indexable_needs_upgrade( $indexable ) ) { $indexable = $this->builder->build( $indexable ); } + return $indexable; } From 8d656971b3b8602d62e25b99bca62287366cf803 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 13 Jun 2023 10:29:39 +0200 Subject: [PATCH 08/41] Add batch size to command. --- .../actions/verify-indexable-action-factory.php | 4 ++-- ...-non-timestamp-indexables-command-hander.php | 2 ++ .../verify-non-timestamp-indexables-command.php | 14 ++------------ .../verify-post-indexables-command-handler.php | 17 +++++++++++++---- .../next-verification-action-handler.php | 3 ++- .../verification-cron-batch-handler.php | 4 ++-- .../domain/abstract-indexables-command.php | 16 +++++++++++++++- ...n-no-timestamp-cron-callback-integration.php | 5 ++--- ...fication-posts-cron-callback-integration.php | 8 +++++--- 9 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 6ce1362e701..f275cf9d63f 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -36,8 +36,8 @@ public function get( Current_Verification_Action $verification_action ): Verify_ /** * @param Current_Verification_Action $current_verification_action_object * - * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception - * @return \Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action + * @throws No_Verification_Action_Left_Exception + * @return Current_Verification_Action */ public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ): Current_Verification_Action { diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php index 9bce1661fdc..9bd05061a1b 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php @@ -15,10 +15,12 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { * @var Verify_Indexable_Action_Factory_Interface */ protected $verify_indexable_action_factory; + /** * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler */ protected $cron_batch_handler; + /** * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler */ diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index ef4fd1dddb1..fafb78860ef 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -13,10 +13,6 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman */ private $current_action; - /** - * @var Batch_Size $batch_size The batch size. - */ - private $batch_size; /** * @param int $last_batch The last batch count. @@ -25,8 +21,8 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman */ public function __construct( int $last_batch, int $batch_size, string $plugin_deactivated_at, string $current_action ) { $this->current_action = new Current_Verification_Action( $current_action ); - $this->batch_size = new Batch_Size( $batch_size ); - parent::__construct( $last_batch, $plugin_deactivated_at ); + + parent::__construct($batch_size, $last_batch, $plugin_deactivated_at ); } /** @@ -36,10 +32,4 @@ public function get_current_action(): Current_Verification_Action { return $this->current_action; } - /** - * @return \Yoast\WP\SEO\Indexables\Domain\Batch_Size - */ - public function get_batch_size(): Batch_Size { - return $this->batch_size; - } } diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index ec1693ddb94..09b17cdd438 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -5,6 +5,7 @@ use Yoast\WP\SEO\Builders\Indexable_Post_Builder; use Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface; +use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; @@ -14,6 +15,10 @@ class Verify_Post_Indexables_Command_Handler { * @var Outdated_Post_Indexables_Repository_Interface */ protected $outdated_post_indexables_repository; + /** + * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + */ + protected $verification_cron_batch_handler; /** * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler @@ -28,21 +33,20 @@ class Verify_Post_Indexables_Command_Handler { public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, Verification_Cron_Schedule_Handler $cron_schedule_handler, + Verification_Cron_Batch_Handler $verification_cron_batch_handler, Indexable_Post_Builder $indexable_post_builder ) { $this->outdated_post_indexables_repository = $outdated_post_indexables_repository; $this->cron_schedule_handler = $cron_schedule_handler; $this->indexable_post_builder = $indexable_post_builder; + $this->verification_cron_batch_handler = $verification_cron_batch_handler; } /** * @param Verify_Post_Indexables_Command $verify_post_indexables_command */ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ): void { - // Need to do something with this. - $batch_size = 10; - try { $outdated_post_indexables_list = $this->outdated_post_indexables_repository->get_outdated_post_indexables( $verify_post_indexables_command->get_last_batch_count(), $verify_post_indexables_command->get_plugin_deactivated_at() ); } catch ( No_Outdated_Posts_Found_Exception $exception ) { @@ -55,8 +59,13 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c $this->indexable_post_builder->build( $post_indexable->object_id, $post_indexable ); } - if ( $outdated_post_indexables_list->count() < $batch_size ) { + if ( $outdated_post_indexables_list->count() < $verify_post_indexables_command->get_batch_size() ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); + + return; } + + $next_batch = $verify_post_indexables_command->get_last_batch_count() + $verify_post_indexables_command->get_batch_size(); + $this->verification_cron_batch_handler->set_current_post_indexables_batch( $next_batch ); } } diff --git a/src/indexables/application/next-verification-action-handler.php b/src/indexables/application/next-verification-action-handler.php index 74e790135af..9bcc92e1611 100644 --- a/src/indexables/application/next-verification-action-handler.php +++ b/src/indexables/application/next-verification-action-handler.php @@ -8,6 +8,7 @@ use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; class Next_Verification_Action_Handler { + /** * @var Options_Helper */ @@ -21,7 +22,7 @@ public function get_current_verification_action():int { return $this->options_helper->get( 'cron_verify_current_action', 'term' ); } - public function set_current_verification_action( Current_Verification_Action $current_verification_action) { + public function set_current_verification_action( Current_Verification_Action $current_verification_action ) { $this->options_helper->set( 'cron_verify_current_action', $current_verification_action->get_action() ); } } diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index a6f276f4c58..3f9530d0c2f 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -29,8 +29,8 @@ public function get_current_non_timestamped_indexables_batch():int { return $this->options_helper->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 ); } - public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size) { - $batch_count = $last_batch_count->get_last_batch() + $batch_size->get_batch_size(); + public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ) { + $batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); $this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count ); } } diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index 6e33d9d3870..a0a3d51c59c 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -14,13 +14,19 @@ abstract class Abstract_Indexables_Command { */ protected $plugin_deactivated_at; + /** + * @var Batch_Size $batch_size The batch size. + */ + private $batch_size; + /** * @param int $last_batch The last batch count. * @param string $plugin_deactivated_at The plugin deactivated at timestamp. */ - public function __construct( int $last_batch, string $plugin_deactivated_at ) { + public function __construct(int $batch_size, int $last_batch, string $plugin_deactivated_at ) { $this->last_batch_count = new Last_Batch_Count( $last_batch ); $this->plugin_deactivated_at = new Plugin_Deactivated_Timestamp( $plugin_deactivated_at ); + $this->batch_size = new Batch_Size( $batch_size ); } /** @@ -36,4 +42,12 @@ public function get_last_batch_count(): Last_Batch_Count { public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { return $this->plugin_deactivated_at; } + + + /** + * @return Batch_Size + */ + public function get_batch_size(): Batch_Size { + return $this->batch_size; + } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 9831560484e..a834958b45d 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -30,10 +30,12 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { * @var Verification_Cron_Batch_Handler */ protected $cron_batch_handler; + /** * @var \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler */ protected $non_timestamp_indexables_command_handler; + /** * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler */ @@ -95,8 +97,5 @@ public function start_verify_non_timestamped_indexables() { $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $plugin_deactivated, $action ); $this->non_timestamp_indexables_command_handler->handle( $command ); - - - // Start cron process } } diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 3295a425098..9f7634ef1a7 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -4,11 +4,11 @@ use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; use Yoast\WP\SEO\Helpers\Options_Helper; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; +use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; class Verification_Cron_Callback_Integration implements Integration_Interface { @@ -80,9 +80,11 @@ public function start_verify_posts(): void { return; } + $batch_size = 10; + $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); - $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $last_batch, $plugin_deactivated ) ); + $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch, $plugin_deactivated ) ); } } From ce1511f165f0007bab046a6556c677408a9820aa Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 14 Jun 2023 10:48:15 +0200 Subject: [PATCH 09/41] Adds options to option list --- .../tracking/class-tracking-settings-data.php | 4 + inc/options/class-wpseo-option-wpseo.php | 232 ++++++++++-------- src/integrations/settings-integration.php | 5 + 3 files changed, 133 insertions(+), 108 deletions(-) diff --git a/admin/tracking/class-tracking-settings-data.php b/admin/tracking/class-tracking-settings-data.php index 29e1a9e6d30..6bc3dcbd59b 100644 --- a/admin/tracking/class-tracking-settings-data.php +++ b/admin/tracking/class-tracking-settings-data.php @@ -224,6 +224,10 @@ class WPSEO_Tracking_Settings_Data implements WPSEO_Collection { 'deny_wp_json_crawling', 'deny_adsbot_crawling', 'last_known_no_unindexed', + 'cron_verify_current_action', + 'cron_verify_post_indexables_last_batch', + 'cron_verify_non_timestamped_indexables_last_batch', + 'plugin_deactivated_at', ]; /** diff --git a/inc/options/class-wpseo-option-wpseo.php b/inc/options/class-wpseo-option-wpseo.php index 3b516553c76..05c25b3bc76 100644 --- a/inc/options/class-wpseo-option-wpseo.php +++ b/inc/options/class-wpseo-option-wpseo.php @@ -26,116 +26,126 @@ class WPSEO_Option_Wpseo extends WPSEO_Option { */ protected $defaults = [ // Non-form fields, set via (ajax) function. - 'tracking' => null, - 'toggled_tracking' => false, - 'license_server_version' => false, - 'ms_defaults_set' => false, - 'ignore_search_engines_discouraged_notice' => false, - 'indexing_first_time' => true, - 'indexing_started' => null, - 'indexing_reason' => '', - 'indexables_indexing_completed' => false, - 'index_now_key' => '', + 'tracking' => null, + 'toggled_tracking' => false, + 'license_server_version' => false, + 'ms_defaults_set' => false, + 'ignore_search_engines_discouraged_notice' => false, + 'indexing_first_time' => true, + 'indexing_started' => null, + 'indexing_reason' => '', + 'indexables_indexing_completed' => false, + 'index_now_key' => '', // Non-form field, should only be set via validation routine. - 'version' => '', // Leave default as empty to ensure activation/upgrade works. - 'previous_version' => '', + 'version' => '', + // Leave default as empty to ensure activation/upgrade works. + 'previous_version' => '', // Form fields. - 'disableadvanced_meta' => true, - 'enable_headless_rest_endpoints' => true, - 'ryte_indexability' => false, - 'baiduverify' => '', // Text field. - 'googleverify' => '', // Text field. - 'msverify' => '', // Text field. - 'yandexverify' => '', - 'site_type' => '', // List of options. - 'has_multiple_authors' => '', - 'environment_type' => '', - 'content_analysis_active' => true, - 'keyword_analysis_active' => true, - 'inclusive_language_analysis_active' => false, - 'enable_admin_bar_menu' => true, - 'enable_cornerstone_content' => true, - 'enable_xml_sitemap' => true, - 'enable_text_link_counter' => true, - 'enable_index_now' => true, - 'show_onboarding_notice' => false, - 'first_activated_on' => false, - 'myyoast-oauth' => [ + 'disableadvanced_meta' => true, + 'enable_headless_rest_endpoints' => true, + 'ryte_indexability' => false, + 'baiduverify' => '', + // Text field. + 'googleverify' => '', + // Text field. + 'msverify' => '', + // Text field. + 'yandexverify' => '', + 'site_type' => '', + // List of options. + 'has_multiple_authors' => '', + 'environment_type' => '', + 'content_analysis_active' => true, + 'keyword_analysis_active' => true, + 'inclusive_language_analysis_active' => false, + 'enable_admin_bar_menu' => true, + 'enable_cornerstone_content' => true, + 'enable_xml_sitemap' => true, + 'enable_text_link_counter' => true, + 'enable_index_now' => true, + 'show_onboarding_notice' => false, + 'first_activated_on' => false, + 'myyoast-oauth' => [ 'config' => [ 'clientId' => null, 'secret' => null, ], 'access_tokens' => [], ], - 'semrush_integration_active' => true, - 'semrush_tokens' => [], - 'semrush_country_code' => 'us', - 'permalink_structure' => '', - 'home_url' => '', - 'dynamic_permalinks' => false, - 'category_base_url' => '', - 'tag_base_url' => '', - 'custom_taxonomy_slugs' => [], - 'enable_enhanced_slack_sharing' => true, - 'zapier_integration_active' => false, - 'zapier_subscription' => [], - 'zapier_api_key' => '', - 'enable_metabox_insights' => true, - 'enable_link_suggestions' => true, - 'algolia_integration_active' => false, - 'import_cursors' => [], - 'workouts_data' => [ 'configuration' => [ 'finishedSteps' => [] ] ], - 'configuration_finished_steps' => [], - 'dismiss_configuration_workout_notice' => false, - 'dismiss_premium_deactivated_notice' => false, - 'importing_completed' => [], - 'wincher_integration_active' => true, - 'wincher_tokens' => [], - 'wincher_automatically_add_keyphrases' => false, - 'wincher_website_id' => '', - 'wordproof_integration_active' => false, - 'wordproof_integration_changed' => false, - 'first_time_install' => false, - 'should_redirect_after_install_free' => false, - 'activation_redirect_timestamp_free' => 0, - 'remove_feed_global' => false, - 'remove_feed_global_comments' => false, - 'remove_feed_post_comments' => false, - 'remove_feed_authors' => false, - 'remove_feed_categories' => false, - 'remove_feed_tags' => false, - 'remove_feed_custom_taxonomies' => false, - 'remove_feed_post_types' => false, - 'remove_feed_search' => false, - 'remove_atom_rdf_feeds' => false, - 'remove_shortlinks' => false, - 'remove_rest_api_links' => false, - 'remove_rsd_wlw_links' => false, - 'remove_oembed_links' => false, - 'remove_generator' => false, - 'remove_emoji_scripts' => false, - 'remove_powered_by_header' => false, - 'remove_pingback_header' => false, - 'clean_campaign_tracking_urls' => false, - 'clean_permalinks' => false, - 'clean_permalinks_extra_variables' => '', - 'search_cleanup' => false, - 'search_cleanup_emoji' => false, - 'search_cleanup_patterns' => false, - 'search_character_limit' => 50, - 'deny_search_crawling' => false, - 'deny_wp_json_crawling' => false, - 'deny_adsbot_crawling' => false, - 'redirect_search_pretty_urls' => false, - 'least_readability_ignore_list' => [], - 'least_seo_score_ignore_list' => [], - 'most_linked_ignore_list' => [], - 'least_linked_ignore_list' => [], - 'indexables_page_reading_list' => [ false, false, false, false, false ], - 'indexables_overview_state' => 'dashboard-not-visited', - 'last_known_public_post_types' => [], - 'last_known_public_taxonomies' => [], - 'last_known_no_unindexed' => [], + 'semrush_integration_active' => true, + 'semrush_tokens' => [], + 'semrush_country_code' => 'us', + 'permalink_structure' => '', + 'home_url' => '', + 'dynamic_permalinks' => false, + 'category_base_url' => '', + 'tag_base_url' => '', + 'custom_taxonomy_slugs' => [], + 'enable_enhanced_slack_sharing' => true, + 'zapier_integration_active' => false, + 'zapier_subscription' => [], + 'zapier_api_key' => '', + 'enable_metabox_insights' => true, + 'enable_link_suggestions' => true, + 'algolia_integration_active' => false, + 'import_cursors' => [], + 'workouts_data' => [ 'configuration' => [ 'finishedSteps' => [] ] ], + 'configuration_finished_steps' => [], + 'dismiss_configuration_workout_notice' => false, + 'dismiss_premium_deactivated_notice' => false, + 'importing_completed' => [], + 'wincher_integration_active' => true, + 'wincher_tokens' => [], + 'wincher_automatically_add_keyphrases' => false, + 'wincher_website_id' => '', + 'wordproof_integration_active' => false, + 'wordproof_integration_changed' => false, + 'first_time_install' => false, + 'should_redirect_after_install_free' => false, + 'activation_redirect_timestamp_free' => 0, + 'remove_feed_global' => false, + 'remove_feed_global_comments' => false, + 'remove_feed_post_comments' => false, + 'remove_feed_authors' => false, + 'remove_feed_categories' => false, + 'remove_feed_tags' => false, + 'remove_feed_custom_taxonomies' => false, + 'remove_feed_post_types' => false, + 'remove_feed_search' => false, + 'remove_atom_rdf_feeds' => false, + 'remove_shortlinks' => false, + 'remove_rest_api_links' => false, + 'remove_rsd_wlw_links' => false, + 'remove_oembed_links' => false, + 'remove_generator' => false, + 'remove_emoji_scripts' => false, + 'remove_powered_by_header' => false, + 'remove_pingback_header' => false, + 'clean_campaign_tracking_urls' => false, + 'clean_permalinks' => false, + 'clean_permalinks_extra_variables' => '', + 'search_cleanup' => false, + 'search_cleanup_emoji' => false, + 'search_cleanup_patterns' => false, + 'search_character_limit' => 50, + 'deny_search_crawling' => false, + 'deny_wp_json_crawling' => false, + 'deny_adsbot_crawling' => false, + 'redirect_search_pretty_urls' => false, + 'least_readability_ignore_list' => [], + 'least_seo_score_ignore_list' => [], + 'most_linked_ignore_list' => [], + 'least_linked_ignore_list' => [], + 'indexables_page_reading_list' => [ false, false, false, false, false ], + 'indexables_overview_state' => 'dashboard-not-visited', + 'last_known_public_post_types' => [], + 'last_known_public_taxonomies' => [], + 'last_known_no_unindexed' => [], + 'cron_verify_current_action' => 'term', + 'cron_verify_post_indexables_last_batch' => 0, + 'cron_verify_non_timestamped_indexables_last_batch' => 0, + 'plugin_deactivated_at' => false, + ]; /** @@ -250,7 +260,7 @@ public static function get_instance() { public function add_option_filters() { parent::add_option_filters(); - list( $hookname, $callback, $priority ) = $this->get_verify_features_option_filter_hook(); + [ $hookname, $callback, $priority ] = $this->get_verify_features_option_filter_hook(); if ( has_filter( $hookname, $callback ) === false ) { add_filter( $hookname, $callback, $priority ); @@ -266,7 +276,7 @@ public function add_option_filters() { public function remove_option_filters() { parent::remove_option_filters(); - list( $hookname, $callback, $priority ) = $this->get_verify_features_option_filter_hook(); + [ $hookname, $callback, $priority ] = $this->get_verify_features_option_filter_hook(); remove_filter( $hookname, $callback, $priority ); } @@ -279,7 +289,7 @@ public function remove_option_filters() { public function add_default_filters() { parent::add_default_filters(); - list( $hookname, $callback, $priority ) = $this->get_verify_features_default_option_filter_hook(); + [ $hookname, $callback, $priority ] = $this->get_verify_features_default_option_filter_hook(); if ( has_filter( $hookname, $callback ) === false ) { add_filter( $hookname, $callback, $priority ); @@ -295,7 +305,7 @@ public function add_default_filters() { public function remove_default_filters() { parent::remove_default_filters(); - list( $hookname, $callback, $priority ) = $this->get_verify_features_default_option_filter_hook(); + [ $hookname, $callback, $priority ] = $this->get_verify_features_default_option_filter_hook(); remove_filter( $hookname, $callback, $priority ); } @@ -325,6 +335,7 @@ protected function validate_option( $dirty, $clean, $old ) { case 'wincher_website_id': case 'clean_permalinks_extra_variables': case 'indexables_overview_state': + case 'cron_verify_current_action': if ( isset( $dirty[ $key ] ) ) { $clean[ $key ] = $dirty[ $key ]; } @@ -382,6 +393,9 @@ protected function validate_option( $dirty, $clean, $old ) { case 'first_activated_on': case 'indexing_started': case 'activation_redirect_timestamp_free': + case 'cron_verify_post_indexables_last_batch': + case 'cron_verify_non_timestamped_indexables_last_batch': + case 'plugin_deactivated_at': $clean[ $key ] = false; if ( isset( $dirty[ $key ] ) ) { if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) ) { @@ -599,7 +613,8 @@ protected function get_verify_features_option_filter_hook() { } /** - * Gets the filter hook name and callback for adjusting the default option value against the network-allowed features. + * Gets the filter hook name and callback for adjusting the default option value against the network-allowed + * features. * * @return array Array where the first item is the hook name, the second is the hook callback, * and the third is the hook priority. @@ -636,7 +651,8 @@ protected function clean_option( $option_value, $current_version = null, $all_ol ]; foreach ( $value_change as $key ) { - if ( isset( $option_value[ $key ] ) + if ( + isset( $option_value[ $key ] ) && in_array( $option_value[ $key ], $target_values, true ) ) { $option_value[ $key ] = true; diff --git a/src/integrations/settings-integration.php b/src/integrations/settings-integration.php index 6ae604392c5..c05e1752c0f 100644 --- a/src/integrations/settings-integration.php +++ b/src/integrations/settings-integration.php @@ -67,6 +67,11 @@ class Settings_Integration implements Integration_Interface { 'most_linked_ignore_list', 'least_linked_ignore_list', 'indexables_page_reading_list', + 'last_known_no_unindexed', + 'cron_verify_current_action', + 'cron_verify_post_indexables_last_batch', + 'cron_verify_non_timestamped_indexables_last_batch', + 'plugin_deactivated_at', ], 'wpseo_titles' => [ 'company_logo_meta', From f3f8ef70b17a9f4feb8c025c07540a2893b29643 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 14 Jun 2023 10:48:33 +0200 Subject: [PATCH 10/41] Finish implementation archive and general. --- .../verify-indexable-action-factory.php | 40 ++++++++++-- ...on-timestamp-indexables-command-hander.php | 16 ++++- .../next-verification-action-handler.php | 2 +- .../verification-cron-schedule-handler.php | 5 +- .../verify-general-indexables-action.php | 59 +++++++++++++++++ ...y-post-type-archives-indexables-action.php | 63 +++++++++++++++++++ .../actions/verify-term-indexables-action.php | 7 ++- ...schedule-verification-cron-integration.php | 14 +++-- ...no-timestamp-cron-callback-integration.php | 9 +-- ...cation-posts-cron-callback-integration.php | 6 +- 10 files changed, 195 insertions(+), 26 deletions(-) create mode 100644 src/indexables/infrastructure/actions/verify-general-indexables-action.php create mode 100644 src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index f275cf9d63f..fb87d74dff3 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -7,27 +7,55 @@ use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; +use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; +use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory_Interface { + + /** + * @var Verify_Term_Indexables_Action + */ + protected $verify_term_indexables_action; private const VERIFICATION_MAPPING = [ - 'terms', + 'term', 'general', + 'post-type-archives', 'term_links', 'post_links', - 'post-type-archives', ]; + /** + * @var \Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action + */ + protected $verify_general_indexables_action; + /** + * @var \Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action + */ + protected $verify_post_type_archives_indexables_action; + + public function __construct( + Verify_Term_Indexables_Action $verify_term_indexables_action, + Verify_General_Indexables_Action $verify_general_indexables_action, + Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action + ) { + $this->verify_term_indexables_action = $verify_term_indexables_action; + $this->verify_general_indexables_action = $verify_general_indexables_action; + $this->verify_post_type_archives_indexables_action = $verify_post_type_archives_indexables_action; + } + /** * @throws Verify_Action_Not_Found_Exception */ public function get( Current_Verification_Action $verification_action ): Verify_Indexables_Action_Interface { switch ( $verification_action->get_action() ) { - case 'terms': - return new Verify_Term_Indexables_Action(); + case 'term': + return $this->verify_term_indexables_action; case 'general': - break; + return $this->verify_general_indexables_action; + case'post-type-archives': + return $this->verify_post_type_archives_indexables_action; default: throw new Verify_Action_Not_Found_Exception(); } @@ -46,7 +74,7 @@ public function determine_next_verify_action( Current_Verification_Action $curre if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING ) ) { $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING ); if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) { - return new Current_Verification_Action( self::VERIFICATION_MAPPING[ ++$key ] ); + return new Current_Verification_Action( self::VERIFICATION_MAPPING[ $key ] ); } throw No_Verification_Action_Left_Exception::because_out_of_bounds(); diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php index 9bd05061a1b..45ebf481abc 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php @@ -7,7 +7,10 @@ use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexable_Action_Factory_Interface; +use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; +use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; +use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; class Verify_Non_Timestamp_Indexables_Command_Handler { @@ -17,12 +20,12 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { protected $verify_indexable_action_factory; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + * @var Verification_Cron_Batch_Handler */ protected $cron_batch_handler; /** - * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler + * @var Next_Verification_Action_Handler */ protected $action_handler; @@ -50,7 +53,13 @@ public function __construct( */ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { - $verification_action = $this->verify_indexable_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); + try { + $verification_action = $this->verify_indexable_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); + }catch(Verify_Action_Not_Found_Exception $exception){ + $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + return; + } + $has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); // for each fix if ( $has_more_to_index ) { @@ -61,6 +70,7 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time try { $next_action = $this->verify_indexable_action_factory->determine_next_verify_action( $verify_non_timestamp_indexables_command->get_current_action() ); $this->action_handler->set_current_verification_action( $next_action ); + $this->cron_batch_handler->set_current_non_timestamped_indexables_batch( new Last_Batch_Count( 0 ), new Batch_Size( 0 ) ); } catch ( No_Verification_Action_Left_Exception $exception ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); } diff --git a/src/indexables/application/next-verification-action-handler.php b/src/indexables/application/next-verification-action-handler.php index 9bcc92e1611..58805d36852 100644 --- a/src/indexables/application/next-verification-action-handler.php +++ b/src/indexables/application/next-verification-action-handler.php @@ -18,7 +18,7 @@ public function __construct( Options_Helper $options_helper ) { $this->options_helper = $options_helper; } - public function get_current_verification_action():int { + public function get_current_verification_action():string { return $this->options_helper->get( 'cron_verify_current_action', 'term' ); } diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index d3d53d27550..0fa0b89d25f 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -20,6 +20,7 @@ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { } public function schedule_indexable_verification(): void { + if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); } @@ -37,9 +38,9 @@ public function unschedule_verify_post_indexables_cron() { } public function unschedule_verify_non_timestamped_indexables_cron() { - $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); if ( $scheduled ) { - \wp_unschedule_event( $scheduled, self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + \wp_unschedule_event( $scheduled, self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); } } } diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php new file mode 100644 index 00000000000..e4feb5b2782 --- /dev/null +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -0,0 +1,59 @@ +repository = $repository; + $this->indexable_builder = $indexable_builder; + } + + /** + * @var \wpdb $wpdb The wp query. + */ + private $wpdb; + + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { + + $system_page = $this->repository->find_for_system_page( '404',false ); + $this->indexable_builder->build_for_system_page( '404', $system_page ); + + $search_result = $this->repository->find_for_system_page( 'search-result',false ); + $this->indexable_builder->build_for_system_page( 'search-result', $search_result ); + + $date_archive = $this->repository->find_for_date_archive(false); + $this->indexable_builder->build_for_date_archive( $date_archive ); + + $home_page = $this->repository->find_for_home_page(false); + $this->indexable_builder->build_for_home_page( $home_page ); + + return false; + } + + /** + * @param \wpdb $wpdb + * + * @return void + * @required + */ + public function set_wpdb( \wpdb $wpdb ) { + $this->wpdb = $wpdb; + } +} diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php new file mode 100644 index 00000000000..3b5b9da6def --- /dev/null +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -0,0 +1,63 @@ +post_type_helper = $post_type_helper; + $this->indexable_builder = $indexable_builder; + $this->indexable_repository = $indexable_repository; + } + + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { + + $archives = $this->post_type_helper->get_indexable_post_archives(); + + $archives = \array_slice( $archives, $last_batch_count->get_last_batch(), $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); + + $indexables = []; + foreach ( $archives as $post_type_archive ) { + $archive_indexable = $this->indexable_repository->find_for_post_type_archive($post_type_archive, false); + $indexables[] = $this->indexable_builder->build_for_post_type_archive( $post_type_archive,$archive_indexable ); + } + + return $batch_size->should_keep_going( \count( $indexables ) ); + } + + /** + * @param \wpdb $wpdb + * + * @return void + * @required + */ + public function set_wpdb( \wpdb $wpdb ) { + $this->wpdb = $wpdb; + } +} diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index bc5f8427bdf..887dfd887e4 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -62,10 +62,13 @@ private function get_query( $limit, $batch_size ) { $replacements = []; \array_push( $replacements, ...$public_taxonomies ); + $limit_query = 'LIMIT %d'; - $replacements[] = $limit; + $replacements[] = $batch_size ; + $offset_query = ''; + if($limit !== 0){ $offset_query = 'OFFSET %d'; - $replacements[] = ( $limit + $batch_size ); + $replacements[] = ( $limit + $batch_size );} return $this->wpdb->prepare( " diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index 4832ce6b92b..81fa24f8805 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -3,9 +3,8 @@ namespace Yoast\WP\SEO\Indexables\User_Interface; use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; -use Yoast\WP\SEO\Helpers\Indexable_Helper; use Yoast\WP\SEO\Helpers\Options_Helper; -use Yoast\WP\SEO\Indexables\application\Verification_Cron_Schedule_Handler; +use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; /** @@ -15,6 +14,10 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { use Admin_Conditional_Trait; + /** + * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + */ + protected $cron_schedule_handler; private $options_helper; /** @@ -22,16 +25,17 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { * * @param Options_Helper $options_helper The options helper. */ - public function __construct( Options_Helper $options_helper ) { + public function __construct( Options_Helper $options_helper,Verification_Cron_Schedule_Handler $cron_schedule_handler) { $this->options_helper = $options_helper; + $this->cron_schedule_handler = $cron_schedule_handler; } /** * @inheritDoc */ public function register_hooks() { - if ( $this->options_helper->get( 'first_time_install', false ) !== false ) { - \add_action( 'wpseo_activate', [ Verification_Cron_Schedule_Handler::class, 'schedule_indexable_verification' ] ); + if ( $this->options_helper->get( 'first_time_install', false ) === false ) { + \add_action( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); } } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index a834958b45d..3c0b256da42 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -32,12 +32,12 @@ class Verification_Cron_Callback_Integration implements Integration_Interface { protected $cron_batch_handler; /** - * @var \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler + * @var Verify_Non_Timestamp_Indexables_Command_Handler */ protected $non_timestamp_indexables_command_handler; /** - * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler + * @var Next_Verification_Action_Handler */ protected $verification_action_handler; @@ -74,7 +74,8 @@ public function __construct( */ public function register_hooks() { \add_action( - Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, + //Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, + 'admin_init', [ $this, 'start_verify_non_timestamped_indexables', @@ -92,7 +93,7 @@ public function start_verify_non_timestamped_indexables() { // @todo add filter here. $batch_size = 10; $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); - $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); + $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); $action = $this->verification_action_handler->get_current_verification_action(); $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $plugin_deactivated, $action ); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 9f7634ef1a7..2ad645efcd1 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -11,7 +11,7 @@ use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; -class Verification_Cron_Callback_Integration implements Integration_Interface { +class Verification_Posts_Cron_Callback_Integration implements Integration_Interface { use Admin_Conditional_Trait; @@ -52,7 +52,7 @@ public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_handler, Options_Helper $options_helper, Verification_Cron_Batch_Handler $cron_batch_handler, - Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler, + Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler ) { $this->cron_verification_gate = $cron_verification_gate; $this->cron_schedule_handler = $cron_schedule_handler; @@ -83,7 +83,7 @@ public function start_verify_posts(): void { $batch_size = 10; $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); - $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION ); + $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch, $plugin_deactivated ) ); } From 08069ab41b180506b05c6fdf4f04876f0091e7cf Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 15 Jun 2023 10:42:18 +0200 Subject: [PATCH 11/41] Progress on updating post indexables. --- ...verify-post-indexables-command-handler.php | 17 +++-- ...d-post-indexables-repository-interface.php | 7 +- .../outdated-post-indexables-repository.php | 76 ++++++++++++++++++- ...no-timestamp-cron-callback-integration.php | 4 +- ...cation-posts-cron-callback-integration.php | 3 +- 5 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index 09b17cdd438..b69cb0edee4 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -3,7 +3,7 @@ namespace Yoast\WP\SEO\Indexables\Application\Commands; -use Yoast\WP\SEO\Builders\Indexable_Post_Builder; +use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; @@ -26,20 +26,20 @@ class Verify_Post_Indexables_Command_Handler { private $cron_schedule_handler; /** - * @var \Yoast\WP\SEO\Builders\Indexable_Post_Builder + * @var \Yoast\WP\SEO\Builders\Indexable_Builder */ - protected $indexable_post_builder; + protected $indexable_builder; public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, Verification_Cron_Schedule_Handler $cron_schedule_handler, Verification_Cron_Batch_Handler $verification_cron_batch_handler, - Indexable_Post_Builder $indexable_post_builder + Indexable_Builder $indexable_builder ) { $this->outdated_post_indexables_repository = $outdated_post_indexables_repository; $this->cron_schedule_handler = $cron_schedule_handler; - $this->indexable_post_builder = $indexable_post_builder; + $this->indexable_builder = $indexable_builder; $this->verification_cron_batch_handler = $verification_cron_batch_handler; } @@ -56,16 +56,17 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c } foreach ( $outdated_post_indexables_list as $post_indexable ) { - $this->indexable_post_builder->build( $post_indexable->object_id, $post_indexable ); + $this->indexable_builder->build( $post_indexable ); } - if ( $outdated_post_indexables_list->count() < $verify_post_indexables_command->get_batch_size() ) { + if ( ! $verify_post_indexables_command->get_batch_size() + ->should_keep_going( $outdated_post_indexables_list->count() ) ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); return; } - $next_batch = $verify_post_indexables_command->get_last_batch_count() + $verify_post_indexables_command->get_batch_size(); + $next_batch = $verify_post_indexables_command->get_last_batch_count()->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size(); $this->verification_cron_batch_handler->set_current_post_indexables_batch( $next_batch ); } } diff --git a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php index 06973cb5450..ab271aaa8d1 100644 --- a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php +++ b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php @@ -11,17 +11,14 @@ interface Outdated_Post_Indexables_Repository_Interface { /** * Finds a list of posts for which the indexables are not up to date. - * This is done by checking if the updated at of the post is the same as the indexable starting from the - * deactivated_timestamp. + * This is done by checking if the updated at of the post is the same as the indexable. * * @param Last_Batch_Count $count - * @param Plugin_Deactivated_Timestamp $deactivated_timestamp * * @throws No_Outdated_Posts_Found_Exception When there are no outdated posts found. * @return Outdated_Post_Indexables_List */ public function get_outdated_post_indexables( - Last_Batch_Count $count, - Plugin_Deactivated_Timestamp $deactivated_timestamp + Last_Batch_Count $count ): Outdated_Post_Indexables_List; } diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 07ec0289928..42de5846cbf 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -4,23 +4,91 @@ use wpdb; use Yoast\WP\Lib\Model; +use Yoast\WP\SEO\Builders\Indexable_Builder; +use Yoast\WP\SEO\Helpers\Post_Helper; +use Yoast\WP\SEO\Helpers\Post_Type_Helper; use Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List; -use Yoast\WP\SEO\Indexables\Domain\Plugin_Deactivated_Timestamp; +use Yoast\WP\SEO\Repositories\Indexable_Repository; class Outdated_Post_Indexables_Repository implements Outdated_Post_Indexables_Repository_Interface { - public function __construct( wpdb $wpdb ) { + /** + * @var \wpdb + */ + protected $wpdb; + /** + * @var Post_Type_Helper + */ + protected $post_type_helper; + /** + * @var Post_Helper + */ + protected $post_helper; + /** + * @var Indexable_Repository + */ + protected $indexable_repository; + + private $indexable_builder; + + public function __construct( + wpdb $wpdb, + Post_Type_Helper $post_type_helper, + Post_Helper $post_helper, + Indexable_Repository $indexable_repository, + Indexable_Builder $indexable_builder + ) { + $this->wpdb = $wpdb; + $this->post_type_helper = $post_type_helper; + $this->post_helper = $post_helper; + $this->indexable_repository = $indexable_repository; + $this->indexable_builder = $indexable_builder; } /** * @inheritDoc */ public function get_outdated_post_indexables( - Last_Batch_Count $count, - Plugin_Deactivated_Timestamp $deactivated_timestamp + Last_Batch_Count $count ): Outdated_Post_Indexables_List { $indexable_table = Model::get_table_name( 'Indexable' ); + + + $post_types = $this->post_type_helper->get_indexable_post_types(); + $excluded_post_statuses = $this->post_helper->get_excluded_post_statuses(); + $replacements = \array_merge( + $post_types, + $excluded_post_statuses + ); + + $limit_query = ''; + if ( $count->get_last_batch() ) { + $limit_query = 'LIMIT %d'; + $replacements[] = $count->get_last_batch(); + } + + // @phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber + $query = $this->wpdb->prepare( + " + SELECT i.* + FROM {$indexable_table} i + LEFT JOIN {$this->wpdb->posts} P on P.id = i.object_id + WHERE i.object_type='post' and object_last_modified <> P.post_modified_gmt + AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ') + AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ") + + $limit_query", + $replacements + ); + + $results = $this->wpdb->get_results( $query, ARRAY_A ); + $indexables = new Outdated_Post_Indexables_List(); + foreach ( $results as $result ) { + $indexables->add_post_indexable( $this->indexable_repository->query()->create( $result )); + } + + return $indexables; } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 3c0b256da42..ad732a883bd 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -74,8 +74,8 @@ public function __construct( */ public function register_hooks() { \add_action( - //Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, - 'admin_init', + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, + //'admin_init', [ $this, 'start_verify_non_timestamped_indexables', diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 2ad645efcd1..2ff7ba952be 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -66,7 +66,8 @@ public function __construct( */ public function register_hooks() { \add_action( - Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, + //Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, + 'admin_init', [ $this, 'start_verify_posts', From bca7ecd516d4816aa0bb94545357fa289257b9d2 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 19 Jun 2023 12:33:12 +0200 Subject: [PATCH 12/41] Make indexables update instead of insert by using the ORM to fetch the data instead of the create method. --- ...verify-post-indexables-command-handler.php | 2 +- .../outdated-post-indexables-repository.php | 38 +++++++------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index b69cb0edee4..d83e8cbbc89 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -48,7 +48,7 @@ public function __construct( */ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ): void { try { - $outdated_post_indexables_list = $this->outdated_post_indexables_repository->get_outdated_post_indexables( $verify_post_indexables_command->get_last_batch_count(), $verify_post_indexables_command->get_plugin_deactivated_at() ); + $outdated_post_indexables_list = $this->outdated_post_indexables_repository->get_outdated_post_indexables( $verify_post_indexables_command->get_last_batch_count() ); } catch ( No_Outdated_Posts_Found_Exception $exception ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 42de5846cbf..8e9da95efb0 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -58,37 +58,25 @@ public function get_outdated_post_indexables( $post_types = $this->post_type_helper->get_indexable_post_types(); $excluded_post_statuses = $this->post_helper->get_excluded_post_statuses(); - $replacements = \array_merge( - $post_types, - $excluded_post_statuses - ); + $query = $this->indexable_repository->query(); - $limit_query = ''; if ( $count->get_last_batch() ) { - $limit_query = 'LIMIT %d'; - $replacements[] = $count->get_last_batch(); + $query->limit( $count->get_last_batch() ); } - // @phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber - $query = $this->wpdb->prepare( - " - SELECT i.* - FROM {$indexable_table} i - LEFT JOIN {$this->wpdb->posts} P on P.id = i.object_id - WHERE i.object_type='post' and object_last_modified <> P.post_modified_gmt - AND P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ') - AND P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ") - - $limit_query", - $replacements - ); + $query->join( $this->wpdb->posts, "P.id = $indexable_table.object_id", 'P' ); + $query->where( 'object_type', 'post' ); + $query->where_raw( 'object_last_modified <> P.post_modified_gmt' ); + $query->where_raw( "P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ")", $post_types ); + $query->where_raw( "P.post_status NOT IN (" . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ")", $excluded_post_statuses ); - $results = $this->wpdb->get_results( $query, ARRAY_A ); - $indexables = new Outdated_Post_Indexables_List(); - foreach ( $results as $result ) { - $indexables->add_post_indexable( $this->indexable_repository->query()->create( $result )); + $indexables = $query->find_many(); + + $indexable_list = new Outdated_Post_Indexables_List(); + foreach ( $indexables as $indexable ) { + $indexable_list->add_post_indexable( $indexable ); } - return $indexables; + return $indexable_list; } } From bbf4fcb2d9750bda644f5549f72ff704dcc56c98 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 19 Jun 2023 15:06:57 +0200 Subject: [PATCH 13/41] Implement link builder. --- .../verify-indexable-action-factory.php | 16 ++- .../verify-term-links-indexables-action.php | 109 ++++++++++++++++++ 2 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/indexables/infrastructure/actions/verify-term-links-indexables-action.php diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index fb87d74dff3..0bb86deebed 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -8,8 +8,10 @@ use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; +use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Links_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; +use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action; class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory_Interface { @@ -27,22 +29,28 @@ class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory ]; /** - * @var \Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action + * @var Verify_General_Indexables_Action */ protected $verify_general_indexables_action; /** - * @var \Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action + * @var Verify_Post_Type_Archives_Indexables_Action */ protected $verify_post_type_archives_indexables_action; + /** + * @var Verify_Term_Links_Indexables_Action + */ + protected $verify_term_links_indexables_action; public function __construct( Verify_Term_Indexables_Action $verify_term_indexables_action, Verify_General_Indexables_Action $verify_general_indexables_action, - Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action + Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action, + Verify_Term_Links_Indexables_Action $verify_term_links_indexables_action ) { $this->verify_term_indexables_action = $verify_term_indexables_action; $this->verify_general_indexables_action = $verify_general_indexables_action; $this->verify_post_type_archives_indexables_action = $verify_post_type_archives_indexables_action; + $this->verify_term_links_indexables_action = $verify_term_links_indexables_action; } /** @@ -56,6 +64,8 @@ public function get( Current_Verification_Action $verification_action ): Verify_ return $this->verify_general_indexables_action; case'post-type-archives': return $this->verify_post_type_archives_indexables_action; + case 'term-links': + return $this->verify_term_links_indexables_action; default: throw new Verify_Action_Not_Found_Exception(); } diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php new file mode 100644 index 00000000000..192f92e7d1b --- /dev/null +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -0,0 +1,109 @@ +taxonomy = $taxonomy; + $this->repository = $repository; + $this->link_builder = $link_builder; + } + + /** + * @var \wpdb $wpdb The wp query. + */ + private $wpdb; + + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { + $query = $this->get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. + $terms = $this->wpdb->get_results( $query ); + + $term_list = \array_map( + static function ( $term ) { + return (object) [ + 'id' => (int) $term->term_id, + 'type' => 'term', + 'content' => $term->description, + ]; + }, + $terms + ); + + $indexables = []; + foreach ( $term_list as $term ) { + $indexable = $this->repository->find_by_id_and_type( $term->id, $term->type ); + if ( $indexable ) { + $this->link_builder->build( $indexable, $term->content ); + + $indexables[] = $indexable; + } + } + + return $batch_size->should_keep_going( \count( $indexables ) ); + } + + /** + * @param \wpdb $wpdb + * + * @return void + * @required + */ + public function set_wpdb( \wpdb $wpdb ) { + $this->wpdb = $wpdb; + } + + private function get_query( $limit, $batch_size ) { + $taxonomy_table = $this->wpdb->term_taxonomy; + $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); + $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); + + $replacements = []; + \array_push( $replacements, ...$public_taxonomies ); + + + $limit_query = 'LIMIT %d'; + $replacements[] = $batch_size; + $offset_query = ''; + if ( $limit !== 0 ) { + $offset_query = 'OFFSET %d'; + $replacements[] = ( $limit + $batch_size ); + } + + return $this->wpdb->prepare( + " + SELECT term_id, description + FROM {$taxonomy_table} AS T + WHERE taxonomy IN ($placeholders) + $limit_query $offset_query", + $replacements + ); + } +} From ea1d39302b39941490aa564dd944ed35d23328a1 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 19 Jun 2023 15:45:12 +0200 Subject: [PATCH 14/41] Lots 'o comments. --- .../verify-indexable-action-factory.php | 43 ++++++++++++++++--- ...on-timestamp-indexables-command-hander.php | 20 ++++++++- ...erify-non-timestamp-indexables-command.php | 8 +++- ...verify-post-indexables-command-handler.php | 27 ++++++++++-- .../verify-post-indexables-command.php | 2 - .../application/cron-verfication-gate.php | 4 +- .../next-verification-action-handler.php | 28 ++++++++++-- .../verification-cron-batch-handler.php | 2 + .../verification-cron-schedule-handler.php | 33 +++++++++++++- .../domain/abstract-indexables-command.php | 14 ++++++ ...fy-indexables-action-factory-interface.php | 24 ++++++++++- .../verify-indexables-action-interface.php | 5 ++- ...on-timestamped-objects-found-exception.php | 4 ++ .../no-outdated-posts-found-exception.php | 3 ++ .../no-verification-action-left-exception.php | 3 ++ .../verify-action-not-found-exception.php | 3 ++ 16 files changed, 199 insertions(+), 24 deletions(-) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 0bb86deebed..c8e2285db15 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -13,13 +13,14 @@ use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action; +/** + * + */ class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory_Interface { - /** - * @var Verify_Term_Indexables_Action + * The list of verification options. */ - protected $verify_term_indexables_action; private const VERIFICATION_MAPPING = [ 'term', 'general', @@ -27,20 +28,41 @@ class Verify_Indexable_Action_Factory implements Verify_Indexable_Action_Factory 'term_links', 'post_links', ]; + /** + * The Verify Term Indexable action instance. + * + * @var Verify_Term_Indexables_Action + */ + private $verify_term_indexables_action; /** + * The Verify General Indexables Action instance. + * * @var Verify_General_Indexables_Action */ - protected $verify_general_indexables_action; + private $verify_general_indexables_action; + /** + * The Verify Post Type Archives Indexables Action instance. + * * @var Verify_Post_Type_Archives_Indexables_Action */ - protected $verify_post_type_archives_indexables_action; + private $verify_post_type_archives_indexables_action; + /** + * The Verify Term Links Indexables Action instance. + * * @var Verify_Term_Links_Indexables_Action */ - protected $verify_term_links_indexables_action; + private $verify_term_links_indexables_action; + + /** + * @param Verify_Term_Indexables_Action $verify_term_indexables_action The instance. + * @param Verify_General_Indexables_Action $verify_general_indexables_action The instance. + * @param Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action The instance. + * @param Verify_Term_Links_Indexables_Action $verify_term_links_indexables_action The instance. + */ public function __construct( Verify_Term_Indexables_Action $verify_term_indexables_action, Verify_General_Indexables_Action $verify_general_indexables_action, @@ -54,7 +76,12 @@ public function __construct( } /** + * Finds the correct verification action for the given domain object. + * + * @param Current_Verification_Action $verification_action The Verification action. + * * @throws Verify_Action_Not_Found_Exception + * @return Verify_Indexables_Action_Interface */ public function get( Current_Verification_Action $verification_action ): Verify_Indexables_Action_Interface { switch ( $verification_action->get_action() ) { @@ -72,7 +99,9 @@ public function get( Current_Verification_Action $verification_action ): Verify_ } /** - * @param Current_Verification_Action $current_verification_action_object + * Determines the next verification action that needs to be taken. + * + * @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for. * * @throws No_Verification_Action_Left_Exception * @return Current_Verification_Action diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php index 45ebf481abc..dda95733b15 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php @@ -15,25 +15,41 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { /** + * The verify indexables action factory instance. + * * @var Verify_Indexable_Action_Factory_Interface */ protected $verify_indexable_action_factory; /** + * The cron batch handler instance. + * * @var Verification_Cron_Batch_Handler */ protected $cron_batch_handler; /** + * The next verification action handler. + * * @var Next_Verification_Action_Handler */ protected $action_handler; /** + * The verification cron schedule handler. + * * @var Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; + /** + * The constructor. + * + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param Verification_Cron_Batch_Handler $cron_batch_handler + * @param Verify_Indexable_Action_Factory_Interface $verify_indexable_action_factory + * @param Next_Verification_Action_Handler $action_handler + */ public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_handler, Verification_Cron_Batch_Handler $cron_batch_handler, @@ -47,7 +63,9 @@ public function __construct( } /** - * @param Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command + * Handles the Verify_Non_Timestamp_Indexables_Command command action. + * + * @param Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command The command. * * @return void */ diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index fafb78860ef..378ee21c5ee 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -6,6 +6,9 @@ use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; +/** + * + */ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Command { /** @@ -13,8 +16,9 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman */ private $current_action; - /** + * The constructor. + * * @param int $last_batch The last batch count. * @param string $plugin_deactivated_at The plugin deactivated at timestamp. * @param string $current_action The current verification action. @@ -26,6 +30,8 @@ public function __construct( int $last_batch, int $batch_size, string $plugin_de } /** + * Gets the current action. + * * @return Current_Verification_Action */ public function get_current_action(): Current_Verification_Action { diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index d83e8cbbc89..7537eaddb7e 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -9,27 +9,44 @@ use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; +/** + * Command handler class. + */ class Verify_Post_Indexables_Command_Handler { /** + * The Outdated_Post_Indexables_Repository_Interface instance. * @var Outdated_Post_Indexables_Repository_Interface */ protected $outdated_post_indexables_repository; + /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + * The Verification_Cron_Batch_Handler instance. + * @var Verification_Cron_Batch_Handler */ protected $verification_cron_batch_handler; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + * The Verification_Cron_Schedule_Handler instance. + * @var Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; /** - * @var \Yoast\WP\SEO\Builders\Indexable_Builder + * The Indexable_Builder instance. + * + * @var Indexable_Builder */ protected $indexable_builder; + /** + * The constructor. + * + * @param \Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository + * @param \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler $verification_cron_batch_handler + * @param \Yoast\WP\SEO\Builders\Indexable_Builder $indexable_builder + */ public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, Verification_Cron_Schedule_Handler $cron_schedule_handler, @@ -44,7 +61,9 @@ public function __construct( } /** - * @param Verify_Post_Indexables_Command $verify_post_indexables_command + * Handles the Verify_Post_Indexables_Command command. + * + * @param Verify_Post_Indexables_Command $verify_post_indexables_command The command. */ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ): void { try { diff --git a/src/indexables/application/commands/verify-post-indexables-command.php b/src/indexables/application/commands/verify-post-indexables-command.php index 8583151a28f..32f092977fc 100644 --- a/src/indexables/application/commands/verify-post-indexables-command.php +++ b/src/indexables/application/commands/verify-post-indexables-command.php @@ -8,6 +8,4 @@ class Verify_Post_Indexables_Command extends Abstract_Indexables_Command { - - } diff --git a/src/indexables/application/cron-verfication-gate.php b/src/indexables/application/cron-verfication-gate.php index 9cb32a9b7b3..be73caf8ef3 100644 --- a/src/indexables/application/cron-verfication-gate.php +++ b/src/indexables/application/cron-verfication-gate.php @@ -8,7 +8,9 @@ class Cron_Verification_Gate { /** - * @var \Yoast\WP\SEO\Helpers\Indexable_Helper + * + * + * @var Indexable_Helper */ protected $indexable_helper; diff --git a/src/indexables/application/next-verification-action-handler.php b/src/indexables/application/next-verification-action-handler.php index 58805d36852..12a385229fb 100644 --- a/src/indexables/application/next-verification-action-handler.php +++ b/src/indexables/application/next-verification-action-handler.php @@ -3,26 +3,46 @@ namespace Yoast\WP\SEO\Indexables\Application; use Yoast\WP\SEO\Helpers\Options_Helper; -use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; -use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; +/** + * The Next_Verification_Action_Handler class. + */ class Next_Verification_Action_Handler { /** + * The options helper instance. + * * @var Options_Helper */ protected $options_helper; + /** + * The constructor. + * + * @param Options_Helper $options_helper + */ public function __construct( Options_Helper $options_helper ) { $this->options_helper = $options_helper; } - public function get_current_verification_action():string { + /** + * Gets the cron_verify_current_action option. + * + * @return string + */ + public function get_current_verification_action(): string { return $this->options_helper->get( 'cron_verify_current_action', 'term' ); } - public function set_current_verification_action( Current_Verification_Action $current_verification_action ) { + /** + * Sets the cron_verify_current_action based on the current action. + * + * @param Current_Verification_Action $current_verification_action The current verification action. + * + * @return void + */ + public function set_current_verification_action( Current_Verification_Action $current_verification_action ): void { $this->options_helper->set( 'cron_verify_current_action', $current_verification_action->get_action() ); } } diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index 3f9530d0c2f..ec3120e935d 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -9,6 +9,8 @@ class Verification_Cron_Batch_Handler { /** + * The Options_Helper instance. + * * @var Options_Helper */ protected $options_helper; diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 0fa0b89d25f..8cba63ac8e7 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -2,23 +2,42 @@ namespace Yoast\WP\SEO\Indexables\Application; +/** + * The Verification_Cron_Schedule_Handler class. + */ class Verification_Cron_Schedule_Handler { - public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables'; + /** + * The name of the CRON job. + */ + public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables'; + + /** + * he name of the CRON job. + */ public const INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME = 'wpseo_indexable_verify_non_timestamped_indexables'; /** + * The Cron_Verification_Gate instance. + * * @var Cron_Verification_Gate */ private $cron_verification_gate; /** - * @param \Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate $cron_verification_gate + * The constructor. + * + * @param Cron_Verification_Gate $cron_verification_gate */ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { $this->cron_verification_gate = $cron_verification_gate; } + /** + * Schedules the indexable verification crons. + * + * @return void + */ public function schedule_indexable_verification(): void { if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { @@ -30,6 +49,11 @@ public function schedule_indexable_verification(): void { } } + /** + * Unschedules the indexable post verification cron. + * + * @return void + */ public function unschedule_verify_post_indexables_cron() { $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); if ( $scheduled ) { @@ -37,6 +61,11 @@ public function unschedule_verify_post_indexables_cron() { } } + /** + * Unschedules the non timestamped cron. + * + * @return void + */ public function unschedule_verify_non_timestamped_indexables_cron() { $scheduled = \wp_next_scheduled( self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); if ( $scheduled ) { diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index a0a3d51c59c..6219fd6fd8d 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -2,14 +2,21 @@ namespace Yoast\WP\SEO\Indexables\Domain; + +/** + * The abstract indexables command class. + */ abstract class Abstract_Indexables_Command { /** + * The last batch count domain object. + * * @var Last_Batch_Count $last_batch_count */ protected $last_batch_count; /** + * The plugin deactivated timestamp domain object. * @var Plugin_Deactivated_Timestamp $plugin_deactivated_at */ protected $plugin_deactivated_at; @@ -20,6 +27,8 @@ abstract class Abstract_Indexables_Command { private $batch_size; /** + * The constructor. + * * @param int $last_batch The last batch count. * @param string $plugin_deactivated_at The plugin deactivated at timestamp. */ @@ -30,6 +39,7 @@ public function __construct(int $batch_size, int $last_batch, string $plugin_dea } /** + * Gets the last batch count domain object. * @return Last_Batch_Count */ public function get_last_batch_count(): Last_Batch_Count { @@ -37,6 +47,8 @@ public function get_last_batch_count(): Last_Batch_Count { } /** + * Gets the plugin deactivated at timestamp. + * * @return Plugin_Deactivated_Timestamp */ public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { @@ -45,6 +57,8 @@ public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { /** + * Gets the batch size. + * * @return Batch_Size */ public function get_batch_size(): Batch_Size { diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index c21cdd48f9c..c5c532e48a1 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -3,10 +3,32 @@ namespace Yoast\WP\SEO\Indexables\Domain\Actions; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; +use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; +use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; +/** + * The Verify_Indexable_Action_Factory_Interface interface. + */ interface Verify_Indexable_Action_Factory_Interface { + + /** + * Finds the correct verification action for the given domain object. + * + * @param Current_Verification_Action $verification_action The Verification action. + * + * @throws Verify_Action_Not_Found_Exception + * @return Verify_Indexables_Action_Interface + */ public function get( Current_Verification_Action $verification_action ):Verify_Indexables_Action_Interface; - public function determine_next_verify_action( Current_Verification_Action $current_verification_action ):Current_Verification_Action; + /** + * Determines the next verification action that needs to be taken. + * + * @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for. + * + * @throws No_Verification_Action_Left_Exception + * @return Current_Verification_Action + */ + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ):Current_Verification_Action; } diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 7cc243407eb..14cc26df985 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -6,6 +6,9 @@ use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Models\Indexable; +/** + * The Verify_Indexables_Action_Interface interface. + */ interface Verify_Indexables_Action_Interface { /** @@ -17,7 +20,7 @@ interface Verify_Indexables_Action_Interface { public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size):bool; /** - * @param \wpdb $wpdb + * @param \wpdb $wpdb The wpdb instance. * * @return mixed * @required diff --git a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php index 93d27afe181..80e2756ed92 100644 --- a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php +++ b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php @@ -2,6 +2,10 @@ namespace Yoast\WP\SEO\Indexables\Domain\Exceptions; + +/** + * The No_Non_Timestamped_Objects_Found_Exception exception. + */ class No_Non_Timestamped_Objects_Found_Exception extends \Exception { /** diff --git a/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php index 004a71eaa2f..767353d4fee 100644 --- a/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php +++ b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php @@ -4,6 +4,9 @@ use Exception; +/** + * The No_Outdated_Posts_Found_Exception exception. + */ class No_Outdated_Posts_Found_Exception extends Exception { /** diff --git a/src/indexables/domain/exceptions/no-verification-action-left-exception.php b/src/indexables/domain/exceptions/no-verification-action-left-exception.php index e1a67128069..82b16eeebcd 100644 --- a/src/indexables/domain/exceptions/no-verification-action-left-exception.php +++ b/src/indexables/domain/exceptions/no-verification-action-left-exception.php @@ -2,6 +2,9 @@ namespace Yoast\WP\SEO\Indexables\Domain\Exceptions; +/** + * The No_Verification_Action_Left_Exception exception. + */ class No_Verification_Action_Left_Exception extends \Exception { /** diff --git a/src/indexables/domain/exceptions/verify-action-not-found-exception.php b/src/indexables/domain/exceptions/verify-action-not-found-exception.php index a30ab85d457..bc849816f9f 100644 --- a/src/indexables/domain/exceptions/verify-action-not-found-exception.php +++ b/src/indexables/domain/exceptions/verify-action-not-found-exception.php @@ -2,6 +2,9 @@ namespace Yoast\WP\SEO\Indexables\Domain\Exceptions; +/** + * A named exception. + */ class Verify_Action_Not_Found_Exception extends \Exception { } From ecaa0d93799d08df2489cd4a01af5eee466c127a Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 20 Jun 2023 13:26:15 +0200 Subject: [PATCH 15/41] CS. --- .../verify-indexable-action-factory.php | 10 ++-- ...on-timestamp-indexables-command-hander.php | 26 ++++----- ...erify-non-timestamp-indexables-command.php | 3 +- ...verify-post-indexables-command-handler.php | 13 +++-- .../verify-post-indexables-command.php | 6 +- .../application/cron-verfication-gate.php | 7 ++- .../next-verification-action-handler.php | 2 +- ...d-post-indexables-repository-interface.php | 2 +- .../domain/abstract-indexables-command.php | 15 +++-- ...fy-indexables-action-factory-interface.php | 5 +- .../verify-indexables-action-interface.php | 7 ++- ...on-timestamped-objects-found-exception.php | 2 +- .../no-outdated-posts-found-exception.php | 1 + .../no-verification-action-left-exception.php | 1 + .../verify-action-not-found-exception.php | 1 + .../domain/outdated-post-indexables-list.php | 45 +++++++++++++++ .../domain/plugin-deactivated-timestamp.php | 6 +- .../verify-general-indexables-action.php | 41 ++++++++++--- ...y-post-type-archives-indexables-action.php | 57 +++++++++++++++---- .../actions/verify-term-indexables-action.php | 57 +++++++++++++++---- .../verify-term-links-indexables-action.php | 41 ++++++++++--- .../outdated-post-indexables-repository.php | 49 +++++++++++----- .../mark-deactivation-integration.php | 3 + ...schedule-verification-cron-integration.php | 16 ++++-- ...no-timestamp-cron-callback-integration.php | 39 ++++++++++--- ...cation-posts-cron-callback-integration.php | 54 ++++++++++++------ 26 files changed, 383 insertions(+), 126 deletions(-) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index c8e2285db15..68fa0816532 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -1,8 +1,8 @@ verify_term_indexables_action; case 'general': return $this->verify_general_indexables_action; - case'post-type-archives': + case 'post-type-archives': return $this->verify_post_type_archives_indexables_action; case 'term-links': return $this->verify_term_links_indexables_action; diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php index dda95733b15..ea231034524 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php @@ -6,7 +6,7 @@ use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexable_Action_Factory_Interface; +use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Factory_Interface; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; @@ -17,9 +17,9 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { /** * The verify indexables action factory instance. * - * @var Verify_Indexable_Action_Factory_Interface + * @var Verify_Indexables_Action_Factory_Interface */ - protected $verify_indexable_action_factory; + protected $verify_indexables_action_factory; /** * The cron batch handler instance. @@ -45,20 +45,20 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { /** * The constructor. * - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param Verification_Cron_Batch_Handler $cron_batch_handler - * @param Verify_Indexable_Action_Factory_Interface $verify_indexable_action_factory - * @param Next_Verification_Action_Handler $action_handler + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param Verification_Cron_Batch_Handler $cron_batch_handler + * @param Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory + * @param Next_Verification_Action_Handler $action_handler */ public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_handler, Verification_Cron_Batch_Handler $cron_batch_handler, - Verify_Indexable_Action_Factory_Interface $verify_indexable_action_factory, + Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory, Next_Verification_Action_Handler $action_handler ) { $this->cron_schedule_handler = $cron_schedule_handler; $this->cron_batch_handler = $cron_batch_handler; - $this->verify_indexable_action_factory = $verify_indexable_action_factory; + $this->verify_indexables_action_factory = $verify_indexables_action_factory; $this->action_handler = $action_handler; } @@ -72,13 +72,13 @@ public function __construct( public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { try { - $verification_action = $this->verify_indexable_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); - }catch(Verify_Action_Not_Found_Exception $exception){ + $verification_action = $this->verify_indexables_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); + }catch ( Verify_Action_Not_Found_Exception $exception ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); return; } - $has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); + $has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); // for each fix if ( $has_more_to_index ) { $this->cron_batch_handler->set_current_non_timestamped_indexables_batch( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); @@ -86,7 +86,7 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time return; } try { - $next_action = $this->verify_indexable_action_factory->determine_next_verify_action( $verify_non_timestamp_indexables_command->get_current_action() ); + $next_action = $this->verify_indexables_action_factory->determine_next_verify_action( $verify_non_timestamp_indexables_command->get_current_action() ); $this->action_handler->set_current_verification_action( $next_action ); $this->cron_batch_handler->set_current_non_timestamped_indexables_batch( new Last_Batch_Count( 0 ), new Batch_Size( 0 ) ); } catch ( No_Verification_Action_Left_Exception $exception ) { diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index 378ee21c5ee..a13b71c836d 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -26,7 +26,7 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman public function __construct( int $last_batch, int $batch_size, string $plugin_deactivated_at, string $current_action ) { $this->current_action = new Current_Verification_Action( $current_action ); - parent::__construct($batch_size, $last_batch, $plugin_deactivated_at ); + parent::__construct( $batch_size, $last_batch, $plugin_deactivated_at ); } /** @@ -37,5 +37,4 @@ public function __construct( int $last_batch, int $batch_size, string $plugin_de public function get_current_action(): Current_Verification_Action { return $this->current_action; } - } diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index 7537eaddb7e..4d0ffdf3523 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -16,18 +16,21 @@ class Verify_Post_Indexables_Command_Handler { /** * The Outdated_Post_Indexables_Repository_Interface instance. + * * @var Outdated_Post_Indexables_Repository_Interface */ protected $outdated_post_indexables_repository; /** * The Verification_Cron_Batch_Handler instance. + * * @var Verification_Cron_Batch_Handler */ protected $verification_cron_batch_handler; /** * The Verification_Cron_Schedule_Handler instance. + * * @var Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; @@ -42,10 +45,10 @@ class Verify_Post_Indexables_Command_Handler { /** * The constructor. * - * @param \Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository - * @param \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler $verification_cron_batch_handler - * @param \Yoast\WP\SEO\Builders\Indexable_Builder $indexable_builder + * @param Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler + * @param Verification_Cron_Batch_Handler $verification_cron_batch_handler + * @param Indexable_Builder $indexable_builder */ public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, @@ -85,7 +88,7 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c return; } - $next_batch = $verify_post_indexables_command->get_last_batch_count()->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size(); + $next_batch = ( $verify_post_indexables_command->get_last_batch_count()->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size() ); $this->verification_cron_batch_handler->set_current_post_indexables_batch( $next_batch ); } } diff --git a/src/indexables/application/commands/verify-post-indexables-command.php b/src/indexables/application/commands/verify-post-indexables-command.php index 32f092977fc..c7c5b0cc074 100644 --- a/src/indexables/application/commands/verify-post-indexables-command.php +++ b/src/indexables/application/commands/verify-post-indexables-command.php @@ -1,11 +1,15 @@ indexable_helper = $indexable_helper; diff --git a/src/indexables/application/next-verification-action-handler.php b/src/indexables/application/next-verification-action-handler.php index 12a385229fb..030b300c81a 100644 --- a/src/indexables/application/next-verification-action-handler.php +++ b/src/indexables/application/next-verification-action-handler.php @@ -20,7 +20,7 @@ class Next_Verification_Action_Handler { /** * The constructor. * - * @param Options_Helper $options_helper + * @param Options_Helper $options_helper The options helper. */ public function __construct( Options_Helper $options_helper ) { $this->options_helper = $options_helper; diff --git a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php index ab271aaa8d1..25d7e27ba43 100644 --- a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php +++ b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php @@ -13,7 +13,7 @@ interface Outdated_Post_Indexables_Repository_Interface { * Finds a list of posts for which the indexables are not up to date. * This is done by checking if the updated at of the post is the same as the indexable. * - * @param Last_Batch_Count $count + * @param Last_Batch_Count $count * * @throws No_Outdated_Posts_Found_Exception When there are no outdated posts found. * @return Outdated_Post_Indexables_List diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index 6219fd6fd8d..58f4e320150 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Indexables\Domain; - /** * The abstract indexables command class. */ @@ -17,29 +16,34 @@ abstract class Abstract_Indexables_Command { /** * The plugin deactivated timestamp domain object. + * * @var Plugin_Deactivated_Timestamp $plugin_deactivated_at */ protected $plugin_deactivated_at; /** - * @var Batch_Size $batch_size The batch size. + * The batch size. + * + * @var Batch_Size $batch_size */ private $batch_size; /** * The constructor. * - * @param int $last_batch The last batch count. + * @param int $batch_size The batch size. + * @param int $last_batch The last batch count. * @param string $plugin_deactivated_at The plugin deactivated at timestamp. */ - public function __construct(int $batch_size, int $last_batch, string $plugin_deactivated_at ) { + public function __construct( int $batch_size, int $last_batch, string $plugin_deactivated_at ) { $this->last_batch_count = new Last_Batch_Count( $last_batch ); $this->plugin_deactivated_at = new Plugin_Deactivated_Timestamp( $plugin_deactivated_at ); - $this->batch_size = new Batch_Size( $batch_size ); + $this->batch_size = new Batch_Size( $batch_size ); } /** * Gets the last batch count domain object. + * * @return Last_Batch_Count */ public function get_last_batch_count(): Last_Batch_Count { @@ -55,7 +59,6 @@ public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { return $this->plugin_deactivated_at; } - /** * Gets the batch size. * diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index c5c532e48a1..b091d5c26c7 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -7,10 +7,9 @@ use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; /** - * The Verify_Indexable_Action_Factory_Interface interface. + * The Verify_Indexables_Action_Factory_Interface interface. */ -interface Verify_Indexable_Action_Factory_Interface { - +interface Verify_Indexables_Action_Factory_Interface { /** * Finds the correct verification action for the given domain object. diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 14cc26df985..98fc1eb3b27 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -1,5 +1,6 @@ $post_indexables_list */ private $post_indexables_list; + /** + * The current array position. + * @var int + */ private $position = 0; + /** + * The constructor. + */ public function __construct() { $this->post_indexables_list = []; } + /** + * Add an indexable to the list. + * + * @param Indexable $post The indexable. + * + * @return void + */ public function add_post_indexable( Indexable $post ) { $this->post_indexables_list[] = $post; } + /** + * Rewinds the array position. + * @return void + */ public function rewind(): void { $this->position = 0; } + /** + * The current item selected. + * + * @return Indexable + */ public function current(): Indexable { return $this->post_indexables_list[ $this->position ]; } + /** + * The current key. + * @return int + */ public function key(): int { return $this->position; } + /** + * Go to the next position. + * + * @return void + */ public function next(): void { ++$this->position; } + /** + * Is the current position valid. + * @return bool + */ public function valid(): bool { return isset( $this->post_indexables_list[ $this->position ] ); } + /** + * Returns the size of the array. + * @return int + */ public function count():int { return \count( $this->post_indexables_list ); } diff --git a/src/indexables/domain/plugin-deactivated-timestamp.php b/src/indexables/domain/plugin-deactivated-timestamp.php index 908c316ab92..83f6817dc56 100644 --- a/src/indexables/domain/plugin-deactivated-timestamp.php +++ b/src/indexables/domain/plugin-deactivated-timestamp.php @@ -2,6 +2,10 @@ namespace Yoast\WP\SEO\Indexables\Domain; + +/** + * The Plugin_Deactivated_Timestamp class. + */ class Plugin_Deactivated_Timestamp { /** @@ -14,7 +18,7 @@ class Plugin_Deactivated_Timestamp { /** * The constructor. * - * @param string $timestamp + * @param string $timestamp The timestamp. */ public function __construct( string $timestamp ) { $this->timestamp = $timestamp; diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index e4feb5b2782..5f4c6e4acfa 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -8,46 +8,71 @@ use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Repositories\Indexable_Repository; +/** + * The Verify_General_Indexables_Action class. + */ class Verify_General_Indexables_Action implements Verify_Indexables_Action_Interface { - /** - * @var \Yoast\WP\SEO\Repositories\Indexable_Repository + * The indexable repository instance. + * + * @var Indexable_Repository */ protected $repository; + /** - * @var \Yoast\WP\SEO\Builders\Indexable_Builder + * The indexable builder instance. + * + * @var Indexable_Builder */ protected $indexable_builder; + /** + * The constructor. + * + * @param Indexable_Repository $repository The indexable repository. + * @param Indexable_Builder $indexable_builder The indexable builder. + */ public function __construct( Indexable_Repository $repository, Indexable_Builder $indexable_builder ) { $this->repository = $repository; $this->indexable_builder = $indexable_builder; } /** - * @var \wpdb $wpdb The wp query. + * The wp query. + * + * @var \wpdb $wpdb */ private $wpdb; + /** + * Rebuilds the indexables for the general pages. + * + * @param Last_Batch_Count $last_batch_count The last batch count domain object. + * @param Batch_Size $batch_size The batch size domain object. + * + * @return bool + */ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { - $system_page = $this->repository->find_for_system_page( '404',false ); + $system_page = $this->repository->find_for_system_page( '404', false ); $this->indexable_builder->build_for_system_page( '404', $system_page ); - $search_result = $this->repository->find_for_system_page( 'search-result',false ); + $search_result = $this->repository->find_for_system_page( 'search-result', false ); $this->indexable_builder->build_for_system_page( 'search-result', $search_result ); - $date_archive = $this->repository->find_for_date_archive(false); + $date_archive = $this->repository->find_for_date_archive( false ); $this->indexable_builder->build_for_date_archive( $date_archive ); - $home_page = $this->repository->find_for_home_page(false); + $home_page = $this->repository->find_for_home_page( false ); $this->indexable_builder->build_for_home_page( $home_page ); return false; } /** + * Sets the wpdb instance. + * * @param \wpdb $wpdb * * @return void diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php index 3b5b9da6def..2e38bb93286 100644 --- a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -1,5 +1,6 @@ post_type_helper = $post_type_helper; - $this->indexable_builder = $indexable_builder; + $this->post_type_helper = $post_type_helper; + $this->indexable_builder = $indexable_builder; $this->indexable_repository = $indexable_repository; } + /** + * Rebuilds the indexables for post type archives. + * + * @param Last_Batch_Count $last_batch_count The last batch count domain object. + * @param Batch_Size $batch_size The batch size domain object. + * + * @return bool + */ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { $archives = $this->post_type_helper->get_indexable_post_archives(); - $archives = \array_slice( $archives, $last_batch_count->get_last_batch(), $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); + $archives = \array_slice( $archives, $last_batch_count->get_last_batch(), ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ) ); $indexables = []; foreach ( $archives as $post_type_archive ) { - $archive_indexable = $this->indexable_repository->find_for_post_type_archive($post_type_archive, false); - $indexables[] = $this->indexable_builder->build_for_post_type_archive( $post_type_archive,$archive_indexable ); + $archive_indexable = $this->indexable_repository->find_for_post_type_archive( $post_type_archive, false ); + $indexables[] = $this->indexable_builder->build_for_post_type_archive( $post_type_archive, $archive_indexable ); } return $batch_size->should_keep_going( \count( $indexables ) ); } /** - * @param \wpdb $wpdb + * Sets the wpdb instance. + * + * @param \wpdb $wpdb The wpdb instance. * * @return void * @required diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 887dfd887e4..ea69591aed8 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -1,5 +1,6 @@ taxonomy = $taxonomy; $this->repository = $repository; } /** - * @var \wpdb $wpdb The wp query. + * The wp query. + * + * @var \wpdb $wpdb */ private $wpdb; + /** + * Re builds indexables for term indexables. + * + * @param Last_Batch_Count $last_batch_count The last batch count domain object. + * @param Batch_Size $batch_size The batch size domain object. + * + * @return bool + */ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { $query = $this->get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); @@ -45,7 +69,9 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S } /** - * @param \wpdb $wpdb + * Sets the wpdb instance. + * + * @param \wpdb $wpdb The wpdb instance. * * @return void * @required @@ -54,6 +80,14 @@ public function set_wpdb( \wpdb $wpdb ) { $this->wpdb = $wpdb; } + /** + * Creates the query to get all the taxonomies. + * + * @param int $limit The query limit. + * @param int $batch_size The batch size for the queries. + * + * @return string|null + */ private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); @@ -62,13 +96,12 @@ private function get_query( $limit, $batch_size ) { $replacements = []; \array_push( $replacements, ...$public_taxonomies ); - $limit_query = 'LIMIT %d'; - $replacements[] = $batch_size ; - $offset_query = ''; - if($limit !== 0){ - $offset_query = 'OFFSET %d'; - $replacements[] = ( $limit + $batch_size );} + $replacements[] = $batch_size; + $offset_query = ''; + if ( $limit !== 0 ) { + $offset_query = 'OFFSET %d'; + $replacements[] = ( $limit + $batch_size );} return $this->wpdb->prepare( " diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index 192f92e7d1b..2da797b674f 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -12,18 +12,30 @@ class Verify_Term_Links_Indexables_Action implements Verify_Indexables_Action_Interface { /** - * @var \Yoast\WP\SEO\Helpers\Taxonomy_Helper + * The taxonomy helper. + * + * @var Taxonomy_Helper */ - protected $taxonomy; + private $taxonomy; /** - * @var \Yoast\WP\SEO\Repositories\Indexable_Repository + * The indexable repository. + * + * @var Indexable_Repository */ - protected $repository; + private $repository; + /** - * @var \Yoast\WP\SEO\Builders\Indexable_Link_Builder + * The indexable link builder. + * + * @var Indexable_Link_Builder */ - protected $link_builder; + private $link_builder; + + /** + * @var \wpdb $wpdb The wp query. + */ + private $wpdb; public function __construct( Taxonomy_Helper $taxonomy, @@ -36,10 +48,13 @@ public function __construct( } /** - * @var \wpdb $wpdb The wp query. + * Re builds indexables for term links. + * + * @param Last_Batch_Count $last_batch_count The last batch count domain object. + * @param Batch_Size $batch_size The batch size domain object. + * + * @return bool */ - private $wpdb; - public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { $query = $this->get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); @@ -80,6 +95,14 @@ public function set_wpdb( \wpdb $wpdb ) { $this->wpdb = $wpdb; } + /** + * Creates the query to get all the taxonomy link options. + * + * @param int $limit The query limit. + * @param int $batch_size The batch size for the queries. + * + * @return string|null + */ private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 8e9da95efb0..94cfca10aaa 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -1,10 +1,9 @@ wpdb = $wpdb; $this->post_type_helper = $post_type_helper; $this->post_helper = $post_helper; $this->indexable_repository = $indexable_repository; - $this->indexable_builder = $indexable_builder; } /** - * @inheritDoc + * The get outdated post indexables + * + * @param Last_Batch_Count $count The last batch count domain object. + * + * @return Outdated_Post_Indexables_List */ public function get_outdated_post_indexables( Last_Batch_Count $count @@ -67,8 +88,8 @@ public function get_outdated_post_indexables( $query->join( $this->wpdb->posts, "P.id = $indexable_table.object_id", 'P' ); $query->where( 'object_type', 'post' ); $query->where_raw( 'object_last_modified <> P.post_modified_gmt' ); - $query->where_raw( "P.post_type IN (" . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ")", $post_types ); - $query->where_raw( "P.post_status NOT IN (" . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ")", $excluded_post_statuses ); + $query->where_raw( 'P.post_type IN (' . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ')', $post_types ); + $query->where_raw( 'P.post_status NOT IN (' . \implode( ', ', \array_fill( 0, \count( $excluded_post_statuses ), '%s' ) ) . ')', $excluded_post_statuses ); $indexables = $query->find_many(); diff --git a/src/indexables/user-interface/mark-deactivation-integration.php b/src/indexables/user-interface/mark-deactivation-integration.php index 1258ce4ddc2..6980f9b9e96 100644 --- a/src/indexables/user-interface/mark-deactivation-integration.php +++ b/src/indexables/user-interface/mark-deactivation-integration.php @@ -15,6 +15,9 @@ class Mark_Deactivation_Integration implements Integration_Interface { use Admin_Conditional_Trait; + /** + * The plugin deactivated at option name. + */ public const PLUGIN_DEACTIVATED_AT_OPTION = 'plugin_deactivated_at'; /** diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index 81fa24f8805..ae7a7b80884 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -15,9 +15,17 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { use Admin_Conditional_Trait; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + * The verification cron schedule handler. + * @var Verification_Cron_Schedule_Handler */ protected $cron_schedule_handler; + + + /** + * The options helper. + * + * @var Options_Helper + */ private $options_helper; /** @@ -25,13 +33,13 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { * * @param Options_Helper $options_helper The options helper. */ - public function __construct( Options_Helper $options_helper,Verification_Cron_Schedule_Handler $cron_schedule_handler) { - $this->options_helper = $options_helper; + public function __construct( Options_Helper $options_helper, Verification_Cron_Schedule_Handler $cron_schedule_handler ) { + $this->options_helper = $options_helper; $this->cron_schedule_handler = $cron_schedule_handler; } /** - * @inheritDoc + * Registers the action with WordPress. */ public function register_hooks() { if ( $this->options_helper->get( 'first_time_install', false ) === false ) { diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index ad732a883bd..08173eba050 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -12,46 +12,64 @@ use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; -class Verification_Cron_Callback_Integration implements Integration_Interface { +/** + * The Verification_Cron_Callback_Integration class. + */ +class Verification_No_Timestamp_Cron_Callback_Integration implements Integration_Interface { use Admin_Conditional_Trait; /** + * The cron scheduler handler instance. + * * @var Verification_Cron_Schedule_Handler */ protected $cron_schedule_handler; /** + * The options helper instance. + * * @var Options_Helper */ protected $options_helper; /** + * The verification cron batch handler. + * * @var Verification_Cron_Batch_Handler */ protected $cron_batch_handler; /** + * The non timestamp command handler. + * * @var Verify_Non_Timestamp_Indexables_Command_Handler */ protected $non_timestamp_indexables_command_handler; /** + * The next verification action handler instance. + * * @var Next_Verification_Action_Handler */ protected $verification_action_handler; /** + * The cron verification gate instance. + * * @var Cron_Verification_Gate */ private $cron_verification_gate; /** - * @param Cron_Verification_Gate $cron_verification_gate - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param Options_Helper $options_helper - * @param Verification_Cron_Batch_Handler $cron_batch_handler - * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler + * The constructor. + * + * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. + * @param Options_Helper $options_helper The options helper. + * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. + * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler The non timestamp indexables command handler. + * @param Next_Verification_Action_Handler $verification_action_handler The verification action handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, @@ -70,12 +88,12 @@ public function __construct( } /** - * @inheritDoc + * Registers the hooks with WordPress. */ public function register_hooks() { \add_action( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, - //'admin_init', + // 'admin_init', [ $this, 'start_verify_non_timestamped_indexables', @@ -83,6 +101,11 @@ public function register_hooks() { ); } + /** + * Start the non timestamp cron handler callback. + * + * @return void + */ public function start_verify_non_timestamped_indexables() { if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 2ff7ba952be..4743de65022 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -11,41 +11,59 @@ use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; + +/** + * The Verification_Posts_Cron_Callback_Integration class. + */ class Verification_Posts_Cron_Callback_Integration implements Integration_Interface { use Admin_Conditional_Trait; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + * The verification cron schedule handler instance. + * + * @var Verification_Cron_Schedule_Handler $cron_schedule_handler */ - protected $cron_schedule_handler; + private $cron_schedule_handler; /** - * @var \Yoast\WP\SEO\Helpers\Options_Helper + * The options helper instance. + * + * @var Options_Helper $options_helper */ - protected $options_helper; + private $options_helper; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + * The cron batch handler instance. + * + * @var Verification_Cron_Batch_Handler $cron_batch_handler */ - protected $cron_batch_handler; + private $cron_batch_handler; /** - * @var \Yoast\WP\SEO\Indexables\Application\Verify_Post_Indexables_Command_Handler + * The verify post indexables command handler. + * + * @var Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler */ - protected $verify_post_indexables_command_handler; + private $verify_post_indexables_command_handler; /** + * The cron verification gate instance. + * * @var Cron_Verification_Gate */ private $cron_verification_gate; /** - * @param Cron_Verification_Gate $cron_verification_gate - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler - * @param Options_Helper $options_helper - * @param Verification_Cron_Batch_Handler $cron_batch_handler - * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler + * The constructor. + * + * @param Cron_Verification_Gate $cron_verification_gate The cron verification + * gate. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. + * @param Options_Helper $options_helper The options helper. + * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. + * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler The verify post indexables + * command handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, @@ -62,12 +80,11 @@ public function __construct( } /** - * @inheritDoc + * Registers the hooks with WordPress. */ public function register_hooks() { \add_action( - //Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, - 'admin_init', + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, [ $this, 'start_verify_posts', @@ -75,6 +92,11 @@ public function register_hooks() { ); } + /** + * Starts the post verification post cron handlers. + * + * @return void + */ public function start_verify_posts(): void { if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); From 572778870adf303d55519e4b1d4cba37e7a4884f Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 21 Jun 2023 08:38:53 +0200 Subject: [PATCH 16/41] CS... --- .../verify-indexable-action-factory.php | 13 +++++--- ...-timestamp-indexables-command-handler.php} | 21 +++++++----- ...erify-non-timestamp-indexables-command.php | 9 +++-- ...verify-post-indexables-command-handler.php | 10 +++--- ...on-gate.php => cron-verification-gate.php} | 0 ...d-post-indexables-repository-interface.php | 3 +- .../verification-cron-batch-handler.php | 33 +++++++++++++++++++ .../verification-cron-schedule-handler.php | 4 +-- ...fy-indexables-action-factory-interface.php | 7 ++-- .../verify-indexables-action-interface.php | 2 ++ src/indexables/domain/batch-size.php | 20 +++++++++-- .../domain/current-verification-action.php | 11 ++++++- ...on-timestamped-objects-found-exception.php | 2 ++ .../domain/outdated-post-indexables-list.php | 5 +++ .../domain/plugin-deactivated-timestamp.php | 1 - .../verify-general-indexables-action.php | 5 +-- .../actions/verify-term-indexables-action.php | 6 ++-- .../verify-term-links-indexables-action.php | 26 +++++++++++---- .../outdated-post-indexables-repository.php | 2 +- ...schedule-verification-cron-integration.php | 5 +-- ...no-timestamp-cron-callback-integration.php | 1 + 21 files changed, 141 insertions(+), 45 deletions(-) rename src/indexables/application/commands/{verify-non-timestamp-indexables-command-hander.php => verify-non-timestamp-indexables-command-handler.php} (80%) rename src/indexables/application/{cron-verfication-gate.php => cron-verification-gate.php} (100%) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 68fa0816532..0e938ab362a 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -1,5 +1,6 @@ get_action(); - if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING ) ) { - $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING ); + if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING, true ) ) { + $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING, true ); if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) { return new Current_Verification_Action( self::VERIFICATION_MAPPING[ $key ] ); } diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php similarity index 80% rename from src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php rename to src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php index ea231034524..3bcceb0edc4 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-hander.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php @@ -1,6 +1,6 @@ cron_schedule_handler = $cron_schedule_handler; - $this->cron_batch_handler = $cron_batch_handler; + $this->cron_schedule_handler = $cron_schedule_handler; + $this->cron_batch_handler = $cron_batch_handler; $this->verify_indexables_action_factory = $verify_indexables_action_factory; - $this->action_handler = $action_handler; + $this->action_handler = $action_handler; } /** @@ -79,7 +83,6 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time } $has_more_to_index = $verification_action->re_build_indexables( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); - // for each fix if ( $has_more_to_index ) { $this->cron_batch_handler->set_current_non_timestamped_indexables_batch( $verify_non_timestamp_indexables_command->get_last_batch_count(), $verify_non_timestamp_indexables_command->get_batch_size() ); diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index a13b71c836d..8ac85505075 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -1,5 +1,5 @@ options_helper = $options_helper; } + /** + * Gets the `cron_verify_post_indexables_last_batch` option + * + * @return int + */ public function get_current_post_indexables_batch():int { return $this->options_helper->get( 'cron_verify_post_indexables_last_batch', 0 ); } + /** + * Sets the `cron_verify_post_indexables_last_batch` option + * + * @param int $batch_count The batch count. + * + * @return void + */ public function set_current_post_indexables_batch( int $batch_count ) { $this->options_helper->set( 'cron_verify_post_indexables_last_batch', $batch_count ); } + /** + * Gets the `cron_verify_non_timestamped_indexables_last_batch` option + * + * @return int + */ public function get_current_non_timestamped_indexables_batch():int { return $this->options_helper->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 ); } + /** + * Sets the `cron_verify_non_timestamped_indexables_last_batch` option. + * + * @param Last_Batch_Count $last_batch_count The current batch count. + * @param Batch_Size $batch_size The batch size. + * + * @return void + */ public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ) { $batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); $this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count ); diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 8cba63ac8e7..7415a726998 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -13,7 +13,7 @@ class Verification_Cron_Schedule_Handler { public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables'; /** - * he name of the CRON job. + * The name of the CRON job. */ public const INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME = 'wpseo_indexable_verify_non_timestamped_indexables'; @@ -27,7 +27,7 @@ class Verification_Cron_Schedule_Handler { /** * The constructor. * - * @param Cron_Verification_Gate $cron_verification_gate + * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. */ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { $this->cron_verification_gate = $cron_verification_gate; diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index b091d5c26c7..e9ab5f46e32 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -1,5 +1,6 @@ batch_size = $batch_size; } /** + * Returns the batch size. + * * @return int */ public function get_batch_size(): int { return $this->batch_size; } + /** + * Checks if the batch is bigger than the count. + * + * @param int|null $count The count to check. + * + * @return bool + */ public function should_keep_going( ?int $count ): bool { return $count >= $this->get_batch_size(); } diff --git a/src/indexables/domain/current-verification-action.php b/src/indexables/domain/current-verification-action.php index 339652b018b..96c866352e0 100644 --- a/src/indexables/domain/current-verification-action.php +++ b/src/indexables/domain/current-verification-action.php @@ -2,21 +2,30 @@ namespace Yoast\WP\SEO\Indexables\Domain; +/** + * The Current_Verification_Action class. + */ class Current_Verification_Action { /** + * The current action. + * * @var string $action */ private $action; /** - * @param string $action + * The constructor. + * + * @param string $action The current action. */ public function __construct( string $action ) { $this->action = $action; } /** + * Gets the current action. + * * @return string */ public function get_action(): string { diff --git a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php index 3193d10b002..0454ab37b18 100644 --- a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php +++ b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php @@ -5,6 +5,8 @@ /** * The No_Non_Timestamped_Objects_Found_Exception exception. + * + * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ class No_Non_Timestamped_Objects_Found_Exception extends \Exception { diff --git a/src/indexables/domain/outdated-post-indexables-list.php b/src/indexables/domain/outdated-post-indexables-list.php index fa7ec969089..c9fc3f46d59 100644 --- a/src/indexables/domain/outdated-post-indexables-list.php +++ b/src/indexables/domain/outdated-post-indexables-list.php @@ -19,6 +19,7 @@ class Outdated_Post_Indexables_List implements \Iterator, \Countable { /** * The current array position. + * * @var int */ private $position = 0; @@ -43,6 +44,7 @@ public function add_post_indexable( Indexable $post ) { /** * Rewinds the array position. + * * @return void */ public function rewind(): void { @@ -61,6 +63,7 @@ public function current(): Indexable { /** * The current key. + * * @return int */ public function key(): int { @@ -78,6 +81,7 @@ public function next(): void { /** * Is the current position valid. + * * @return bool */ public function valid(): bool { @@ -86,6 +90,7 @@ public function valid(): bool { /** * Returns the size of the array. + * * @return int */ public function count():int { diff --git a/src/indexables/domain/plugin-deactivated-timestamp.php b/src/indexables/domain/plugin-deactivated-timestamp.php index 83f6817dc56..deab73b6eac 100644 --- a/src/indexables/domain/plugin-deactivated-timestamp.php +++ b/src/indexables/domain/plugin-deactivated-timestamp.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Indexables\Domain; - /** * The Plugin_Deactivated_Timestamp class. */ diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index 5f4c6e4acfa..edaa0f1cf15 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -1,5 +1,6 @@ repository = $repository; @@ -73,7 +74,7 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb instance. * - * @param \wpdb $wpdb + * @param \wpdb $wpdb The instance. * * @return void * @required diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index ea69591aed8..0d77192e182 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -91,7 +91,6 @@ public function set_wpdb( \wpdb $wpdb ) { private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); - $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); $replacements = []; \array_push( $replacements, ...$public_taxonomies ); @@ -100,14 +99,15 @@ private function get_query( $limit, $batch_size ) { $replacements[] = $batch_size; $offset_query = ''; if ( $limit !== 0 ) { - $offset_query = 'OFFSET %d'; + $offset_query = ' OFFSET %d'; $replacements[] = ( $limit + $batch_size );} + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. return $this->wpdb->prepare( " SELECT term_id FROM {$taxonomy_table} AS T - WHERE taxonomy IN ($placeholders) + WHERE taxonomy IN (" . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") $limit_query $offset_query", $replacements ); diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index 2da797b674f..c5c07814d3e 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -1,5 +1,6 @@ get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_query returns a prepared query. $terms = $this->wpdb->get_results( $query ); $term_list = \array_map( @@ -86,7 +99,9 @@ static function ( $term ) { } /** - * @param \wpdb $wpdb + * Sets the wpdb. + * + * @param \wpdb $wpdb The wpdb instance. * * @return void * @required @@ -106,7 +121,6 @@ public function set_wpdb( \wpdb $wpdb ) { private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); - $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); $replacements = []; \array_push( $replacements, ...$public_taxonomies ); @@ -119,12 +133,12 @@ private function get_query( $limit, $batch_size ) { $offset_query = 'OFFSET %d'; $replacements[] = ( $limit + $batch_size ); } - + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. return $this->wpdb->prepare( " SELECT term_id, description FROM {$taxonomy_table} AS T - WHERE taxonomy IN ($placeholders) + WHERE taxonomy IN (" . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") $limit_query $offset_query", $replacements ); diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 94cfca10aaa..0b99f71d1fc 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -56,7 +56,7 @@ public function __construct( wpdb $wpdb, Post_Type_Helper $post_type_helper, Post_Helper $post_helper, - Indexable_Repository $indexable_repository, + Indexable_Repository $indexable_repository ) { $this->wpdb = $wpdb; $this->post_type_helper = $post_type_helper; diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index ae7a7b80884..e6037e90d9b 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -16,11 +16,11 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { /** * The verification cron schedule handler. + * * @var Verification_Cron_Schedule_Handler */ protected $cron_schedule_handler; - /** * The options helper. * @@ -31,7 +31,8 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { /** * The constructor. * - * @param Options_Helper $options_helper The options helper. + * @param Options_Helper $options_helper The options helper. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. */ public function __construct( Options_Helper $options_helper, Verification_Cron_Schedule_Handler $cron_schedule_handler ) { $this->options_helper = $options_helper; diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 08173eba050..fce59f4f5c4 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -14,6 +14,7 @@ /** * The Verification_Cron_Callback_Integration class. + * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ class Verification_No_Timestamp_Cron_Callback_Integration implements Integration_Interface { From c3a368a9387d4819e7bf5ec67f3bc96e2f45a32b Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 22 Jun 2023 10:46:24 +0200 Subject: [PATCH 17/41] More tests --- .../verify-indexable-action-factory-test.php | 150 ++++++++++++++++++ ...estamp-indexables-command-handler-test.php | 129 +++++++++++++++ ...-non-timestamp-indexables-command-test.php | 77 +++++++++ ...y-post-indexables-command-handler-test.php | 103 ++++++++++++ .../verify-post-indexables-command-test.php | 66 ++++++++ 5 files changed, 525 insertions(+) create mode 100644 tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php create mode 100644 tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php create mode 100644 tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php create mode 100644 tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php create mode 100644 tests/unit/indexables/application/commands/verify-post-indexables-command-test.php diff --git a/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php new file mode 100644 index 00000000000..137213835fb --- /dev/null +++ b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php @@ -0,0 +1,150 @@ +term_action = Mockery::mock( Verify_Term_Indexables_Action::class ); + $this->general_action = Mockery::mock( Verify_General_Indexables_Action::class ); + $this->post_type_action = Mockery::mock( Verify_Post_Type_Archives_Indexables_Action::class ); + $this->term_link_action = Mockery::mock( Verify_Term_Links_Indexables_Action::class ); + + $this->instance = new Verify_Indexable_Action_Factory( $this->term_action, $this->general_action, $this->post_type_action, $this->term_link_action ); + } + + + /** + * + * @covers ::get + * @dataProvider indexable_action_factory_data_provider + * + * @param Current_Verification_Action $verification_action The given verification action. + * @param MockInterface|Verify_Indexables_Action_Interface $expected_result The expected result. + * + * @return void + */ + public function test_get( $verification_action, $expected_result ) { + $this->assertSame( \get_class( $expected_result ), \get_class( $this->instance->get( $verification_action ) ) ); + } + + /** + * Provides data for the `test_get` function. + * + * @return Generator + */ + public function indexable_action_factory_data_provider() { + yield 'Get term action' => [ + 'verification_action' => new Current_Verification_Action( 'term' ), + 'expected_result' => Mockery::mock( Verify_Term_Indexables_Action::class ), + ]; + + yield 'Get general action' => [ + 'verification_action' => new Current_Verification_Action( 'general' ), + 'expected_result' => Mockery::mock( Verify_General_Indexables_Action::class ), + ]; + + yield 'Get post type archives action' => [ + 'verification_action' => new Current_Verification_Action( 'post-type-archives' ), + 'expected_result' => Mockery::mock( Verify_Post_Type_Archives_Indexables_Action::class ), + ]; + yield 'Get term link action' => [ + 'verification_action' => new Current_Verification_Action( 'term-links' ), + 'expected_result' => Mockery::mock( Verify_Term_Links_Indexables_Action::class ), + ]; + } + + /** + * Tests if the exception gets thrown if the verification action does not exist. + * + * @covers ::get + * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception + * @return void + */ + public function test_get_exception() { + $this->expectException( Verify_Action_Not_Found_Exception::class ); + + $this->instance->get( new Current_Verification_Action( 'nothing' ) ); + } + + /** + * Tests if the exception gets thrown if a non existing action is given. + * + * @covers ::determine_next_verify_action + * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @return void + */ + public function test_determine_next_verify_action_no_existing_action() { + $this->expectException( No_Verification_Action_Left_Exception::class ); + + $this->instance->determine_next_verify_action( new Current_Verification_Action( 'nothing' ) ); + } + + /** + * Tests if the exception gets thrown if no actions are left. + * + * @covers ::determine_next_verify_action + * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @return void + */ + public function test_determine_next_verify_action_no_actions_left() { + $this->expectException( No_Verification_Action_Left_Exception::class ); + + $this->instance->determine_next_verify_action( new Current_Verification_Action( 'post_links' ) ); + } + + /** + * Tests getting the next action. + * + * @covers ::determine_next_verify_action + * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @return void + */ + public function test_determine_next_verify_action() { + $next_action = new Current_Verification_Action( 'term_links' ); + $result = $this->instance->determine_next_verify_action( new Current_Verification_Action( 'post-type-archives' ) ); + $this->assertSame( $next_action->get_action(), $result->get_action() ); + } +} diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php new file mode 100644 index 00000000000..81248652c4d --- /dev/null +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php @@ -0,0 +1,129 @@ +cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); + $this->indexables_action_factory = Mockery::mock( Verify_Indexables_Action_Factory_Interface::class ); + $this->next_verification_action_handler = Mockery::mock( Next_Verification_Action_Handler::class ); + $this->command = new Verify_Non_Timestamp_Indexables_Command( 10, 10, \time(), 'term' ); + $this->instance = new Verify_Non_Timestamp_Indexables_Command_Handler( $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_action_factory, $this->next_verification_action_handler ); + } + + public function test_handle_with_next_batch() { + + $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); + $action_mock->expects( 're_build_indexables' )->andReturnTrue(); + + $this->indexables_action_factory->expects( 'get' ) + ->with( $this->command->get_current_action() ) + ->andReturn( $action_mock ); + $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' ) + ->with( $this->command->get_last_batch_count(), $this->command->get_batch_size() ); + $this->instance->handle( $this->command ); + } + + public function test_handle_with_action_not_found() { + $this->indexables_action_factory->expects( 'get' ) + ->with( $this->command->get_current_action() ) + ->andThrow( new Verify_Action_Not_Found_Exception() ); + $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); + $this->instance->handle( $this->command ); + } + + public function test_handle_with_no_next_batch_action_found() { + + $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); + $action_mock->expects( 're_build_indexables' )->andReturnFalse(); + + $new_action = new Current_Verification_Action( 'general' ); + $this->indexables_action_factory->expects() + ->get( $this->command->get_current_action() ) + ->andReturn( $action_mock ); + $this->indexables_action_factory->expects() + ->determine_next_verify_action( $this->command->get_current_action() ) + ->andReturn( $new_action ); + $this->next_verification_action_handler->expects()->set_current_verification_action( $new_action ); + $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' ); + $this->instance->handle( $this->command ); + } + + public function test_handle_with_no_next_batch_action_not_found() { + + $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); + $action_mock->expects( 're_build_indexables' )->andReturnFalse(); + + $new_action = new Current_Verification_Action( 'general' ); + $this->indexables_action_factory->expects() + ->get( $this->command->get_current_action() ) + ->andReturn( $action_mock ); + $this->indexables_action_factory->expects() + ->determine_next_verify_action( $this->command->get_current_action() ) + ->andThrow( new No_Verification_Action_Left_Exception() ); + $this->next_verification_action_handler->expects()->set_current_verification_action( $new_action )->never(); + $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' )->never(); + $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); + + $this->instance->handle( $this->command ); + } +} diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php new file mode 100644 index 00000000000..dcbb9f7cdce --- /dev/null +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php @@ -0,0 +1,77 @@ +instance = new Verify_Non_Timestamp_Indexables_Command( 10, 10, \time(), 'post' ); + } + + + /** + * Tests the get current action object. + * @covers ::get_current_action + * + * @return void + */ + public function test_get_current_action() { + $this->assertEquals( new Current_Verification_Action( 'post' ), $this->instance->get_current_action() ); + } + + /** + * Tests the last batch count object. + * @covers ::get_last_batch_count + * + * @return void + */ + public function test_get_last_batch_count() { + $this->assertEquals( new Last_Batch_Count( 10 ), $this->instance->get_last_batch_count() ); + } + + /** + * Tests getting the plugin deactivated at object. + * + * @covers ::get_plugin_deactivated_at + * @return void + */ + public function test_get_plugin_deactivated_at() { + $this->assertEquals( new Plugin_Deactivated_Timestamp( \time() ), $this->instance->get_plugin_deactivated_at() ); + } + + /** + * Test getting the batch size object. + * + * @covers ::get_batch_size + * @return void + */ + public function test_get_batch_size() { + $this->assertEquals( new Batch_Size( 10 ), $this->instance->get_batch_size() ); + } + +} diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php new file mode 100644 index 00000000000..a19a1dc188a --- /dev/null +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -0,0 +1,103 @@ +cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); + $this->outdated_post_indexables_repository = Mockery::mock( Outdated_Post_Indexables_Repository_Interface::class ); + $this->indexables_builder = Mockery::mock( Indexable_Builder::class ); + $this->command = new Verify_Post_Indexables_Command( 10, 10, \time()); + $this->instance = new Verify_Post_Indexables_Command_Handler($this->outdated_post_indexables_repository, $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_builder ); + } + + public function test_handle_with_next_batch() { + + $indexable_list = []; + $indexable_mock = Mockery::mock( Indexable::class ); + $indexable_list[]= $indexable_mock; + $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) + ->with( $this->command->get_last_batch_count() ) + ->andReturn($indexable_list); + + + $this->indexables_builder->expects()->build($indexable_mock); + + $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' ) + ->with( $this->command->get_last_batch_count(), $this->command->get_batch_size() ); + $this->instance->handle( $this->command ); + } + + public function test_handle_with_action_not_found() { + $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) + ->with( $this->command->get_last_batch_count() ) + ->andThrow( new No_Outdated_Posts_Found_Exception() ); + $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); + $this->instance->handle( $this->command ); + } + +} diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php new file mode 100644 index 00000000000..e27c28ea32f --- /dev/null +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php @@ -0,0 +1,66 @@ +instance = new Verify_Post_Indexables_Command( 10, 10, \time() ); + } + + /** + * Tests the last batch count object. + * @covers ::get_last_batch_count + * + * @return void + */ + public function test_get_last_batch_count() { + $this->assertEquals( new Last_Batch_Count( 10 ), $this->instance->get_last_batch_count() ); + } + + /** + * Tests getting the plugin deactivated at object. + * + * @covers ::get_plugin_deactivated_at + * @return void + */ + public function test_get_plugin_deactivated_at() { + $this->assertEquals( new Plugin_Deactivated_Timestamp( \time() ), $this->instance->get_plugin_deactivated_at() ); + } + + /** + * Test getting the batch size object. + * + * @covers ::get_batch_size + * @return void + */ + public function test_get_batch_size() { + $this->assertEquals( new Batch_Size( 10 ), $this->instance->get_batch_size() ); + } + +} From eff9831b0a09e6d184e9cc1f8d49c43031955a7c Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 27 Jun 2023 15:10:28 +0200 Subject: [PATCH 18/41] Tests progress. --- .../verification-cron-schedule-handler.php | 4 +- .../verify-indexable-action-factory-test.php | 42 +++++-- ...estamp-indexables-command-handler-test.php | 58 +++++++-- ...-non-timestamp-indexables-command-test.php | 8 +- ...y-post-indexables-command-handler-test.php | 60 ++++++--- .../verify-post-indexables-command-test.php | 9 +- .../cron-verification-gate-test.php | 86 +++++++++++++ .../next-verification-action-handler-test.php | 64 ++++++++++ .../verification-cron-batch-handler-test.php | 91 ++++++++++++++ ...erification-cron-schedule-handler-test.php | 115 ++++++++++++++++++ .../indexables/domain/batch-size-test.php | 56 +++++++++ .../current-verification-action-test.php | 44 +++++++ .../domain/last-batch-count-test.php | 44 +++++++ .../outdated-post-indexables-list-test.php | 70 +++++++++++ .../plugin-deactivated-timestamp-test.php | 41 +++++++ 15 files changed, 753 insertions(+), 39 deletions(-) create mode 100644 tests/unit/indexables/application/cron-verification-gate-test.php create mode 100644 tests/unit/indexables/application/next-verification-action-handler-test.php create mode 100644 tests/unit/indexables/application/verification-cron-batch-handler-test.php create mode 100644 tests/unit/indexables/application/verification-cron-schedule-handler-test.php create mode 100644 tests/unit/indexables/domain/batch-size-test.php create mode 100644 tests/unit/indexables/domain/current-verification-action-test.php create mode 100644 tests/unit/indexables/domain/last-batch-count-test.php create mode 100644 tests/unit/indexables/domain/outdated-post-indexables-list-test.php create mode 100644 tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 7415a726998..3ad4f25499a 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -40,11 +40,11 @@ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { */ public function schedule_indexable_verification(): void { - if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { + if ( $this->cron_verification_gate->should_verify_on_cron() && ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) ) { \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); } - if ( ! \wp_next_scheduled( self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) && $this->cron_verification_gate->should_verify_on_cron() ) { + if ( $this->cron_verification_gate->should_verify_on_cron() && ! \wp_next_scheduled( self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) ) { \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); } } diff --git a/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php index 137213835fb..9a488cf4422 100644 --- a/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php +++ b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php @@ -1,5 +1,6 @@ instance = new Verify_Indexable_Action_Factory( $this->term_action, $this->general_action, $this->post_type_action, $this->term_link_action ); } - /** + * Tests the get function. * * @covers ::get + * * @dataProvider indexable_action_factory_data_provider * * @param Current_Verification_Action $verification_action The given verification action. * @param MockInterface|Verify_Indexables_Action_Interface $expected_result The expected result. * + * @throws Verify_Action_Not_Found_Exception When the given action is not found. * @return void */ public function test_get( $verification_action, $expected_result ) { @@ -100,7 +124,7 @@ public function indexable_action_factory_data_provider() { * Tests if the exception gets thrown if the verification action does not exist. * * @covers ::get - * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception + * @throws Verify_Action_Not_Found_Exception Throws when the action is not found. * @return void */ public function test_get_exception() { @@ -113,7 +137,7 @@ public function test_get_exception() { * Tests if the exception gets thrown if a non existing action is given. * * @covers ::determine_next_verify_action - * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @throws No_Verification_Action_Left_Exception Throws when no verification action is left. * @return void */ public function test_determine_next_verify_action_no_existing_action() { @@ -126,7 +150,7 @@ public function test_determine_next_verify_action_no_existing_action() { * Tests if the exception gets thrown if no actions are left. * * @covers ::determine_next_verify_action - * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @throws No_Verification_Action_Left_Exception Throws when no verification action is left. * @return void */ public function test_determine_next_verify_action_no_actions_left() { @@ -139,7 +163,7 @@ public function test_determine_next_verify_action_no_actions_left() { * Tests getting the next action. * * @covers ::determine_next_verify_action - * @throws \Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception + * @throws No_Verification_Action_Left_Exception Throws when no verification action is left. * @return void */ public function test_determine_next_verify_action() { diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php index 81248652c4d..2fdc160fb52 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php @@ -1,5 +1,6 @@ instance = new Verify_Non_Timestamp_Indexables_Command_Handler( $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_action_factory, $this->next_verification_action_handler ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @return void + */ public function test_handle_with_next_batch() { $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); @@ -83,6 +105,12 @@ public function test_handle_with_next_batch() { $this->instance->handle( $this->command ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @return void + */ public function test_handle_with_action_not_found() { $this->indexables_action_factory->expects( 'get' ) ->with( $this->command->get_current_action() ) @@ -91,6 +119,14 @@ public function test_handle_with_action_not_found() { $this->instance->handle( $this->command ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @throws No_Verification_Action_Left_Exception Throws when there is no verification action left. + * @throws Verify_Action_Not_Found_Exception Throws when the verification action is not found. + * @return void + */ public function test_handle_with_no_next_batch_action_found() { $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); @@ -108,6 +144,14 @@ public function test_handle_with_no_next_batch_action_found() { $this->instance->handle( $this->command ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @throws No_Verification_Action_Left_Exception Throws when there is no verification action left. + * @throws Verify_Action_Not_Found_Exception Throws when the verification action is not found. + * @return void + */ public function test_handle_with_no_next_batch_action_not_found() { $action_mock = Mockery::mock( Verify_Term_Indexables_Action::class ); diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php index dcbb9f7cdce..423e324504b 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php @@ -1,5 +1,6 @@ instance = new Verify_Non_Timestamp_Indexables_Command( 10, 10, \time(), 'post' ); } - /** * Tests the get current action object. + * * @covers ::get_current_action * * @return void @@ -46,6 +50,7 @@ public function test_get_current_action() { /** * Tests the last batch count object. + * * @covers ::get_last_batch_count * * @return void @@ -73,5 +78,4 @@ public function test_get_plugin_deactivated_at() { public function test_get_batch_size() { $this->assertEquals( new Batch_Size( 10 ), $this->instance->get_batch_size() ); } - } diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index a19a1dc188a..46ed70c263e 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -1,5 +1,6 @@ cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); - $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); - $this->outdated_post_indexables_repository = Mockery::mock( Outdated_Post_Indexables_Repository_Interface::class ); - $this->indexables_builder = Mockery::mock( Indexable_Builder::class ); - $this->command = new Verify_Post_Indexables_Command( 10, 10, \time()); - $this->instance = new Verify_Post_Indexables_Command_Handler($this->outdated_post_indexables_repository, $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_builder ); + $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); + $this->outdated_post_indexables_repository = Mockery::mock( Outdated_Post_Indexables_Repository_Interface::class ); + $this->indexables_builder = Mockery::mock( Indexable_Builder::class ); + $this->command = new Verify_Post_Indexables_Command( 10, 10, \time() ); + $this->instance = new Verify_Post_Indexables_Command_Handler( $this->outdated_post_indexables_repository, $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_builder ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @return void + */ public function test_handle_with_next_batch() { - $indexable_list = []; - $indexable_mock = Mockery::mock( Indexable::class ); - $indexable_list[]= $indexable_mock; + $indexable_list = []; + $indexable_mock = Mockery::mock( Indexable::class ); + $indexable_list[] = $indexable_mock; $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) ->with( $this->command->get_last_batch_count() ) - ->andReturn($indexable_list); + ->andReturn( $indexable_list ); - $this->indexables_builder->expects()->build($indexable_mock); + $this->indexables_builder->expects()->build( $indexable_mock ); $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' ) ->with( $this->command->get_last_batch_count(), $this->command->get_batch_size() ); $this->instance->handle( $this->command ); } + /** + * Tests the handle function. + * + * @covers ::handle + * @return void + */ public function test_handle_with_action_not_found() { $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) ->with( $this->command->get_last_batch_count() ) @@ -99,5 +126,4 @@ public function test_handle_with_action_not_found() { $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); $this->instance->handle( $this->command ); } - } diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php index e27c28ea32f..c019a1d6ca3 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php @@ -1,5 +1,6 @@ assertEquals( new Batch_Size( 10 ), $this->instance->get_batch_size() ); } - } diff --git a/tests/unit/indexables/application/cron-verification-gate-test.php b/tests/unit/indexables/application/cron-verification-gate-test.php new file mode 100644 index 00000000000..aa2798feb61 --- /dev/null +++ b/tests/unit/indexables/application/cron-verification-gate-test.php @@ -0,0 +1,86 @@ +indexable_helper = Mockery::mock( Indexable_Helper::class ); + + $this->instance = new Cron_Verification_Gate( $this->indexable_helper ); + } + + /** + * Tests if the should verify on cron function gives the expected response. + * + * @param bool $expected The expected result + * @param string $should_index What the helper should return. + * @param string $filter_value What the filter should return. + * + * @covers ::should_verify_on_cron + * @covers ::__construct + * @dataProvider should_verify_on_cron_dataprovider + * @return void + */ + public function test_should_verify_on_cron( $expected, $should_index, $filter_value ) { + $this->indexable_helper->expects()->should_index_indexables()->andReturn( $should_index ); + Monkey\Functions\expect( 'apply_filters' )->andReturn( $filter_value ); + + $this->assertSame( $expected, $this->instance->should_verify_on_cron() ); + } + + /** + * Data provider for the `test_should_verify_on_cron` test. + * + * @return \Generator + */ + public function should_verify_on_cron_dataprovider() { + yield [ + 'expected' => false, + 'should_index' => false, + 'filter_value' => false, + ]; + + yield [ + 'expected' => false, + 'should_index' => true, + 'filter_value' => false, + ]; + + yield [ + 'expected' => true, + 'should_index' => true, + 'filter_value' => true, + ]; + } +} diff --git a/tests/unit/indexables/application/next-verification-action-handler-test.php b/tests/unit/indexables/application/next-verification-action-handler-test.php new file mode 100644 index 00000000000..676f1390848 --- /dev/null +++ b/tests/unit/indexables/application/next-verification-action-handler-test.php @@ -0,0 +1,64 @@ +options_helper = Mockery::mock( Options_Helper::class ); + + $this->instance = new Next_Verification_Action_Handler( $this->options_helper ); + } + + /** + * Tests the get function. + * + * @covers ::get_current_verification_action + * @return void + */ + public function test_get_current_verification_action() { + $this->options_helper->expects()->get( 'cron_verify_current_action', 'term' )->andReturn( 'term' ); + $this->instance->get_current_verification_action(); + } + + /** + * Tests the set function. + * + * @covers ::set_current_verification_Action + * @return void + */ + public function test_set_current_verification_action() { + $this->options_helper->expects()->set( 'cron_verify_current_action', 'value' ); + $this->instance->set_current_verification_action( new Current_Verification_Action( 'value' ) ); + } +} diff --git a/tests/unit/indexables/application/verification-cron-batch-handler-test.php b/tests/unit/indexables/application/verification-cron-batch-handler-test.php new file mode 100644 index 00000000000..0871e5e3880 --- /dev/null +++ b/tests/unit/indexables/application/verification-cron-batch-handler-test.php @@ -0,0 +1,91 @@ +options_helper = Mockery::mock( Options_Helper::class ); + + $this->instance = new Verification_Cron_Batch_Handler( $this->options_helper ); + } + + /** + * Tests the get function. + * + * @covers ::get_current_post_indexables_batch + * @return void + */ + public function test_get_current_post_indexables_batch() { + $this->options_helper->expects()->get( 'cron_verify_post_indexables_last_batch', 0 )->andReturn( 0 ); + $this->instance->get_current_post_indexables_batch(); + } + + /** + * Tests the set function. + * + * @covers ::set_current_post_indexables_batch + * + * @return void + */ + public function test_set_current_post_indexables_batch() { + $this->options_helper->expects()->set( 'cron_verify_post_indexables_last_batch', 5 ); + $this->instance->set_current_post_indexables_batch( 5 ); + } + + /** + * Tests the get function. + * + * @covers ::get_current_non_timestamped_indexables_batch + * @return void + */ + public function test_get_current_non_timestamped_indexables_batch() { + $this->options_helper->expects() + ->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 ) + ->andReturn( 0 ); + $this->instance->get_current_non_timestamped_indexables_batch(); + } + + /** + * Tests the set function. + * + * @covers ::set_current_non_timestamped_indexables_batch + * + * @return void + */ + public function test_set_current_non_timestamped_indexables_batch() { + $this->options_helper->expects()->set( 'cron_verify_non_timestamped_indexables_last_batch', 15 ); + $this->instance->set_current_non_timestamped_indexables_batch( new Last_Batch_Count( 10 ), new Batch_Size( 5 ) ); + } +} diff --git a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php new file mode 100644 index 00000000000..4845702c8d6 --- /dev/null +++ b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php @@ -0,0 +1,115 @@ +cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); + + $this->instance = new Verification_Cron_Schedule_Handler( $this->cron_verification_gate ); + } + + /** + * Tests the schedule_indexable_verification method. + * + * @covers ::schedule_indexable_verification + * + * @dataProvider schedule_indexable_verification_provider + * @return void + */ + public function test_schedule_indexable_verification( + $should_verify, + $post_scheduled, + $timestamp_scheduled, + $time_wp_schedule_event + ) { + $this->cron_verification_gate->expects( 'should_verify_on_cron' )->twice()->andReturn( $should_verify ); + if ( $should_verify ) { + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) + ->andReturn( $post_scheduled ); + + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) + ->andReturn( $timestamp_scheduled ); + } + + Monkey\Functions\expect( 'wp_schedule_event' ) + ->times( $time_wp_schedule_event ); + + $this->instance->schedule_indexable_verification(); + } + + /** + * Data provider for `test_schedule_indexable_verification` + * + * @return \Generator + */ + public function schedule_indexable_verification_provider() { + yield 'Both crons already scheduled.' => [ + 'should_verify' => true, + 'post_cron_scheduled' => true, + 'timestamp_cron_scheduled' => true, + 'time_wp_schedule_event' => 0, + ]; + yield 'Verification turned off.' => [ + 'should_verify' => false, + 'post_cron_scheduled' => false, + 'timestamp_cron_scheduled' => false, + 'time_wp_schedule_event' => 0, + ]; + yield 'Post not scheduled timestamp is.' => [ + 'should_verify' => true, + 'post_cron_scheduled' => false, + 'timestamp_cron_scheduled' => true, + 'time_wp_schedule_event' => 1, + ]; + + yield 'Timestamp not scheduled post is.' => [ + 'should_verify' => true, + 'post_cron_scheduled' => true, + 'timestamp_cron_scheduled' => false, + 'time_wp_schedule_event' => 1, + ]; + + yield 'Nothing is scheduled yet.' => [ + 'should_verify' => true, + 'post_cron_scheduled' => true, + 'timestamp_cron_scheduled' => false, + 'time_wp_schedule_event' => 1, + ]; + } +} diff --git a/tests/unit/indexables/domain/batch-size-test.php b/tests/unit/indexables/domain/batch-size-test.php new file mode 100644 index 00000000000..64569b6ccf4 --- /dev/null +++ b/tests/unit/indexables/domain/batch-size-test.php @@ -0,0 +1,56 @@ +instance = new Batch_Size( 10 ); + } + + /** + * Tests the get function. + * + * @covers ::get_batch_size + * @covers ::__construct + * @return void + */ + public function test_get_batch_size() { + $this->assertSame( 10, $this->instance->get_batch_size() ); + } + + /** + * Tests the get function. + * + * @covers ::get_batch_size + * @covers ::__construct + * @return void + */ + public function test_should_keep_going() { + $this->assertSame( true, $this->instance->should_keep_going( 12 ) ); + $this->assertSame( false, $this->instance->should_keep_going( 9 ) ); + $this->assertSame( true, $this->instance->should_keep_going( 10 ) ); + } +} diff --git a/tests/unit/indexables/domain/current-verification-action-test.php b/tests/unit/indexables/domain/current-verification-action-test.php new file mode 100644 index 00000000000..7b5f5090ff6 --- /dev/null +++ b/tests/unit/indexables/domain/current-verification-action-test.php @@ -0,0 +1,44 @@ +instance = new Current_Verification_Action( 'term' ); + } + + /** + * Tests the get function. + * + * @covers ::get_action + * @covers ::__construct + * @return void + */ + public function test_get_action() { + $this->assertSame( 'term', $this->instance->get_action() ); + } +} diff --git a/tests/unit/indexables/domain/last-batch-count-test.php b/tests/unit/indexables/domain/last-batch-count-test.php new file mode 100644 index 00000000000..1c3e10e4e36 --- /dev/null +++ b/tests/unit/indexables/domain/last-batch-count-test.php @@ -0,0 +1,44 @@ +instance = new Last_Batch_Count( 10 ); + } + + /** + * Tests the get function. + * + * @covers ::get_last_batch + * @covers ::__construct + * @return void + */ + public function test_get_batch_size() { + $this->assertSame( 10, $this->instance->get_last_batch() ); + } +} diff --git a/tests/unit/indexables/domain/outdated-post-indexables-list-test.php b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php new file mode 100644 index 00000000000..66d89762d43 --- /dev/null +++ b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php @@ -0,0 +1,70 @@ +instance = new Outdated_Post_Indexables_List(); + } + + /** + * Tests the add_post_indexable function. + * + * @covers ::add_post_indexable + * @covers ::__construct + * @return void + */ + public function test_add_post_indexable() { + $indexable = new Indexable_Double(); + $this->instance->add_post_indexable( $indexable ); + $this->assertSame( $this->instance->current(), $indexable ); + } + + /** + * Tests the array functions. + * + * @covers ::add_post_indexable + * @covers ::key + * @covers ::next + * @covers ::rewind + * @covers ::count + * @return void + */ + public function test_array_functions() { + $indexable = new Indexable_Double(); + $this->instance->add_post_indexable( $indexable ); + + $this->assertSame( 0, $this->instance->key() ); + $this->instance->next(); + $this->assertSame( 1, $this->instance->key() ); + $this->assertFalse( $this->instance->valid() ); + $this->assertSame( 1, $this->instance->count() ); + $this->instance->rewind(); + $this->assertSame( 0, $this->instance->key() ); + } +} diff --git a/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php b/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php new file mode 100644 index 00000000000..875179f1b38 --- /dev/null +++ b/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php @@ -0,0 +1,41 @@ +instance = new Plugin_Deactivated_Timestamp( \time() ); + } +} From 593338f13afe11d427d74f6614cff5a6e5783d86 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 28 Jun 2023 12:41:53 +0200 Subject: [PATCH 19/41] More tests. --- ...no-timestamp-cron-callback-integration.php | 3 +- ...cation-posts-cron-callback-integration.php | 2 +- .../mark-deactivation-integration-test.php | 80 +++++++++ ...ule-verification-cron-integration-test.php | 92 ++++++++++ ...mestamp-cron-callback-integration-test.php | 162 ++++++++++++++++++ 5 files changed, 336 insertions(+), 3 deletions(-) create mode 100644 tests/unit/indexables/user-interface/mark-deactivation-integration-test.php create mode 100644 tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php create mode 100644 tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index fce59f4f5c4..5538f4a8c9c 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -94,7 +94,6 @@ public function __construct( public function register_hooks() { \add_action( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, - // 'admin_init', [ $this, 'start_verify_non_timestamped_indexables', @@ -108,7 +107,7 @@ public function register_hooks() { * @return void */ public function start_verify_non_timestamped_indexables() { - if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { + if ( \wp_doing_cron() || ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); return; diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 4743de65022..ec321f5df09 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -98,7 +98,7 @@ public function register_hooks() { * @return void */ public function start_verify_posts(): void { - if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { + if ( \wp_doing_cron() || ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); return; diff --git a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php new file mode 100644 index 00000000000..014ac99b5f6 --- /dev/null +++ b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php @@ -0,0 +1,80 @@ +options_helper = Mockery::mock( Options_Helper::class ); + + $this->instance = new Mark_Deactivation_Integration( $this->options_helper ); + } + + /** + * Tests the get function. + * + * @covers ::register_hooks + * @return void + */ + public function test_register_hooks() { + Monkey\Functions\expect( 'add_action' ) + ->with( 'wpseo_deactivate', [ $this->instance, 'register_deactivation' ] ); + } + + /** + * Tests the get function. + * + * @covers ::get_conditionals + * @return void + */ + public function test_get_conditionals() { + $this->assertEquals( + [ + Admin_Conditional::class, + ], + Mark_Deactivation_Integration::get_conditionals() + ); + } + + /** + * Tests setting the deactivation option. + * + * @covers ::register_deactivation + * @return void + */ + public function test_register_deactivation() { + $this->options_helper->expects()->set( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); + + $this->instance->register_deactivation(); + } +} diff --git a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php new file mode 100644 index 00000000000..cfe6aaa9c4c --- /dev/null +++ b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php @@ -0,0 +1,92 @@ +options_helper = Mockery::mock( Options_Helper::class ); + $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + + $this->instance = new Schedule_Verification_Cron_Integration( $this->options_helper, $this->cron_schedule_handler ); + } + + /** + * Tests the register_hooks function. + * + * @covers ::register_hooks + * @return void + */ + public function test_register_hooks_ftc() { + $this->options_helper->expects()->get( 'first_time_install', false )->andReturnFalse(); + + Monkey\Functions\expect( 'add_action' ) + ->with( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); + + $this->instance->register_hooks(); + } + + /** + * Tests the register_hooks function. + * + * @covers ::register_hooks + * @return void + */ + public function test_register_hooks_without_ftc() { + $this->options_helper->expects()->get( 'first_time_install', false )->andReturnTrue(); + Monkey\Functions\expect( 'add_action' )->never(); + $this->instance->register_hooks(); + } + + /** + * Tests the get function. + * + * @covers ::get_conditionals + * @return void + */ + public function test_get_conditionals() { + $this->assertEquals( + [ + Admin_Conditional::class, + ], + Schedule_Verification_Cron_Integration::get_conditionals() + ); + } +} diff --git a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php new file mode 100644 index 00000000000..501607fb224 --- /dev/null +++ b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php @@ -0,0 +1,162 @@ +cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); + $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->options_helper = Mockery::mock( Options_Helper::class ); + $this->verification_cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); + $this->verify_non_timestamp_indexables_command_handler = Mockery::mock( Verify_Non_Timestamp_Indexables_Command_Handler::class ); + $this->next_verification_action_handler = Mockery::mock( Next_Verification_Action_Handler::class ); + + $this->instance = new Verification_No_Timestamp_Cron_Callback_Integration( $this->cron_verification_gate, $this->cron_schedule_handler, $this->options_helper, $this->verification_cron_batch_handler, $this->verify_non_timestamp_indexables_command_handler, $this->next_verification_action_handler ); + } + + /** + * Tests the register_hooks function. + * + * @covers ::register_hooks + * @return void + */ + public function test_register_hooks() { + Monkey\Functions\expect( 'add_action' ) + ->with( + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME, + [ + $this->instance, + 'start_verify_non_timestamped_indexables', + ] + ); + + $this->instance->register_hooks(); + } + + /** + * Tests the get function. + * + * @covers ::get_conditionals + * @return void + */ + public function test_get_conditionals() { + $this->assertEquals( + [ + Admin_Conditional::class, + ], + Verification_No_Timestamp_Cron_Callback_Integration::get_conditionals() + ); + } + + /** + * Tests the `start_verify_non_timestamped_indexables` while a cron is already running. + * + * @covers ::start_verify_non_timestamped_indexables + * + * @return void + */ + public function test_start_verify_non_timestamped_indexables_doing_cron() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); + $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); + $this->instance->start_verify_non_timestamped_indexables(); + } + + /** + * Tests the `start_verify_non_timestamped_indexables` when no cron is running and indexables are enabled. + * + * @covers ::start_verify_non_timestamped_indexables + * + * @return void + */ + public function test_start_verify_non_timestamped_indexables_indexables_disabled() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnFalse(); + $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); + $this->instance->start_verify_non_timestamped_indexables(); + } + + /** + * Tests the `start_verify_non_timestamped_indexables` in a normal flow. + * + * @covers ::start_verify_non_timestamped_indexables + * + * @return void + */ + public function test_start_verify_non_timestamped_indexables() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue(); + $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->never(); + + $this->verification_cron_batch_handler->expects( 'get_current_non_timestamped_indexables_batch' )->andReturn( 10 ); + $this->options_helper->expects( 'get' ) + ->with( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() )->andReturn( \time() ); + $this->next_verification_action_handler->expects( 'get_current_verification_action' )->andReturn( 'term' ); + + $this->verify_non_timestamp_indexables_command_handler->expects( 'handle' ); + + $this->instance->start_verify_non_timestamped_indexables(); + } +} From 0f7eb107230a490a0d4d9ebdc958d3b03a04f21e Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 28 Jun 2023 16:16:26 +0200 Subject: [PATCH 20/41] Update tests --- ...erification-cron-schedule-handler-test.php | 12 +- .../mark-deactivation-integration-test.php | 10 +- ...ule-verification-cron-integration-test.php | 12 +- ...mestamp-cron-callback-integration-test.php | 20 ++- ...n-posts-cron-callback-integration-test.php | 167 ++++++++++++++++++ 5 files changed, 211 insertions(+), 10 deletions(-) create mode 100644 tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php diff --git a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php index 4845702c8d6..a6f4282c587 100644 --- a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php @@ -18,11 +18,15 @@ class Verification_Cron_Schedule_Handler_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler + * The instance. + * + * @var Verification_Cron_Schedule_Handler */ private $instance; /** + * The cron verification gate. + * * @var \Mockery\MockInterface|Cron_Verification_Gate */ private $cron_verification_gate; @@ -46,6 +50,12 @@ protected function setUp(): void { * @covers ::schedule_indexable_verification * * @dataProvider schedule_indexable_verification_provider + * + * @param bool $should_verify If the indexable verification is enabled. + * @param bool $post_scheduled If the cron is scheduled. + * @param bool $timestamp_scheduled If the cron is scheduled. + * @param int $time_wp_schedule_event How many times this functions should be called. + * * @return void */ public function test_schedule_indexable_verification( diff --git a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php index 014ac99b5f6..2f5d7c635ec 100644 --- a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php +++ b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php @@ -1,6 +1,6 @@ cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); + $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->options_helper = Mockery::mock( Options_Helper::class ); + $this->verification_cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); + $this->verify_posts_indexables_command_handler = Mockery::mock( Verify_Post_Indexables_Command_Handler::class ); + $this->instance = new Verification_Posts_Cron_Callback_Integration( $this->cron_verification_gate, $this->cron_schedule_handler, $this->options_helper, $this->verification_cron_batch_handler, $this->verify_posts_indexables_command_handler ); + } + + /** + * Tests the register_hooks function. + * + * @covers ::register_hooks + * @return void + */ + public function test_register_hooks() { + Monkey\Functions\expect( 'add_action' ) + ->with( + Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME, + [ + $this->instance, + 'start_verify_posts', + ] + ); + + $this->instance->register_hooks(); + } + + /** + * Tests the get function. + * + * @covers ::get_conditionals + * @return void + */ + public function test_get_conditionals() { + $this->assertEquals( + [ + Admin_Conditional::class, + ], + Verification_Posts_Cron_Callback_Integration::get_conditionals() + ); + } + + /** + * Tests the `start_verify_posts` while a cron is already running. + * + * @covers ::start_verify_posts + * + * @return void + */ + public function test_start_verify_posts_indexables_doing_cron() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); + $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); + $this->instance->start_verify_posts(); + } + + /** + * Tests the `start_verify_posts` when no cron is running and indexables are enabled. + * + * @covers ::start_verify_posts + * + * @return void + */ + public function test_start_verify_posts_indexables_indexables_disabled() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnFalse(); + $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); + $this->instance->start_verify_posts(); + } + + /** + * Tests the `start_verify_posts` in a normal flow. + * + * @covers ::start_verify_posts + * + * @return void + */ + public function test_start_verify_posts_indexables() { + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue(); + + $this->verification_cron_batch_handler->expects( 'get_current_post_indexables_batch' )->andReturn( 10 ); + $this->options_helper->expects( 'get' ) + ->with( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() )->andReturn( \time() ); + + $this->verify_posts_indexables_command_handler->expects( 'handle' ); + + $this->instance->start_verify_posts(); + } +} From 576282934ea315c44f44b6854bb80d9e9d86bd6e Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 29 Jun 2023 11:37:52 +0200 Subject: [PATCH 21/41] Tests --- .../application/cron-verification-gate-test.php | 10 +++++++--- .../next-verification-action-handler-test.php | 8 ++++++-- .../verification-cron-batch-handler-test.php | 8 ++++++-- tests/unit/indexables/domain/batch-size-test.php | 4 +++- .../domain/current-verification-action-test.php | 4 +++- .../indexables/domain/last-batch-count-test.php | 2 ++ .../domain/outdated-post-indexables-list-test.php | 2 ++ .../domain/plugin-deactivated-timestamp-test.php | 13 +++---------- ...-no-timestamp-cron-callback-integration-test.php | 1 + 9 files changed, 33 insertions(+), 19 deletions(-) diff --git a/tests/unit/indexables/application/cron-verification-gate-test.php b/tests/unit/indexables/application/cron-verification-gate-test.php index aa2798feb61..8ef79647c55 100644 --- a/tests/unit/indexables/application/cron-verification-gate-test.php +++ b/tests/unit/indexables/application/cron-verification-gate-test.php @@ -18,12 +18,16 @@ class Cron_Verification_Gate_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate + * The instance. + * + * @var Cron_Verification_Gate */ private $instance; /** - * @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Indexable_Helper + * The indexable helper. + * + * @var \Mockery\MockInterface|Indexable_Helper */ private $indexable_helper; @@ -43,7 +47,7 @@ protected function setUp(): void { /** * Tests if the should verify on cron function gives the expected response. * - * @param bool $expected The expected result + * @param bool $expected The expected result. * @param string $should_index What the helper should return. * @param string $filter_value What the filter should return. * diff --git a/tests/unit/indexables/application/next-verification-action-handler-test.php b/tests/unit/indexables/application/next-verification-action-handler-test.php index 676f1390848..2dedef2b74d 100644 --- a/tests/unit/indexables/application/next-verification-action-handler-test.php +++ b/tests/unit/indexables/application/next-verification-action-handler-test.php @@ -18,12 +18,16 @@ class Next_Verification_Action_Handler_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler + * The instance. + * + * @var Next_Verification_Action_Handler */ private $instance; /** - * @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Options_Helper + * The options helper. + * + * @var \Mockery\MockInterface|Options_Helper */ private $options_helper; diff --git a/tests/unit/indexables/application/verification-cron-batch-handler-test.php b/tests/unit/indexables/application/verification-cron-batch-handler-test.php index 0871e5e3880..b1134fc523e 100644 --- a/tests/unit/indexables/application/verification-cron-batch-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-batch-handler-test.php @@ -19,12 +19,16 @@ class Verification_Cron_Batch_Handler_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler + * The instance. + * + * @var Verification_Cron_Batch_Handler */ private $instance; /** - * @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Options_Helper + * The options helper. + * + * @var \Mockery\MockInterface|Options_Helper */ private $options_helper; diff --git a/tests/unit/indexables/domain/batch-size-test.php b/tests/unit/indexables/domain/batch-size-test.php index 64569b6ccf4..6484a3fc59f 100644 --- a/tests/unit/indexables/domain/batch-size-test.php +++ b/tests/unit/indexables/domain/batch-size-test.php @@ -15,7 +15,9 @@ class Batch_Size_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Domain\Batch_Size + * The instance. + * + * @var Batch_Size */ private $instance; diff --git a/tests/unit/indexables/domain/current-verification-action-test.php b/tests/unit/indexables/domain/current-verification-action-test.php index 7b5f5090ff6..9db0719e954 100644 --- a/tests/unit/indexables/domain/current-verification-action-test.php +++ b/tests/unit/indexables/domain/current-verification-action-test.php @@ -16,7 +16,9 @@ class Current_Verification_Action_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action + * The instance. + * + * @var Current_Verification_Action */ private $instance; diff --git a/tests/unit/indexables/domain/last-batch-count-test.php b/tests/unit/indexables/domain/last-batch-count-test.php index 1c3e10e4e36..1e0a1f99f9f 100644 --- a/tests/unit/indexables/domain/last-batch-count-test.php +++ b/tests/unit/indexables/domain/last-batch-count-test.php @@ -16,6 +16,8 @@ class Last_Batch_Count_Test extends TestCase { /** + * The instance. + * * @var \Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count */ private $instance; diff --git a/tests/unit/indexables/domain/outdated-post-indexables-list-test.php b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php index 66d89762d43..2344ef0b423 100644 --- a/tests/unit/indexables/domain/outdated-post-indexables-list-test.php +++ b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php @@ -17,6 +17,8 @@ class Outdated_Post_Indexables_List_Test extends TestCase { /** + * The instance. + * * @var \Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List */ private $instance; diff --git a/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php b/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php index 875179f1b38..16554fa7a02 100644 --- a/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php +++ b/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php @@ -16,18 +16,11 @@ class Plugin_Deactivated_Timestamp_Test extends TestCase { /** - * @var \Yoast\WP\SEO\Indexables\Domain\Plugin_Deactivated_Timestamp - */ - private $instance; - - /** - * The setup function. + * The instance. * - * @return void + * @var Plugin_Deactivated_Timestamp */ - protected function setUp(): void { - parent::setUp(); - } + private $instance; /** * Tests constructor function. diff --git a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php index 5f8497183df..b182ef19ca8 100644 --- a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php @@ -21,6 +21,7 @@ * @group indexables * * @coversDefaultClass \Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration + * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ class Verification_No_Timestamp_Cron_Callback_Integration_Test extends TestCase { From 0a08048f3a1fdff2108ef885ebdf378866042f39 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 29 Jun 2023 12:19:31 +0200 Subject: [PATCH 22/41] More tests --- ...y-post-indexables-command-handler-test.php | 20 ++++++++++++++----- .../mark-deactivation-integration-test.php | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index 46ed70c263e..e884a631a54 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -19,6 +19,7 @@ use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; +use Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -86,7 +87,7 @@ protected function setUp(): void { $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); $this->outdated_post_indexables_repository = Mockery::mock( Outdated_Post_Indexables_Repository_Interface::class ); $this->indexables_builder = Mockery::mock( Indexable_Builder::class ); - $this->command = new Verify_Post_Indexables_Command( 10, 10, \time() ); + $this->command = new Verify_Post_Indexables_Command( 1, 0, \time() ); $this->instance = new Verify_Post_Indexables_Command_Handler( $this->outdated_post_indexables_repository, $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_builder ); } @@ -98,18 +99,27 @@ protected function setUp(): void { */ public function test_handle_with_next_batch() { - $indexable_list = []; + $indexable_list = new Outdated_Post_Indexables_List(); $indexable_mock = Mockery::mock( Indexable::class ); - $indexable_list[] = $indexable_mock; + $indexable_mock1 = Mockery::mock( Indexable::class ); + $indexable_mock2 = Mockery::mock( Indexable::class ); + $indexable_mock3 = Mockery::mock( Indexable::class ); + $indexable_list->add_post_indexable( $indexable_mock); + $indexable_list->add_post_indexable( $indexable_mock1); + $indexable_list->add_post_indexable( $indexable_mock2); + $indexable_list->add_post_indexable( $indexable_mock3); $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) ->with( $this->command->get_last_batch_count() ) ->andReturn( $indexable_list ); $this->indexables_builder->expects()->build( $indexable_mock ); + $this->indexables_builder->expects()->build( $indexable_mock1 ); + $this->indexables_builder->expects()->build( $indexable_mock2 ); + $this->indexables_builder->expects()->build( $indexable_mock3 ); - $this->cron_batch_handler->expects( 'set_current_non_timestamped_indexables_batch' ) - ->with( $this->command->get_last_batch_count(), $this->command->get_batch_size() ); + $this->cron_batch_handler->expects( 'set_current_post_indexables_batch' ) + ->with( 1 ); $this->instance->handle( $this->command ); } diff --git a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php index 2f5d7c635ec..1ebd86c01b6 100644 --- a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php +++ b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php @@ -3,6 +3,7 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\User_Interface; use Mockery; +use Brain\Monkey; use Yoast\WP\SEO\Conditionals\Admin_Conditional; use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\User_Interface\Mark_Deactivation_Integration; @@ -53,6 +54,8 @@ protected function setUp(): void { public function test_register_hooks() { Monkey\Functions\expect( 'add_action' ) ->with( 'wpseo_deactivate', [ $this->instance, 'register_deactivation' ] ); + + $this->instance->register_hooks(); } /** From a825771a187bfa3361882a5f19c58e640e250301 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 30 Oct 2023 11:10:19 +0100 Subject: [PATCH 23/41] cs --- inc/options/class-wpseo-option-wpseo.php | 218 +++++++++++------------ 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/inc/options/class-wpseo-option-wpseo.php b/inc/options/class-wpseo-option-wpseo.php index 201823ddf0c..e923feaee3f 100644 --- a/inc/options/class-wpseo-option-wpseo.php +++ b/inc/options/class-wpseo-option-wpseo.php @@ -26,123 +26,123 @@ class WPSEO_Option_Wpseo extends WPSEO_Option { */ protected $defaults = [ // Non-form fields, set via (ajax) function. - 'tracking' => null, - 'toggled_tracking' => false, - 'license_server_version' => false, - 'ms_defaults_set' => false, - 'ignore_search_engines_discouraged_notice' => false, - 'indexing_first_time' => true, - 'indexing_started' => null, - 'indexing_reason' => '', - 'indexables_indexing_completed' => false, - 'index_now_key' => '', + 'tracking' => null, + 'toggled_tracking' => false, + 'license_server_version' => false, + 'ms_defaults_set' => false, + 'ignore_search_engines_discouraged_notice' => false, + 'indexing_first_time' => true, + 'indexing_started' => null, + 'indexing_reason' => '', + 'indexables_indexing_completed' => false, + 'index_now_key' => '', // Non-form field, should only be set via validation routine. - 'version' => '', // Leave default as empty to ensure activation/upgrade works. - 'previous_version' => '', + 'version' => '', // Leave default as empty to ensure activation/upgrade works. + 'previous_version' => '', // Form fields. - 'disableadvanced_meta' => true, - 'enable_headless_rest_endpoints' => true, - 'ryte_indexability' => false, - 'baiduverify' => '', // Text field. - 'googleverify' => '', // Text field. - 'msverify' => '', // Text field. - 'yandexverify' => '', - 'site_type' => '', // List of options. - 'has_multiple_authors' => '', - 'environment_type' => '', - 'content_analysis_active' => true, - 'keyword_analysis_active' => true, - 'inclusive_language_analysis_active' => false, - 'enable_admin_bar_menu' => true, - 'enable_cornerstone_content' => true, - 'enable_xml_sitemap' => true, - 'enable_text_link_counter' => true, - 'enable_index_now' => true, - 'enable_ai_generator' => false, - 'show_onboarding_notice' => false, - 'first_activated_on' => false, - 'myyoast-oauth' => [ + 'disableadvanced_meta' => true, + 'enable_headless_rest_endpoints' => true, + 'ryte_indexability' => false, + 'baiduverify' => '', // Text field. + 'googleverify' => '', // Text field. + 'msverify' => '', // Text field. + 'yandexverify' => '', + 'site_type' => '', // List of options. + 'has_multiple_authors' => '', + 'environment_type' => '', + 'content_analysis_active' => true, + 'keyword_analysis_active' => true, + 'inclusive_language_analysis_active' => false, + 'enable_admin_bar_menu' => true, + 'enable_cornerstone_content' => true, + 'enable_xml_sitemap' => true, + 'enable_text_link_counter' => true, + 'enable_index_now' => true, + 'enable_ai_generator' => false, + 'show_onboarding_notice' => false, + 'first_activated_on' => false, + 'myyoast-oauth' => [ 'config' => [ 'clientId' => null, 'secret' => null, ], 'access_tokens' => [], ], - 'semrush_integration_active' => true, - 'semrush_tokens' => [], - 'semrush_country_code' => 'us', - 'permalink_structure' => '', - 'home_url' => '', - 'dynamic_permalinks' => false, - 'category_base_url' => '', - 'tag_base_url' => '', - 'custom_taxonomy_slugs' => [], - 'enable_enhanced_slack_sharing' => true, - 'zapier_integration_active' => false, - 'zapier_subscription' => [], - 'zapier_api_key' => '', - 'enable_metabox_insights' => true, - 'enable_link_suggestions' => true, - 'algolia_integration_active' => false, - 'import_cursors' => [], - 'workouts_data' => [ 'configuration' => [ 'finishedSteps' => [] ] ], - 'configuration_finished_steps' => [], - 'dismiss_configuration_workout_notice' => false, - 'dismiss_premium_deactivated_notice' => false, - 'importing_completed' => [], - 'wincher_integration_active' => true, - 'wincher_tokens' => [], - 'wincher_automatically_add_keyphrases' => false, - 'wincher_website_id' => '', - 'wordproof_integration_active' => false, - 'wordproof_integration_changed' => false, - 'first_time_install' => false, - 'should_redirect_after_install_free' => false, - 'activation_redirect_timestamp_free' => 0, - 'remove_feed_global' => false, - 'remove_feed_global_comments' => false, - 'remove_feed_post_comments' => false, - 'remove_feed_authors' => false, - 'remove_feed_categories' => false, - 'remove_feed_tags' => false, - 'remove_feed_custom_taxonomies' => false, - 'remove_feed_post_types' => false, - 'remove_feed_search' => false, - 'remove_atom_rdf_feeds' => false, - 'remove_shortlinks' => false, - 'remove_rest_api_links' => false, - 'remove_rsd_wlw_links' => false, - 'remove_oembed_links' => false, - 'remove_generator' => false, - 'remove_emoji_scripts' => false, - 'remove_powered_by_header' => false, - 'remove_pingback_header' => false, - 'clean_campaign_tracking_urls' => false, - 'clean_permalinks' => false, - 'clean_permalinks_extra_variables' => '', - 'search_cleanup' => false, - 'search_cleanup_emoji' => false, - 'search_cleanup_patterns' => false, - 'search_character_limit' => 50, - 'deny_search_crawling' => false, - 'deny_wp_json_crawling' => false, - 'deny_adsbot_crawling' => false, - 'deny_ccbot_crawling' => false, - 'deny_google_extended_crawling' => false, - 'deny_gptbot_crawling' => false, - 'redirect_search_pretty_urls' => false, - 'least_readability_ignore_list' => [], - 'least_seo_score_ignore_list' => [], - 'most_linked_ignore_list' => [], - 'least_linked_ignore_list' => [], - 'indexables_page_reading_list' => [ false, false, false, false, false ], - 'indexables_overview_state' => 'dashboard-not-visited', - 'last_known_public_post_types' => [], - 'last_known_public_taxonomies' => [], - 'last_known_no_unindexed' => [], - 'new_post_types' => [], - 'new_taxonomies' => [], - 'show_new_content_type_notification' => false, + 'semrush_integration_active' => true, + 'semrush_tokens' => [], + 'semrush_country_code' => 'us', + 'permalink_structure' => '', + 'home_url' => '', + 'dynamic_permalinks' => false, + 'category_base_url' => '', + 'tag_base_url' => '', + 'custom_taxonomy_slugs' => [], + 'enable_enhanced_slack_sharing' => true, + 'zapier_integration_active' => false, + 'zapier_subscription' => [], + 'zapier_api_key' => '', + 'enable_metabox_insights' => true, + 'enable_link_suggestions' => true, + 'algolia_integration_active' => false, + 'import_cursors' => [], + 'workouts_data' => [ 'configuration' => [ 'finishedSteps' => [] ] ], + 'configuration_finished_steps' => [], + 'dismiss_configuration_workout_notice' => false, + 'dismiss_premium_deactivated_notice' => false, + 'importing_completed' => [], + 'wincher_integration_active' => true, + 'wincher_tokens' => [], + 'wincher_automatically_add_keyphrases' => false, + 'wincher_website_id' => '', + 'wordproof_integration_active' => false, + 'wordproof_integration_changed' => false, + 'first_time_install' => false, + 'should_redirect_after_install_free' => false, + 'activation_redirect_timestamp_free' => 0, + 'remove_feed_global' => false, + 'remove_feed_global_comments' => false, + 'remove_feed_post_comments' => false, + 'remove_feed_authors' => false, + 'remove_feed_categories' => false, + 'remove_feed_tags' => false, + 'remove_feed_custom_taxonomies' => false, + 'remove_feed_post_types' => false, + 'remove_feed_search' => false, + 'remove_atom_rdf_feeds' => false, + 'remove_shortlinks' => false, + 'remove_rest_api_links' => false, + 'remove_rsd_wlw_links' => false, + 'remove_oembed_links' => false, + 'remove_generator' => false, + 'remove_emoji_scripts' => false, + 'remove_powered_by_header' => false, + 'remove_pingback_header' => false, + 'clean_campaign_tracking_urls' => false, + 'clean_permalinks' => false, + 'clean_permalinks_extra_variables' => '', + 'search_cleanup' => false, + 'search_cleanup_emoji' => false, + 'search_cleanup_patterns' => false, + 'search_character_limit' => 50, + 'deny_search_crawling' => false, + 'deny_wp_json_crawling' => false, + 'deny_adsbot_crawling' => false, + 'deny_ccbot_crawling' => false, + 'deny_google_extended_crawling' => false, + 'deny_gptbot_crawling' => false, + 'redirect_search_pretty_urls' => false, + 'least_readability_ignore_list' => [], + 'least_seo_score_ignore_list' => [], + 'most_linked_ignore_list' => [], + 'least_linked_ignore_list' => [], + 'indexables_page_reading_list' => [ false, false, false, false, false ], + 'indexables_overview_state' => 'dashboard-not-visited', + 'last_known_public_post_types' => [], + 'last_known_public_taxonomies' => [], + 'last_known_no_unindexed' => [], + 'new_post_types' => [], + 'new_taxonomies' => [], + 'show_new_content_type_notification' => false, 'cron_verify_current_action' => 'term', 'cron_verify_post_indexables_last_batch' => 0, 'cron_verify_non_timestamped_indexables_last_batch' => 0, From 254582900f7342b65eb783a7d9ca41e5e617f3bf Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 1 Nov 2023 16:17:01 +0100 Subject: [PATCH 24/41] Remove unneeded deactivation tracking. --- ...erify-non-timestamp-indexables-command.php | 5 +- .../domain/abstract-indexables-command.php | 24 +---- .../domain/plugin-deactivated-timestamp.php | 25 ----- .../mark-deactivation-integration.php | 54 ---------- ...schedule-verification-cron-integration.php | 2 +- ...no-timestamp-cron-callback-integration.php | 9 +- ...cation-posts-cron-callback-integration.php | 5 +- ...estamp-indexables-command-handler-test.php | 2 +- ...-non-timestamp-indexables-command-test.php | 13 +-- ...y-post-indexables-command-handler-test.php | 2 +- .../verify-post-indexables-command-test.php | 14 +-- .../plugin-deactivated-timestamp-test.php | 34 ------- .../mark-deactivation-integration-test.php | 87 ---------------- ...ule-verification-cron-integration-test.php | 98 ------------------- ...mestamp-cron-callback-integration-test.php | 3 - ...n-posts-cron-callback-integration-test.php | 3 - 16 files changed, 16 insertions(+), 364 deletions(-) delete mode 100644 src/indexables/domain/plugin-deactivated-timestamp.php delete mode 100644 src/indexables/user-interface/mark-deactivation-integration.php delete mode 100644 tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php delete mode 100644 tests/unit/indexables/user-interface/mark-deactivation-integration-test.php delete mode 100644 tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index 8ac85505075..6927038487e 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -23,13 +23,12 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman * * @param int $last_batch The last batch count. * @param int $batch_size The batch size. - * @param string $plugin_deactivated_at The plugin deactivated at timestamp. * @param string $current_action The current verification action. */ - public function __construct( int $last_batch, int $batch_size, string $plugin_deactivated_at, string $current_action ) { + public function __construct( int $last_batch, int $batch_size, string $current_action ) { $this->current_action = new Current_Verification_Action( $current_action ); - parent::__construct( $batch_size, $last_batch, $plugin_deactivated_at ); + parent::__construct( $batch_size, $last_batch ); } /** diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index 58f4e320150..227f1876485 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -14,13 +14,6 @@ abstract class Abstract_Indexables_Command { */ protected $last_batch_count; - /** - * The plugin deactivated timestamp domain object. - * - * @var Plugin_Deactivated_Timestamp $plugin_deactivated_at - */ - protected $plugin_deactivated_at; - /** * The batch size. * @@ -33,12 +26,10 @@ abstract class Abstract_Indexables_Command { * * @param int $batch_size The batch size. * @param int $last_batch The last batch count. - * @param string $plugin_deactivated_at The plugin deactivated at timestamp. */ - public function __construct( int $batch_size, int $last_batch, string $plugin_deactivated_at ) { - $this->last_batch_count = new Last_Batch_Count( $last_batch ); - $this->plugin_deactivated_at = new Plugin_Deactivated_Timestamp( $plugin_deactivated_at ); - $this->batch_size = new Batch_Size( $batch_size ); + public function __construct( int $batch_size, int $last_batch ) { + $this->last_batch_count = new Last_Batch_Count( $last_batch ); + $this->batch_size = new Batch_Size( $batch_size ); } /** @@ -50,15 +41,6 @@ public function get_last_batch_count(): Last_Batch_Count { return $this->last_batch_count; } - /** - * Gets the plugin deactivated at timestamp. - * - * @return Plugin_Deactivated_Timestamp - */ - public function get_plugin_deactivated_at(): Plugin_Deactivated_Timestamp { - return $this->plugin_deactivated_at; - } - /** * Gets the batch size. * diff --git a/src/indexables/domain/plugin-deactivated-timestamp.php b/src/indexables/domain/plugin-deactivated-timestamp.php deleted file mode 100644 index deab73b6eac..00000000000 --- a/src/indexables/domain/plugin-deactivated-timestamp.php +++ /dev/null @@ -1,25 +0,0 @@ -timestamp = $timestamp; - } -} diff --git a/src/indexables/user-interface/mark-deactivation-integration.php b/src/indexables/user-interface/mark-deactivation-integration.php deleted file mode 100644 index 6980f9b9e96..00000000000 --- a/src/indexables/user-interface/mark-deactivation-integration.php +++ /dev/null @@ -1,54 +0,0 @@ -options_helper = $options_helper; - } - - /** - * Registers a deactivation action. - */ - public function register_hooks() { - \add_action( 'wpseo_deactivate', [ $this, 'register_deactivation' ] ); - } - - /** - * Sets a timestamp for the moment the plugin was deactivated. - * - * @return void - */ - public function register_deactivation(): void { - $this->options_helper->set( self::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); - } -} diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index e6037e90d9b..2d23a89d178 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -43,7 +43,7 @@ public function __construct( Options_Helper $options_helper, Verification_Cron_S * Registers the action with WordPress. */ public function register_hooks() { - if ( $this->options_helper->get( 'first_time_install', false ) === false ) { + if ( $this->options_helper->get( 'first_time_install', true ) === false ) { \add_action( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 5538f4a8c9c..873573f6a61 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -114,11 +114,10 @@ public function start_verify_non_timestamped_indexables() { } // @todo add filter here. - $batch_size = 10; - $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); - $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); - $action = $this->verification_action_handler->get_current_verification_action(); - $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $plugin_deactivated, $action ); + $batch_size = 10; + $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); + $action = $this->verification_action_handler->get_current_verification_action(); + $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $action ); $this->non_timestamp_indexables_command_handler->handle( $command ); } diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index ec321f5df09..2ee8058c6b8 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -105,9 +105,8 @@ public function start_verify_posts(): void { } $batch_size = 10; - $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); - $plugin_deactivated = $this->options_helper->get( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); + $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); - $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch, $plugin_deactivated ) ); + $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch ) ); } } diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php index 2fdc160fb52..67fe5795b7c 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php @@ -82,7 +82,7 @@ protected function setUp(): void { $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); $this->indexables_action_factory = Mockery::mock( Verify_Indexables_Action_Factory_Interface::class ); $this->next_verification_action_handler = Mockery::mock( Next_Verification_Action_Handler::class ); - $this->command = new Verify_Non_Timestamp_Indexables_Command( 10, 10, \time(), 'term' ); + $this->command = new Verify_Non_Timestamp_Indexables_Command( 10, 10, 'term' ); $this->instance = new Verify_Non_Timestamp_Indexables_Command_Handler( $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_action_factory, $this->next_verification_action_handler ); } diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php index 423e324504b..d3385932ca5 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php @@ -7,7 +7,6 @@ use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Indexables\Domain\Plugin_Deactivated_Timestamp; use Yoast\WP\SEO\Tests\Unit\TestCase; /** @@ -34,7 +33,7 @@ class Verify_Non_Timestamp_Indexables_Command_Test extends TestCase { protected function setUp(): void { parent::setUp(); - $this->instance = new Verify_Non_Timestamp_Indexables_Command( 10, 10, \time(), 'post' ); + $this->instance = new Verify_Non_Timestamp_Indexables_Command( 10, 10, 'post' ); } /** @@ -59,16 +58,6 @@ public function test_get_last_batch_count() { $this->assertEquals( new Last_Batch_Count( 10 ), $this->instance->get_last_batch_count() ); } - /** - * Tests getting the plugin deactivated at object. - * - * @covers ::get_plugin_deactivated_at - * @return void - */ - public function test_get_plugin_deactivated_at() { - $this->assertEquals( new Plugin_Deactivated_Timestamp( \time() ), $this->instance->get_plugin_deactivated_at() ); - } - /** * Test getting the batch size object. * diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index c5bcefff9fa..6acd0997ca9 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -87,7 +87,7 @@ protected function setUp(): void { $this->cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); $this->outdated_post_indexables_repository = Mockery::mock( Outdated_Post_Indexables_Repository_Interface::class ); $this->indexables_builder = Mockery::mock( Indexable_Builder::class ); - $this->command = new Verify_Post_Indexables_Command( 1, 0, \time() ); + $this->command = new Verify_Post_Indexables_Command( 1, 0 ); $this->instance = new Verify_Post_Indexables_Command_Handler( $this->outdated_post_indexables_repository, $this->cron_schedule_handler, $this->cron_batch_handler, $this->indexables_builder ); } diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php index c019a1d6ca3..a640310a22c 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php @@ -6,9 +6,7 @@ use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; -use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Indexables\Domain\Plugin_Deactivated_Timestamp; use Yoast\WP\SEO\Tests\Unit\TestCase; /** @@ -35,7 +33,7 @@ class Verify_Post_Indexables_Command_Test extends TestCase { protected function setUp(): void { parent::setUp(); - $this->instance = new Verify_Post_Indexables_Command( 10, 10, \time() ); + $this->instance = new Verify_Post_Indexables_Command( 10, 10 ); } /** @@ -49,16 +47,6 @@ public function test_get_last_batch_count() { $this->assertEquals( new Last_Batch_Count( 10 ), $this->instance->get_last_batch_count() ); } - /** - * Tests getting the plugin deactivated at object. - * - * @covers ::get_plugin_deactivated_at - * @return void - */ - public function test_get_plugin_deactivated_at() { - $this->assertEquals( new Plugin_Deactivated_Timestamp( \time() ), $this->instance->get_plugin_deactivated_at() ); - } - /** * Test getting the batch size object. * diff --git a/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php b/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php deleted file mode 100644 index 16554fa7a02..00000000000 --- a/tests/unit/indexables/domain/plugin-deactivated-timestamp-test.php +++ /dev/null @@ -1,34 +0,0 @@ -instance = new Plugin_Deactivated_Timestamp( \time() ); - } -} diff --git a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php b/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php deleted file mode 100644 index 1ebd86c01b6..00000000000 --- a/tests/unit/indexables/user-interface/mark-deactivation-integration-test.php +++ /dev/null @@ -1,87 +0,0 @@ -options_helper = Mockery::mock( Options_Helper::class ); - - $this->instance = new Mark_Deactivation_Integration( $this->options_helper ); - } - - /** - * Tests the get function. - * - * @covers ::register_hooks - * @return void - */ - public function test_register_hooks() { - Monkey\Functions\expect( 'add_action' ) - ->with( 'wpseo_deactivate', [ $this->instance, 'register_deactivation' ] ); - - $this->instance->register_hooks(); - } - - /** - * Tests the get function. - * - * @covers ::get_conditionals - * @return void - */ - public function test_get_conditionals() { - $this->assertEquals( - [ - Admin_Conditional::class, - ], - Mark_Deactivation_Integration::get_conditionals() - ); - } - - /** - * Tests setting the deactivation option. - * - * @covers ::register_deactivation - * @return void - */ - public function test_register_deactivation() { - $this->options_helper->expects()->set( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() ); - - $this->instance->register_deactivation(); - } -} diff --git a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php deleted file mode 100644 index a578d925ff2..00000000000 --- a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php +++ /dev/null @@ -1,98 +0,0 @@ -options_helper = Mockery::mock( Options_Helper::class ); - $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); - - $this->instance = new Schedule_Verification_Cron_Integration( $this->options_helper, $this->cron_schedule_handler ); - } - - /** - * Tests the register_hooks function. - * - * @covers ::register_hooks - * @return void - */ - public function test_register_hooks_ftc() { - $this->options_helper->expects()->get( 'first_time_install', false )->andReturnFalse(); - - Monkey\Functions\expect( 'add_action' ) - ->with( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); - - $this->instance->register_hooks(); - } - - /** - * Tests the register_hooks function. - * - * @covers ::register_hooks - * @return void - */ - public function test_register_hooks_without_ftc() { - $this->options_helper->expects()->get( 'first_time_install', false )->andReturnTrue(); - Monkey\Functions\expect( 'add_action' )->never(); - $this->instance->register_hooks(); - } - - /** - * Tests the get function. - * - * @covers ::get_conditionals - * @return void - */ - public function test_get_conditionals() { - $this->assertEquals( - [ - Admin_Conditional::class, - ], - Schedule_Verification_Cron_Integration::get_conditionals() - ); - } -} diff --git a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php index b182ef19ca8..28a3b92dfa1 100644 --- a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php @@ -11,7 +11,6 @@ use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\User_Interface\Mark_Deactivation_Integration; use Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -166,8 +165,6 @@ public function test_start_verify_non_timestamped_indexables() { $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->never(); $this->verification_cron_batch_handler->expects( 'get_current_non_timestamped_indexables_batch' )->andReturn( 10 ); - $this->options_helper->expects( 'get' ) - ->with( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() )->andReturn( \time() ); $this->next_verification_action_handler->expects( 'get_current_verification_action' )->andReturn( 'term' ); $this->verify_non_timestamp_indexables_command_handler->expects( 'handle' ); diff --git a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php index a002ae2729b..0989a8da8dc 100644 --- a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php @@ -157,9 +157,6 @@ public function test_start_verify_posts_indexables() { $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue(); $this->verification_cron_batch_handler->expects( 'get_current_post_indexables_batch' )->andReturn( 10 ); - $this->options_helper->expects( 'get' ) - ->with( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() )->andReturn( \time() ); - $this->verify_posts_indexables_command_handler->expects( 'handle' ); $this->instance->start_verify_posts(); From 375e7671a95e10e9431396fbffe3a7a28735030c Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 2 Nov 2023 14:31:40 +0100 Subject: [PATCH 25/41] Update scheduling mechanics --- config/dependency-injection/loader-pass.php | 3 --- .../verification-cron-schedule-handler.php | 15 ++++++++++++++- .../domain/abstract-indexables-command.php | 4 ++-- .../schedule-verification-cron-integration.php | 15 ++------------- ...n-no-timestamp-cron-callback-integration.php | 3 +-- ...fication-posts-cron-callback-integration.php | 4 ++-- .../verification-cron-schedule-handler-test.php | 5 ++++- ...timestamp-cron-callback-integration-test.php | 17 ++--------------- ...ion-posts-cron-callback-integration-test.php | 17 ++--------------- 9 files changed, 29 insertions(+), 54 deletions(-) diff --git a/config/dependency-injection/loader-pass.php b/config/dependency-injection/loader-pass.php index 3fee9a2a7e2..445609c98eb 100644 --- a/config/dependency-injection/loader-pass.php +++ b/config/dependency-injection/loader-pass.php @@ -79,9 +79,6 @@ private function process_definition( Definition $definition, Definition $loader_ $definition->setPublic( true ); } - if ( \strpos( $path, 'src' . \DIRECTORY_SEPARATOR . 'indexables' ) ) { - $definition->setPublic( false ); - } } catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch // Catch all for non-existing classes. } diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 3ad4f25499a..0fa8f321f2f 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -2,6 +2,8 @@ namespace Yoast\WP\SEO\Indexables\Application; +use Yoast\WP\SEO\Helpers\Options_Helper; + /** * The Verification_Cron_Schedule_Handler class. */ @@ -24,13 +26,21 @@ class Verification_Cron_Schedule_Handler { */ private $cron_verification_gate; + /** + * The Options_Helper instance. + * + * @var Options_Helper + */ + private $options_helper; + /** * The constructor. * * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. */ - public function __construct( Cron_Verification_Gate $cron_verification_gate ) { + public function __construct( Cron_Verification_Gate $cron_verification_gate, Options_Helper $options_helper ) { $this->cron_verification_gate = $cron_verification_gate; + $this->options_helper = $options_helper; } /** @@ -39,6 +49,9 @@ public function __construct( Cron_Verification_Gate $cron_verification_gate ) { * @return void */ public function schedule_indexable_verification(): void { + if ( $this->options_helper->get( 'activation_redirect_timestamp_free', 0 ) === 0 ) { + return; + } if ( $this->cron_verification_gate->should_verify_on_cron() && ! \wp_next_scheduled( self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) ) { \wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index 227f1876485..5c81cb1fbda 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -24,8 +24,8 @@ abstract class Abstract_Indexables_Command { /** * The constructor. * - * @param int $batch_size The batch size. - * @param int $last_batch The last batch count. + * @param int $batch_size The batch size. + * @param int $last_batch The last batch count. */ public function __construct( int $batch_size, int $last_batch ) { $this->last_batch_count = new Last_Batch_Count( $last_batch ); diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index 2d23a89d178..0c8e9ec28cf 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -21,21 +21,12 @@ class Schedule_Verification_Cron_Integration implements Integration_Interface { */ protected $cron_schedule_handler; - /** - * The options helper. - * - * @var Options_Helper - */ - private $options_helper; - /** * The constructor. * - * @param Options_Helper $options_helper The options helper. * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. */ - public function __construct( Options_Helper $options_helper, Verification_Cron_Schedule_Handler $cron_schedule_handler ) { - $this->options_helper = $options_helper; + public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_handler ) { $this->cron_schedule_handler = $cron_schedule_handler; } @@ -43,8 +34,6 @@ public function __construct( Options_Helper $options_helper, Verification_Cron_S * Registers the action with WordPress. */ public function register_hooks() { - if ( $this->options_helper->get( 'first_time_install', true ) === false ) { - \add_action( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); - } + \add_action( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); } } diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 873573f6a61..c600683cd7f 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -107,13 +107,12 @@ public function register_hooks() { * @return void */ public function start_verify_non_timestamped_indexables() { - if ( \wp_doing_cron() || ! $this->cron_verification_gate->should_verify_on_cron() ) { + if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); return; } - // @todo add filter here. $batch_size = 10; $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); $action = $this->verification_action_handler->get_current_verification_action(); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 2ee8058c6b8..9f7baeb271a 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -98,13 +98,13 @@ public function register_hooks() { * @return void */ public function start_verify_posts(): void { - if ( \wp_doing_cron() || ! $this->cron_verification_gate->should_verify_on_cron() ) { + if ( \wp_doing_cron() && ! $this->cron_verification_gate->should_verify_on_cron() ) { $this->cron_schedule_handler->unschedule_verify_post_indexables_cron(); return; } - $batch_size = 10; + $batch_size = 10; $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch ) ); diff --git a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php index a6f4282c587..8e1c5358479 100644 --- a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php @@ -4,6 +4,7 @@ use Brain\Monkey; use Mockery; +use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -40,8 +41,10 @@ protected function setUp(): void { parent::setUp(); $this->cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); + $options_helper = Mockery::mock( Options_Helper::class ); + $options_helper->expects( 'get' )->with( 'activation_redirect_timestamp_free', 0 )->andReturn( 2 ); - $this->instance = new Verification_Cron_Schedule_Handler( $this->cron_verification_gate ); + $this->instance = new Verification_Cron_Schedule_Handler( $this->cron_verification_gate, $options_helper ); } /** diff --git a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php index 28a3b92dfa1..a54f8a5c74b 100644 --- a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php @@ -125,19 +125,6 @@ public function test_get_conditionals() { ); } - /** - * Tests the `start_verify_non_timestamped_indexables` while a cron is already running. - * - * @covers ::start_verify_non_timestamped_indexables - * - * @return void - */ - public function test_start_verify_non_timestamped_indexables_doing_cron() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); - $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); - $this->instance->start_verify_non_timestamped_indexables(); - } - /** * Tests the `start_verify_non_timestamped_indexables` when no cron is running and indexables are enabled. * @@ -146,7 +133,7 @@ public function test_start_verify_non_timestamped_indexables_doing_cron() { * @return void */ public function test_start_verify_non_timestamped_indexables_indexables_disabled() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnFalse(); $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->once(); $this->instance->start_verify_non_timestamped_indexables(); @@ -160,7 +147,7 @@ public function test_start_verify_non_timestamped_indexables_indexables_disabled * @return void */ public function test_start_verify_non_timestamped_indexables() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue(); $this->cron_schedule_handler->expects( 'unschedule_verify_non_timestamped_indexables_cron' )->never(); diff --git a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php index 0989a8da8dc..b2732ac5de2 100644 --- a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php @@ -118,19 +118,6 @@ public function test_get_conditionals() { ); } - /** - * Tests the `start_verify_posts` while a cron is already running. - * - * @covers ::start_verify_posts - * - * @return void - */ - public function test_start_verify_posts_indexables_doing_cron() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); - $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); - $this->instance->start_verify_posts(); - } - /** * Tests the `start_verify_posts` when no cron is running and indexables are enabled. * @@ -139,7 +126,7 @@ public function test_start_verify_posts_indexables_doing_cron() { * @return void */ public function test_start_verify_posts_indexables_indexables_disabled() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnFalse(); $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); $this->instance->start_verify_posts(); @@ -153,7 +140,7 @@ public function test_start_verify_posts_indexables_indexables_disabled() { * @return void */ public function test_start_verify_posts_indexables() { - Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse(); + Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue(); $this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue(); $this->verification_cron_batch_handler->expects( 'get_current_post_indexables_batch' )->andReturn( 10 ); From 82f7324eef00b70dcbaf2287b47f90e2166ea329 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Fri, 3 Nov 2023 14:39:14 +0100 Subject: [PATCH 26/41] Add comment. --- .../application/verification-cron-schedule-handler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index 0fa8f321f2f..de5372eb34a 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -37,6 +37,7 @@ class Verification_Cron_Schedule_Handler { * The constructor. * * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. + * @param Options_Helper $options_helper The options helper. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, Options_Helper $options_helper ) { $this->cron_verification_gate = $cron_verification_gate; From 52e6c52489d3e587bb169b24cbe79f270b75a2fa Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Fri, 3 Nov 2023 16:03:20 +0100 Subject: [PATCH 27/41] Add batch size filters. --- ...erification-no-timestamp-cron-callback-integration.php | 8 +++++++- .../verification-posts-cron-callback-integration.php | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index c600683cd7f..94fda343825 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -14,6 +14,7 @@ /** * The Verification_Cron_Callback_Integration class. + * * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ class Verification_No_Timestamp_Cron_Callback_Integration implements Integration_Interface { @@ -113,7 +114,12 @@ public function start_verify_non_timestamped_indexables() { return; } - $batch_size = 10; + /** + * Filter: 'Yoast\WP\SEO\no_timestamped_indexable_verify_limit_size' - Adds the possibility to limit the number of items that are indexed when in cron action. + * + * @api int $limit Maximum number of indexables to be indexed per indexing action. + */ + $batch_size = \apply_filters( 'Yoast\WP\SEO\no_timestamped_indexable_verify_limit_size', 15 ); //@phpcs:ignore Yoast.NamingConventions.ValidHookName.MaxExceeded -- The name needs to be descriptive since it is a very niche use case $current_batch = $this->cron_batch_handler->get_current_non_timestamped_indexables_batch(); $action = $this->verification_action_handler->get_current_verification_action(); $command = new Verify_Non_Timestamp_Indexables_Command( $current_batch, $batch_size, $action ); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 9f7baeb271a..17191efe575 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -103,8 +103,12 @@ public function start_verify_posts(): void { return; } - - $batch_size = 10; + /** + * Filter: 'Yoast\WP\SEO\post_verify_indexing_limit_size' - Adds the possibility to limit the number of items that are indexed when in cron action. + * + * @api int $limit Maximum number of indexables to be indexed per indexing action. + */ + $batch_size = \apply_filters( 'Yoast\WP\SEO\post_verify_indexing_limit_size', 15 ); //@phpcs:ignore Yoast.NamingConventions.ValidHookName.MaxExceeded -- The name needs to be descriptive since it is a very niche use case $last_batch = $this->cron_batch_handler->get_current_post_indexables_batch(); $this->verify_post_indexables_command_handler->handle( new Verify_Post_Indexables_Command( $batch_size, $last_batch ) ); From a22a22d2e8ae3eda5f8770e6279b560e98e574a6 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 13 Nov 2023 15:27:05 +0100 Subject: [PATCH 28/41] CS. --- .../verify-indexable-action-factory.php | 10 ++++---- ...n-timestamp-indexables-command-handler.php | 13 ++++++---- ...erify-non-timestamp-indexables-command.php | 7 +++--- ...verify-post-indexables-command-handler.php | 14 +++++++---- .../verify-post-indexables-command.php | 1 - .../application/cron-verification-gate.php | 1 - ...d-post-indexables-repository-interface.php | 5 +--- .../verification-cron-batch-handler.php | 11 +++++---- .../domain/abstract-indexables-command.php | 2 +- ...fy-indexables-action-factory-interface.php | 8 ++++--- .../verify-indexables-action-interface.php | 7 +++--- .../domain/outdated-post-indexables-list.php | 3 +-- .../verify-general-indexables-action.php | 4 ++-- ...y-post-type-archives-indexables-action.php | 12 ++++++---- .../actions/verify-term-indexables-action.php | 9 +++---- .../verify-term-links-indexables-action.php | 9 +++---- ...schedule-verification-cron-integration.php | 1 - ...no-timestamp-cron-callback-integration.php | 24 ++++++++++++++----- ...cation-posts-cron-callback-integration.php | 3 +-- 19 files changed, 82 insertions(+), 62 deletions(-) diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 0e938ab362a..80eb2601f3a 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -9,7 +9,6 @@ use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; -use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Links_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action; @@ -61,10 +60,10 @@ class Verify_Indexable_Action_Factory implements Verify_Indexables_Action_Factor /** * The constructor. * - * @param Verify_Term_Indexables_Action $verify_term_indexables_action The instance. - * @param Verify_General_Indexables_Action $verify_general_indexables_action The instance. + * @param Verify_Term_Indexables_Action $verify_term_indexables_action The instance. + * @param Verify_General_Indexables_Action $verify_general_indexables_action The instance. * @param Verify_Post_Type_Archives_Indexables_Action $verify_post_type_archives_indexables_action The instance. - * @param Verify_Term_Links_Indexables_Action $verify_term_links_indexables_action The instance. + * @param Verify_Term_Links_Indexables_Action $verify_term_links_indexables_action The instance. */ public function __construct( Verify_Term_Indexables_Action $verify_term_indexables_action, @@ -104,7 +103,8 @@ public function get( Current_Verification_Action $verification_action ): Verify_ /** * Determines the next verification action that needs to be taken. * - * @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for. + * @param Current_Verification_Action $current_verification_action_object The current verification object to + * determine the next one for. * * @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left. * @return Current_Verification_Action diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php index 3bcceb0edc4..5a0c7f5cf8e 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php @@ -14,6 +14,7 @@ /** * The Verify_Non_Timestamp_Indexables_Command_Handler class. + * * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ class Verify_Non_Timestamp_Indexables_Command_Handler { @@ -49,10 +50,11 @@ class Verify_Non_Timestamp_Indexables_Command_Handler { /** * The constructor. * - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. - * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. - * @param Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory The verify indexables action factory. - * @param Next_Verification_Action_Handler $action_handler The action handler. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. + * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. + * @param Verify_Indexables_Action_Factory_Interface $verify_indexables_action_factory The verify indexables action + * factory. + * @param Next_Verification_Action_Handler $action_handler The action handler. */ public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_handler, @@ -77,8 +79,9 @@ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_time try { $verification_action = $this->verify_indexables_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); - }catch ( Verify_Action_Not_Found_Exception $exception ) { + } catch ( Verify_Action_Not_Found_Exception $exception ) { $this->cron_schedule_handler->unschedule_verify_non_timestamped_indexables_cron(); + return; } diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php index 6927038487e..1c9036ef7e5 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Indexables\Application\Commands; use Yoast\WP\SEO\Indexables\Domain\Abstract_Indexables_Command; -use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; /** @@ -21,9 +20,9 @@ class Verify_Non_Timestamp_Indexables_Command extends Abstract_Indexables_Comman /** * The constructor. * - * @param int $last_batch The last batch count. - * @param int $batch_size The batch size. - * @param string $current_action The current verification action. + * @param int $last_batch The last batch count. + * @param int $batch_size The batch size. + * @param string $current_action The current verification action. */ public function __construct( int $last_batch, int $batch_size, string $current_action ) { $this->current_action = new Current_Verification_Action( $current_action ); diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index 127b8e5e4a5..09f6ff6498d 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -45,10 +45,13 @@ class Verify_Post_Indexables_Command_Handler { /** * The constructor. * - * @param Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository The outdated post indexables repository. - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. - * @param Verification_Cron_Batch_Handler $verification_cron_batch_handler The verification cron batch handler. - * @param Indexable_Builder $indexable_builder The indexable builder. + * @param Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository The outdated post + * indexables repository. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule + * handler. + * @param Verification_Cron_Batch_Handler $verification_cron_batch_handler The verification cron + * batch handler. + * @param Indexable_Builder $indexable_builder The indexable builder. */ public function __construct( Outdated_Post_Indexables_Repository_Interface $outdated_post_indexables_repository, @@ -88,7 +91,8 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c return; } - $next_batch = ( $verify_post_indexables_command->get_last_batch_count()->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size() ); + $next_batch = ( $verify_post_indexables_command->get_last_batch_count() + ->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size() ); $this->verification_cron_batch_handler->set_current_post_indexables_batch( $next_batch ); } } diff --git a/src/indexables/application/commands/verify-post-indexables-command.php b/src/indexables/application/commands/verify-post-indexables-command.php index c7c5b0cc074..f4d784dd695 100644 --- a/src/indexables/application/commands/verify-post-indexables-command.php +++ b/src/indexables/application/commands/verify-post-indexables-command.php @@ -6,7 +6,6 @@ use Yoast\WP\SEO\Indexables\Domain\Abstract_Indexables_Command; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; - /** * The Verify_Post_Indexables_Command class. */ diff --git a/src/indexables/application/cron-verification-gate.php b/src/indexables/application/cron-verification-gate.php index 5224858ee21..87154cb6c28 100644 --- a/src/indexables/application/cron-verification-gate.php +++ b/src/indexables/application/cron-verification-gate.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Indexables\Application; use Yoast\WP\SEO\Helpers\Indexable_Helper; -use Yoast\WP\SEO\Helpers\Options_Helper; /** * The Cron_Verification_Gate class. diff --git a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php index 57b7be3dffb..4d8d5635fad 100644 --- a/src/indexables/application/ports/outdated-post-indexables-repository-interface.php +++ b/src/indexables/application/ports/outdated-post-indexables-repository-interface.php @@ -6,7 +6,6 @@ use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List; -use Yoast\WP\SEO\Indexables\Domain\Plugin_Deactivated_Timestamp; interface Outdated_Post_Indexables_Repository_Interface { @@ -19,7 +18,5 @@ interface Outdated_Post_Indexables_Repository_Interface { * @throws No_Outdated_Posts_Found_Exception When there are no outdated posts found. * @return Outdated_Post_Indexables_List */ - public function get_outdated_post_indexables( - Last_Batch_Count $count - ): Outdated_Post_Indexables_List; + public function get_outdated_post_indexables( Last_Batch_Count $count ): Outdated_Post_Indexables_List; } diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index 01f32db2d47..c2cae1b9b8f 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -32,7 +32,7 @@ public function __construct( Options_Helper $options_helper ) { * * @return int */ - public function get_current_post_indexables_batch():int { + public function get_current_post_indexables_batch(): int { return $this->options_helper->get( 'cron_verify_post_indexables_last_batch', 0 ); } @@ -52,7 +52,7 @@ public function set_current_post_indexables_batch( int $batch_count ) { * * @return int */ - public function get_current_non_timestamped_indexables_batch():int { + public function get_current_non_timestamped_indexables_batch(): int { return $this->options_helper->get( 'cron_verify_non_timestamped_indexables_last_batch', 0 ); } @@ -60,11 +60,14 @@ public function get_current_non_timestamped_indexables_batch():int { * Sets the `cron_verify_non_timestamped_indexables_last_batch` option. * * @param Last_Batch_Count $last_batch_count The current batch count. - * @param Batch_Size $batch_size The batch size. + * @param Batch_Size $batch_size The batch size. * * @return void */ - public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ) { + public function set_current_non_timestamped_indexables_batch( + Last_Batch_Count $last_batch_count, + Batch_Size $batch_size + ) { $batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); $this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count ); } diff --git a/src/indexables/domain/abstract-indexables-command.php b/src/indexables/domain/abstract-indexables-command.php index 5c81cb1fbda..d466ef4145c 100644 --- a/src/indexables/domain/abstract-indexables-command.php +++ b/src/indexables/domain/abstract-indexables-command.php @@ -25,7 +25,7 @@ abstract class Abstract_Indexables_Command { * The constructor. * * @param int $batch_size The batch size. - * @param int $last_batch The last batch count. + * @param int $last_batch The last batch count. */ public function __construct( int $batch_size, int $last_batch ) { $this->last_batch_count = new Last_Batch_Count( $last_batch ); diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index e9ab5f46e32..a3fc839a217 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -22,15 +22,17 @@ interface Verify_Indexables_Action_Factory_Interface { * @throws Verify_Action_Not_Found_Exception When the given verification action does not exists. * @return Verify_Indexables_Action_Interface */ - public function get( Current_Verification_Action $verification_action ):Verify_Indexables_Action_Interface; + public function get( Current_Verification_Action $verification_action ): Verify_Indexables_Action_Interface; /** * Determines the next verification action that needs to be taken. * - * @param Current_Verification_Action $current_verification_action_object The current verification object to determine the next one for. + * @param Current_Verification_Action $current_verification_action_object The current verification object to + * determine the next one for. * * @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left. * @return Current_Verification_Action */ - public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ):Current_Verification_Action; + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object + ): Current_Verification_Action; } diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 40a49fe01e2..1c23e7053b3 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -5,7 +5,6 @@ use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Models\Indexable; /** * The Verify_Indexables_Action_Interface interface. @@ -16,11 +15,11 @@ interface Verify_Indexables_Action_Interface { * Rebuilds indexables for the given action type. * * @param Last_Batch_Count $last_batch_count The last batch count domain object. - * @param Batch_Size $batch_size The batch size domain object. + * @param Batch_Size $batch_size The batch size domain object. * * @return bool return false if there are no objects left to re-build. */ - public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size):bool; + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool; /** * Sets the wpdb instance. @@ -30,5 +29,5 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S * @return mixed * @required */ - public function set_wpdb( \wpdb $wpdb); + public function set_wpdb( \wpdb $wpdb ); } diff --git a/src/indexables/domain/outdated-post-indexables-list.php b/src/indexables/domain/outdated-post-indexables-list.php index c9fc3f46d59..f6593262129 100644 --- a/src/indexables/domain/outdated-post-indexables-list.php +++ b/src/indexables/domain/outdated-post-indexables-list.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Indexables\Domain; -use WP_Post; use Yoast\WP\SEO\Models\Indexable; /** @@ -93,7 +92,7 @@ public function valid(): bool { * * @return int */ - public function count():int { + public function count(): int { return \count( $this->post_indexables_list ); } } diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index edaa0f1cf15..507c1494272 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -31,7 +31,7 @@ class Verify_General_Indexables_Action implements Verify_Indexables_Action_Inter /** * The constructor. * - * @param Indexable_Repository $repository The indexable repository. + * @param Indexable_Repository $repository The indexable repository. * @param Indexable_Builder $indexable_builder The indexable builder. */ public function __construct( Indexable_Repository $repository, Indexable_Builder $indexable_builder ) { @@ -50,7 +50,7 @@ public function __construct( Indexable_Repository $repository, Indexable_Builder * Rebuilds the indexables for the general pages. * * @param Last_Batch_Count $last_batch_count The last batch count domain object. - * @param Batch_Size $batch_size The batch size domain object. + * @param Batch_Size $batch_size The batch size domain object. * * @return bool */ diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php index 2e38bb93286..ee290885666 100644 --- a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -48,11 +48,15 @@ class Verify_Post_Type_Archives_Indexables_Action implements Verify_Indexables_A /** * The constructor. * - * @param Post_Type_Helper $post_type_helper The post type helper. - * @param Indexable_Builder $indexable_builder The indexable builder. + * @param Post_Type_Helper $post_type_helper The post type helper. + * @param Indexable_Builder $indexable_builder The indexable builder. * @param Indexable_Repository $indexable_repository The indexable repository. */ - public function __construct( Post_Type_Helper $post_type_helper, Indexable_Builder $indexable_builder, Indexable_Repository $indexable_repository ) { + public function __construct( + Post_Type_Helper $post_type_helper, + Indexable_Builder $indexable_builder, + Indexable_Repository $indexable_repository + ) { $this->post_type_helper = $post_type_helper; $this->indexable_builder = $indexable_builder; @@ -63,7 +67,7 @@ public function __construct( Post_Type_Helper $post_type_helper, Indexable_Build * Rebuilds the indexables for post type archives. * * @param Last_Batch_Count $last_batch_count The last batch count domain object. - * @param Batch_Size $batch_size The batch size domain object. + * @param Batch_Size $batch_size The batch size domain object. * * @return bool */ diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 0d77192e182..2bcef6b491a 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -31,7 +31,7 @@ class Verify_Term_Indexables_Action implements Verify_Indexables_Action_Interfac /** * The constructor. * - * @param Taxonomy_Helper $taxonomy The taxonomy helper. + * @param Taxonomy_Helper $taxonomy The taxonomy helper. * @param Indexable_Repository $repository The indexable repository. */ public function __construct( Taxonomy_Helper $taxonomy, Indexable_Repository $repository ) { @@ -50,7 +50,7 @@ public function __construct( Taxonomy_Helper $taxonomy, Indexable_Repository $re * Re builds indexables for term indexables. * * @param Last_Batch_Count $last_batch_count The last batch count domain object. - * @param Batch_Size $batch_size The batch size domain object. + * @param Batch_Size $batch_size The batch size domain object. * * @return bool */ @@ -83,7 +83,7 @@ public function set_wpdb( \wpdb $wpdb ) { /** * Creates the query to get all the taxonomies. * - * @param int $limit The query limit. + * @param int $limit The query limit. * @param int $batch_size The batch size for the queries. * * @return string|null @@ -100,7 +100,8 @@ private function get_query( $limit, $batch_size ) { $offset_query = ''; if ( $limit !== 0 ) { $offset_query = ' OFFSET %d'; - $replacements[] = ( $limit + $batch_size );} + $replacements[] = ( $limit + $batch_size ); + } // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. return $this->wpdb->prepare( diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index c5c07814d3e..13abe6cdfd8 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -46,8 +46,8 @@ class Verify_Term_Links_Indexables_Action implements Verify_Indexables_Action_In /** * The constructor. * - * @param Taxonomy_Helper $taxonomy The taxonomy helper. - * @param Indexable_Repository $repository The indexable repository. + * @param Taxonomy_Helper $taxonomy The taxonomy helper. + * @param Indexable_Repository $repository The indexable repository. * @param Indexable_Link_Builder $link_builder The link builder. */ public function __construct( @@ -64,7 +64,7 @@ public function __construct( * Re builds indexables for term links. * * @param Last_Batch_Count $last_batch_count The last batch count domain object. - * @param Batch_Size $batch_size The batch size domain object. + * @param Batch_Size $batch_size The batch size domain object. * * @return bool */ @@ -113,7 +113,7 @@ public function set_wpdb( \wpdb $wpdb ) { /** * Creates the query to get all the taxonomy link options. * - * @param int $limit The query limit. + * @param int $limit The query limit. * @param int $batch_size The batch size for the queries. * * @return string|null @@ -133,6 +133,7 @@ private function get_query( $limit, $batch_size ) { $offset_query = 'OFFSET %d'; $replacements[] = ( $limit + $batch_size ); } + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. return $this->wpdb->prepare( " diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index 0c8e9ec28cf..68e2868f71e 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Indexables\User_Interface; use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; -use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Integrations\Integration_Interface; diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index 94fda343825..c5e066f8dea 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -66,12 +66,24 @@ class Verification_No_Timestamp_Cron_Callback_Integration implements Integration /** * The constructor. * - * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. - * @param Options_Helper $options_helper The options helper. - * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. - * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler The non timestamp indexables command handler. - * @param Next_Verification_Action_Handler $verification_action_handler The verification action handler. + * @param Cron_Verification_Gate $cron_verification_gate The cron + * verification + * gate. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron + * schedule + * handler. + * @param Options_Helper $options_helper The options + * helper. + * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch + * handler. + * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler The non + * timestamp + * indexables + * command + * handler. + * @param Next_Verification_Action_Handler $verification_action_handler The + * verification + * action handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 17191efe575..88656a91ee1 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -62,8 +62,7 @@ class Verification_Posts_Cron_Callback_Integration implements Integration_Interf * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. * @param Options_Helper $options_helper The options helper. * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. - * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler The verify post indexables - * command handler. + * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler The verify post indexables command handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, From 449c46c890c290581b3d86ba95247389120a6578 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 14 Nov 2023 23:01:55 +0100 Subject: [PATCH 29/41] Initial run of some more CS and first feedback. --- admin/tracking/class-tracking-settings-data.php | 1 - .../actions/verify-indexable-action-factory.php | 6 ++---- ...fy-non-timestamp-indexables-command-handler.php | 1 - .../commands/verify-post-indexables-command.php | 1 - .../application/cron-verification-gate.php | 4 ++-- .../verification-cron-batch-handler.php | 6 +++--- .../verification-cron-schedule-handler.php | 4 ++-- src/indexables/domain/batch-size.php | 4 ++-- .../no-non-timestamped-objects-found-exception.php | 2 +- .../no-outdated-posts-found-exception.php | 2 +- .../no-verification-action-left-exception.php | 6 +++--- .../domain/outdated-post-indexables-list.php | 3 +-- .../actions/verify-general-indexables-action.php | 14 +++++++------- ...verify-post-type-archives-indexables-action.php | 1 - .../actions/verify-term-indexables-action.php | 5 ++--- .../outdated-post-indexables-repository.php | 1 - ...erification-posts-cron-callback-integration.php | 11 +---------- src/integrations/settings-integration.php | 2 -- 18 files changed, 27 insertions(+), 47 deletions(-) diff --git a/admin/tracking/class-tracking-settings-data.php b/admin/tracking/class-tracking-settings-data.php index baadded8630..7d4a7b5b82f 100644 --- a/admin/tracking/class-tracking-settings-data.php +++ b/admin/tracking/class-tracking-settings-data.php @@ -238,7 +238,6 @@ class WPSEO_Tracking_Settings_Data implements WPSEO_Collection { 'cron_verify_current_action', 'cron_verify_post_indexables_last_batch', 'cron_verify_non_timestamped_indexables_last_batch', - 'plugin_deactivated_at', ]; /** diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 80eb2601f3a..36126e8ceb8 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -26,7 +26,6 @@ class Verify_Indexable_Action_Factory implements Verify_Indexables_Action_Factor 'general', 'post-type-archives', 'term_links', - 'post_links', ]; /** @@ -109,12 +108,11 @@ public function get( Current_Verification_Action $verification_action ): Verify_ * @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left. * @return Current_Verification_Action */ - public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object - ): Current_Verification_Action { + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ): Current_Verification_Action { $current_verification_action = $current_verification_action_object->get_action(); if ( \in_array( $current_verification_action, self::VERIFICATION_MAPPING, true ) ) { - $key = array_search( $current_verification_action, self::VERIFICATION_MAPPING, true ); + $key = \array_search( $current_verification_action, self::VERIFICATION_MAPPING, true ); if ( isset( self::VERIFICATION_MAPPING[ ++$key ] ) ) { return new Current_Verification_Action( self::VERIFICATION_MAPPING[ $key ] ); } diff --git a/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php index 5a0c7f5cf8e..c104912359b 100644 --- a/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-non-timestamp-indexables-command-handler.php @@ -76,7 +76,6 @@ public function __construct( * @return void */ public function handle( Verify_Non_Timestamp_Indexables_Command $verify_non_timestamp_indexables_command ): void { - try { $verification_action = $this->verify_indexables_action_factory->get( $verify_non_timestamp_indexables_command->get_current_action() ); } catch ( Verify_Action_Not_Found_Exception $exception ) { diff --git a/src/indexables/application/commands/verify-post-indexables-command.php b/src/indexables/application/commands/verify-post-indexables-command.php index f4d784dd695..d4f469138d3 100644 --- a/src/indexables/application/commands/verify-post-indexables-command.php +++ b/src/indexables/application/commands/verify-post-indexables-command.php @@ -4,7 +4,6 @@ namespace Yoast\WP\SEO\Indexables\Application\Commands; use Yoast\WP\SEO\Indexables\Domain\Abstract_Indexables_Command; -use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; /** * The Verify_Post_Indexables_Command class. diff --git a/src/indexables/application/cron-verification-gate.php b/src/indexables/application/cron-verification-gate.php index 87154cb6c28..5d4e9acfddc 100644 --- a/src/indexables/application/cron-verification-gate.php +++ b/src/indexables/application/cron-verification-gate.php @@ -26,11 +26,11 @@ public function __construct( Indexable_Helper $indexable_helper ) { } /** - * Determine whether cron verification of indexables should be performed. + * Determines whether cron verification of indexables should be performed. * * @return bool Should cron verification be performed. */ - public function should_verify_on_cron() { + public function should_verify_on_cron(): bool { if ( ! $this->indexable_helper->should_index_indexables() ) { return false; } diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index c2cae1b9b8f..626987091fb 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -28,7 +28,7 @@ public function __construct( Options_Helper $options_helper ) { } /** - * Gets the `cron_verify_post_indexables_last_batch` option + * Gets the `cron_verify_post_indexables_last_batch` option. * * @return int */ @@ -37,7 +37,7 @@ public function get_current_post_indexables_batch(): int { } /** - * Sets the `cron_verify_post_indexables_last_batch` option + * Sets the `cron_verify_post_indexables_last_batch` option. * * @param int $batch_count The batch count. * @@ -48,7 +48,7 @@ public function set_current_post_indexables_batch( int $batch_count ) { } /** - * Gets the `cron_verify_non_timestamped_indexables_last_batch` option + * Gets the `cron_verify_non_timestamped_indexables_last_batch` option. * * @return int */ diff --git a/src/indexables/application/verification-cron-schedule-handler.php b/src/indexables/application/verification-cron-schedule-handler.php index de5372eb34a..e64945592b3 100644 --- a/src/indexables/application/verification-cron-schedule-handler.php +++ b/src/indexables/application/verification-cron-schedule-handler.php @@ -10,12 +10,12 @@ class Verification_Cron_Schedule_Handler { /** - * The name of the CRON job. + * The name of the cron job. */ public const INDEXABLE_VERIFY_POST_INDEXABLES_NAME = 'wpseo_indexable_verify_post_indexables'; /** - * The name of the CRON job. + * The name of the cron job. */ public const INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME = 'wpseo_indexable_verify_non_timestamped_indexables'; diff --git a/src/indexables/domain/batch-size.php b/src/indexables/domain/batch-size.php index d6bd0fc64d3..9862c5233ba 100644 --- a/src/indexables/domain/batch-size.php +++ b/src/indexables/domain/batch-size.php @@ -35,11 +35,11 @@ public function get_batch_size(): int { /** * Checks if the batch is bigger than the count. * - * @param int|null $count The count to check. + * @param int $count The count to check. * * @return bool */ - public function should_keep_going( ?int $count ): bool { + public function should_keep_going( int $count ): bool { return $count >= $this->get_batch_size(); } } diff --git a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php index 0454ab37b18..9a36219d51f 100644 --- a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php +++ b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php @@ -15,7 +15,7 @@ class No_Non_Timestamped_Objects_Found_Exception extends \Exception { * * @return No_Non_Timestamped_Objects_Found_Exception The exception. */ - public static function because_no_objects_queried() { + public static function because_no_objects_queried(): self { return new self( 'No objects found.' ); diff --git a/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php index a8700a73a4a..f0060adbf62 100644 --- a/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php +++ b/src/indexables/domain/exceptions/no-outdated-posts-found-exception.php @@ -15,7 +15,7 @@ class No_Outdated_Posts_Found_Exception extends Exception { * * @return No_Outdated_Posts_Found_Exception The exception. */ - public static function because_no_outdated_posts_queried() { + public static function because_no_outdated_posts_queried(): self { return new self( 'No outdated posts found.' ); diff --git a/src/indexables/domain/exceptions/no-verification-action-left-exception.php b/src/indexables/domain/exceptions/no-verification-action-left-exception.php index 5e64df0981a..53348942794 100644 --- a/src/indexables/domain/exceptions/no-verification-action-left-exception.php +++ b/src/indexables/domain/exceptions/no-verification-action-left-exception.php @@ -6,14 +6,14 @@ /** * The No_Verification_Action_Left_Exception exception. */ -class No_Verification_Action_Left_Exception extends \Exception { +class No_Verification_Action_Left_Exception extends \Exception { /** * Named constructor to create this exception for when there are no verification actions left. * * @return No_Verification_Action_Left_Exception The exception. */ - public static function because_out_of_bounds() { + public static function because_out_of_bounds(): self { return new self( 'No verification actions left process is done.' ); @@ -26,7 +26,7 @@ public static function because_out_of_bounds() { * * @return No_Verification_Action_Left_Exception The exception. */ - public static function because_unidentified_action_given( $verification_action ) { + public static function because_unidentified_action_given( string $verification_action ): self { return new self( "The passed verification action $verification_action is not found" ); diff --git a/src/indexables/domain/outdated-post-indexables-list.php b/src/indexables/domain/outdated-post-indexables-list.php index f6593262129..a7b4eb5203e 100644 --- a/src/indexables/domain/outdated-post-indexables-list.php +++ b/src/indexables/domain/outdated-post-indexables-list.php @@ -37,7 +37,7 @@ public function __construct() { * * @return void */ - public function add_post_indexable( Indexable $post ) { + public function add_post_indexable( Indexable $post ): void { $this->post_indexables_list[] = $post; } @@ -56,7 +56,6 @@ public function rewind(): void { * @return Indexable */ public function current(): Indexable { - return $this->post_indexables_list[ $this->position ]; } diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index 507c1494272..9a6ef107777 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -28,6 +28,13 @@ class Verify_General_Indexables_Action implements Verify_Indexables_Action_Inter */ protected $indexable_builder; + /** + * The wp query. + * + * @var \wpdb $wpdb + */ + private $wpdb; + /** * The constructor. * @@ -39,13 +46,6 @@ public function __construct( Indexable_Repository $repository, Indexable_Builder $this->indexable_builder = $indexable_builder; } - /** - * The wp query. - * - * @var \wpdb $wpdb - */ - private $wpdb; - /** * Rebuilds the indexables for the general pages. * diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php index ee290885666..43208a5eddf 100644 --- a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -57,7 +57,6 @@ public function __construct( Indexable_Builder $indexable_builder, Indexable_Repository $indexable_repository ) { - $this->post_type_helper = $post_type_helper; $this->indexable_builder = $indexable_builder; $this->indexable_repository = $indexable_repository; diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 2bcef6b491a..3688563074e 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -64,7 +64,6 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S $this->repository->build_by_id_and_type( (int) $term_id, 'term' ); } - return $batch_size->should_keep_going( \count( $term_ids ) ); } @@ -86,9 +85,9 @@ public function set_wpdb( \wpdb $wpdb ) { * @param int $limit The query limit. * @param int $batch_size The batch size for the queries. * - * @return string|null + * @return string */ - private function get_query( $limit, $batch_size ) { + private function get_query( int $limit, int $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 0b99f71d1fc..390f10f1c65 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -76,7 +76,6 @@ public function get_outdated_post_indexables( ): Outdated_Post_Indexables_List { $indexable_table = Model::get_table_name( 'Indexable' ); - $post_types = $this->post_type_helper->get_indexable_post_types(); $excluded_post_statuses = $this->post_helper->get_excluded_post_statuses(); $query = $this->indexable_repository->query(); diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 88656a91ee1..9730ea7849c 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -26,13 +26,6 @@ class Verification_Posts_Cron_Callback_Integration implements Integration_Interf */ private $cron_schedule_handler; - /** - * The options helper instance. - * - * @var Options_Helper $options_helper - */ - private $options_helper; - /** * The cron batch handler instance. * @@ -60,20 +53,17 @@ class Verification_Posts_Cron_Callback_Integration implements Integration_Interf * @param Cron_Verification_Gate $cron_verification_gate The cron verification * gate. * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. - * @param Options_Helper $options_helper The options helper. * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. * @param Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler The verify post indexables command handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, Verification_Cron_Schedule_Handler $cron_schedule_handler, - Options_Helper $options_helper, Verification_Cron_Batch_Handler $cron_batch_handler, Verify_Post_Indexables_Command_Handler $verify_post_indexables_command_handler ) { $this->cron_verification_gate = $cron_verification_gate; $this->cron_schedule_handler = $cron_schedule_handler; - $this->options_helper = $options_helper; $this->cron_batch_handler = $cron_batch_handler; $this->verify_post_indexables_command_handler = $verify_post_indexables_command_handler; } @@ -102,6 +92,7 @@ public function start_verify_posts(): void { return; } + /** * Filter: 'Yoast\WP\SEO\post_verify_indexing_limit_size' - Adds the possibility to limit the number of items that are indexed when in cron action. * diff --git a/src/integrations/settings-integration.php b/src/integrations/settings-integration.php index fd961bb9ce5..b6ebe553de9 100644 --- a/src/integrations/settings-integration.php +++ b/src/integrations/settings-integration.php @@ -70,11 +70,9 @@ class Settings_Integration implements Integration_Interface { 'most_linked_ignore_list', 'least_linked_ignore_list', 'indexables_page_reading_list', - 'last_known_no_unindexed', 'cron_verify_current_action', 'cron_verify_post_indexables_last_batch', 'cron_verify_non_timestamped_indexables_last_batch', - 'plugin_deactivated_at', 'show_new_content_type_notification', 'new_post_types', 'new_taxonomies', From bd4447e37638543ffdf1273ad8af9a36779bf7e9 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Wed, 15 Nov 2023 12:11:52 +0100 Subject: [PATCH 30/41] Actually use exception as intended. --- ...on-timestamped-objects-found-exception.php | 23 ------------------- .../outdated-post-indexables-repository.php | 6 +++++ 2 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php diff --git a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php b/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php deleted file mode 100644 index 9a36219d51f..00000000000 --- a/src/indexables/domain/exceptions/no-non-timestamped-objects-found-exception.php +++ /dev/null @@ -1,23 +0,0 @@ -find_many(); + if ( \count( $indexables ) === 0 ) { + throw No_Outdated_Posts_Found_Exception::because_no_outdated_posts_queried(); + } + $indexable_list = new Outdated_Post_Indexables_List(); foreach ( $indexables as $indexable ) { $indexable_list->add_post_indexable( $indexable ); From dd1fa1e908f6015b18efa7f4634b8a956366d477 Mon Sep 17 00:00:00 2001 From: thijsoo Date: Wed, 15 Nov 2023 12:19:55 +0100 Subject: [PATCH 31/41] Update src/indexables/infrastructure/actions/verify-term-indexables-action.php Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../infrastructure/actions/verify-term-indexables-action.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 3688563074e..282f6cfc568 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -63,7 +63,6 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S foreach ( $term_ids as $term_id ) { $this->repository->build_by_id_and_type( (int) $term_id, 'term' ); } - return $batch_size->should_keep_going( \count( $term_ids ) ); } From 577c34087b0bb56512c57c6afb48f12a6386ceee Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 16 Nov 2023 15:13:04 +0100 Subject: [PATCH 32/41] Feedback. --- inc/options/class-wpseo-option-wpseo.php | 10 ++++-- .../verify-indexable-action-factory.php | 3 +- ...verify-post-indexables-command-handler.php | 7 +++-- .../verification-cron-batch-handler.php | 11 +++++-- .../actions/verify-term-indexables-action.php | 4 +-- .../verify-term-links-indexables-action.php | 31 ++++++------------- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/inc/options/class-wpseo-option-wpseo.php b/inc/options/class-wpseo-option-wpseo.php index 607c9146394..fb6aa737f4c 100644 --- a/inc/options/class-wpseo-option-wpseo.php +++ b/inc/options/class-wpseo-option-wpseo.php @@ -394,8 +394,6 @@ protected function validate_option( $dirty, $clean, $old ) { case 'first_activated_on': case 'indexing_started': case 'activation_redirect_timestamp_free': - case 'cron_verify_post_indexables_last_batch': - case 'cron_verify_non_timestamped_indexables_last_batch': $clean[ $key ] = false; if ( isset( $dirty[ $key ] ) ) { if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) ) { @@ -403,7 +401,13 @@ protected function validate_option( $dirty, $clean, $old ) { } } break; - + case 'cron_verify_post_indexables_last_batch': + case 'cron_verify_non_timestamped_indexables_last_batch': + $clean[ $key ] = 0; + if ( isset( $dirty[ $key ] ) && WPSEO_Utils::validate_int( $dirty[ $key ] ) ) { + $clean[ $key ] = $dirty[ $key ]; + } + break; case 'tracking': $clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : null ); break; diff --git a/src/indexables/application/actions/verify-indexable-action-factory.php b/src/indexables/application/actions/verify-indexable-action-factory.php index 36126e8ceb8..1c3fca09901 100644 --- a/src/indexables/application/actions/verify-indexable-action-factory.php +++ b/src/indexables/application/actions/verify-indexable-action-factory.php @@ -14,7 +14,8 @@ use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action; /** - * The Verify_Indexable_Action_Factory class + * The Verify_Indexable_Action_Factory class. + * This class determines and selects the right indexing action for the current type of indexable that is indexed. */ class Verify_Indexable_Action_Factory implements Verify_Indexables_Action_Factory_Interface { diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index 09f6ff6498d..7e4c27d4ce9 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -91,8 +91,9 @@ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_c return; } - $next_batch = ( $verify_post_indexables_command->get_last_batch_count() - ->get_last_batch() + $verify_post_indexables_command->get_batch_size()->get_batch_size() ); - $this->verification_cron_batch_handler->set_current_post_indexables_batch( $next_batch ); + $this->verification_cron_batch_handler->set_current_post_indexables_batch( + $verify_post_indexables_command->get_last_batch_count(), + $verify_post_indexables_command->get_batch_size() + ); } } diff --git a/src/indexables/application/verification-cron-batch-handler.php b/src/indexables/application/verification-cron-batch-handler.php index 626987091fb..a4e8d841555 100644 --- a/src/indexables/application/verification-cron-batch-handler.php +++ b/src/indexables/application/verification-cron-batch-handler.php @@ -39,11 +39,16 @@ public function get_current_post_indexables_batch(): int { /** * Sets the `cron_verify_post_indexables_last_batch` option. * - * @param int $batch_count The batch count. + * @param Last_Batch_Count $last_batch_count The current batch count. + * @param Batch_Size $batch_size The batch size. * * @return void */ - public function set_current_post_indexables_batch( int $batch_count ) { + public function set_current_post_indexables_batch( + Last_Batch_Count $last_batch_count, + Batch_Size $batch_size + ): void { + $batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); $this->options_helper->set( 'cron_verify_post_indexables_last_batch', $batch_count ); } @@ -67,7 +72,7 @@ public function get_current_non_timestamped_indexables_batch(): int { public function set_current_non_timestamped_indexables_batch( Last_Batch_Count $last_batch_count, Batch_Size $batch_size - ) { + ): void { $batch_count = ( $last_batch_count->get_last_batch() + $batch_size->get_batch_size() ); $this->options_helper->set( 'cron_verify_non_timestamped_indexables_last_batch', $batch_count ); } diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 3688563074e..1376c4ad2b9 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -90,9 +90,7 @@ public function set_wpdb( \wpdb $wpdb ) { private function get_query( int $limit, int $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); - - $replacements = []; - \array_push( $replacements, ...$public_taxonomies ); + $replacements = $public_taxonomies; $limit_query = 'LIMIT %d'; $replacements[] = $batch_size; diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index 13abe6cdfd8..a26e3de4084 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -74,20 +74,9 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_query returns a prepared query. $terms = $this->wpdb->get_results( $query ); - $term_list = \array_map( - static function ( $term ) { - return (object) [ - 'id' => (int) $term->term_id, - 'type' => 'term', - 'content' => $term->description, - ]; - }, - $terms - ); - $indexables = []; - foreach ( $term_list as $term ) { - $indexable = $this->repository->find_by_id_and_type( $term->id, $term->type ); + foreach ( $terms as $term ) { + $indexable = $this->repository->find_by_id_and_type( (int) $term->id, 'term' ); if ( $indexable ) { $this->link_builder->build( $indexable, $term->content ); @@ -116,15 +105,12 @@ public function set_wpdb( \wpdb $wpdb ) { * @param int $limit The query limit. * @param int $batch_size The batch size for the queries. * - * @return string|null + * @return string */ private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); - - $replacements = []; - \array_push( $replacements, ...$public_taxonomies ); - + $replacements = $public_taxonomies; $limit_query = 'LIMIT %d'; $replacements[] = $batch_size; @@ -134,13 +120,14 @@ private function get_query( $limit, $batch_size ) { $replacements[] = ( $limit + $batch_size ); } - // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. + // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: These can be removed in the next version of WPCS. return $this->wpdb->prepare( - " + ' SELECT term_id, description - FROM {$taxonomy_table} AS T - WHERE taxonomy IN (" . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") + FROM %i AS T + WHERE taxonomy IN (' . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") $limit_query $offset_query", + $taxonomy_table, $replacements ); } From f1dad56e73490cc5615234d62dc03c221f4c4941 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 16 Nov 2023 15:35:01 +0100 Subject: [PATCH 33/41] Fix unit tests. --- ...erify-post-indexables-command-handler-test.php | 2 +- .../verification-cron-batch-handler-test.php | 4 ++-- ...ation-posts-cron-callback-integration-test.php | 15 +-------------- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index 6acd0997ca9..947a8b82db6 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -119,7 +119,7 @@ public function test_handle_with_next_batch() { $this->indexables_builder->expects()->build( $indexable_mock3 ); $this->cron_batch_handler->expects( 'set_current_post_indexables_batch' ) - ->with( 1 ); + ->with( $this->command->get_last_batch_count(), $this->command->get_batch_size() ); $this->instance->handle( $this->command ); } diff --git a/tests/unit/indexables/application/verification-cron-batch-handler-test.php b/tests/unit/indexables/application/verification-cron-batch-handler-test.php index b1134fc523e..1eda36419ac 100644 --- a/tests/unit/indexables/application/verification-cron-batch-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-batch-handler-test.php @@ -64,8 +64,8 @@ public function test_get_current_post_indexables_batch() { * @return void */ public function test_set_current_post_indexables_batch() { - $this->options_helper->expects()->set( 'cron_verify_post_indexables_last_batch', 5 ); - $this->instance->set_current_post_indexables_batch( 5 ); + $this->options_helper->expects()->set( 'cron_verify_post_indexables_last_batch', 15 ); + $this->instance->set_current_post_indexables_batch( new Last_Batch_Count( 10 ), new Batch_Size( 5 ) ); } /** diff --git a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php index b2732ac5de2..fe036cfe670 100644 --- a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php @@ -5,15 +5,10 @@ use Brain\Monkey; use Mockery; use Yoast\WP\SEO\Conditionals\Admin_Conditional; -use Yoast\WP\SEO\Helpers\Options_Helper; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; -use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\User_Interface\Mark_Deactivation_Integration; -use Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration; use Yoast\WP\SEO\Indexables\User_Interface\Verification_Posts_Cron_Callback_Integration; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -33,13 +28,6 @@ class Verification_Posts_Cron_Callback_Integration_Test extends TestCase { */ private $instance; - /** - * The options helper. - * - * @var \Mockery\MockInterface|Options_Helper - */ - private $options_helper; - /** * The cron schedule handler. * @@ -78,10 +66,9 @@ protected function setUp(): void { $this->cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); - $this->options_helper = Mockery::mock( Options_Helper::class ); $this->verification_cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class ); $this->verify_posts_indexables_command_handler = Mockery::mock( Verify_Post_Indexables_Command_Handler::class ); - $this->instance = new Verification_Posts_Cron_Callback_Integration( $this->cron_verification_gate, $this->cron_schedule_handler, $this->options_helper, $this->verification_cron_batch_handler, $this->verify_posts_indexables_command_handler ); + $this->instance = new Verification_Posts_Cron_Callback_Integration( $this->cron_verification_gate, $this->cron_schedule_handler, $this->verification_cron_batch_handler, $this->verify_posts_indexables_command_handler ); } /** From c4037c48dfbda6205bbf72d099a57207b5ab131d Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 16 Nov 2023 16:00:07 +0100 Subject: [PATCH 34/41] Small fix in using the name of the post type instead of the object. --- .../actions/verify-post-type-archives-indexables-action.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php index 43208a5eddf..a3aa643d965 100644 --- a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -78,8 +78,8 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S $indexables = []; foreach ( $archives as $post_type_archive ) { - $archive_indexable = $this->indexable_repository->find_for_post_type_archive( $post_type_archive, false ); - $indexables[] = $this->indexable_builder->build_for_post_type_archive( $post_type_archive, $archive_indexable ); + $archive_indexable = $this->indexable_repository->find_for_post_type_archive( $post_type_archive->name, false ); + $indexables[] = $this->indexable_builder->build_for_post_type_archive( $post_type_archive->name, $archive_indexable ); } return $batch_size->should_keep_going( \count( $indexables ) ); From b16f58206ce8995c69e241968708e5534ae99724 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Thu, 7 Dec 2023 09:31:08 +0100 Subject: [PATCH 35/41] Add/update unit tests --- .../verify-indexable-action-factory-test.php | 3 +- ...estamp-indexables-command-handler-test.php | 1 + ...-non-timestamp-indexables-command-test.php | 1 + ...y-post-indexables-command-handler-test.php | 32 ++++++ .../verify-post-indexables-command-test.php | 1 + .../next-verification-action-handler-test.php | 1 + .../verification-cron-batch-handler-test.php | 1 + ...erification-cron-schedule-handler-test.php | 100 ++++++++++++++++-- .../indexables/domain/batch-size-test.php | 2 +- .../outdated-post-indexables-list-test.php | 2 + ...ule-verification-cron-integration-test.php | 86 +++++++++++++++ ...mestamp-cron-callback-integration-test.php | 1 + ...n-posts-cron-callback-integration-test.php | 1 + 13 files changed, 224 insertions(+), 8 deletions(-) create mode 100644 tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php diff --git a/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php index 9a488cf4422..56b6cf0aa3a 100644 --- a/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php +++ b/tests/unit/indexables/application/actions/verify-indexable-action-factory-test.php @@ -81,6 +81,7 @@ protected function setUp(): void { * Tests the get function. * * @covers ::get + * @covers ::__construct * * @dataProvider indexable_action_factory_data_provider * @@ -156,7 +157,7 @@ public function test_determine_next_verify_action_no_existing_action() { public function test_determine_next_verify_action_no_actions_left() { $this->expectException( No_Verification_Action_Left_Exception::class ); - $this->instance->determine_next_verify_action( new Current_Verification_Action( 'post_links' ) ); + $this->instance->determine_next_verify_action( new Current_Verification_Action( 'term_links' ) ); } /** diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php index 67fe5795b7c..3f1c38e617a 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-handler-test.php @@ -90,6 +90,7 @@ protected function setUp(): void { * Tests the handle function. * * @covers ::handle + * @covers ::__construct * @return void */ public function test_handle_with_next_batch() { diff --git a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php index d3385932ca5..6805dbd3bee 100644 --- a/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-non-timestamp-indexables-command-test.php @@ -40,6 +40,7 @@ protected function setUp(): void { * Tests the get current action object. * * @covers ::get_current_action + * @covers ::__construct * * @return void */ diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index 947a8b82db6..8d93dfc2155 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -95,6 +95,7 @@ protected function setUp(): void { * Tests the handle function. * * @covers ::handle + * @covers ::__construct * @return void */ public function test_handle_with_next_batch() { @@ -136,4 +137,35 @@ public function test_handle_with_action_not_found() { $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); $this->instance->handle( $this->command ); } + + /** + * Tests the handle function when there is no next batch. + * + * @covers ::handle + * @return void + */ + public function test_handle_with_no_next_batch() { + $this->command = new Verify_Post_Indexables_Command( 10, 0 ); + $indexable_list = new Outdated_Post_Indexables_List(); + $indexable_mock = Mockery::mock( Indexable::class ); + $indexable_mock1 = Mockery::mock( Indexable::class ); + $indexable_mock2 = Mockery::mock( Indexable::class ); + $indexable_mock3 = Mockery::mock( Indexable::class ); + $indexable_list->add_post_indexable( $indexable_mock ); + $indexable_list->add_post_indexable( $indexable_mock1 ); + $indexable_list->add_post_indexable( $indexable_mock2 ); + $indexable_list->add_post_indexable( $indexable_mock3 ); + $this->outdated_post_indexables_repository->expects( 'get_outdated_post_indexables' ) + ->with( $this->command->get_last_batch_count() ) + ->andReturn( $indexable_list ); + + + $this->indexables_builder->expects()->build( $indexable_mock ); + $this->indexables_builder->expects()->build( $indexable_mock1 ); + $this->indexables_builder->expects()->build( $indexable_mock2 ); + $this->indexables_builder->expects()->build( $indexable_mock3 ); + + $this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once(); + $this->instance->handle( $this->command ); + } } diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php index a640310a22c..c5c3f883cfa 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-test.php @@ -40,6 +40,7 @@ protected function setUp(): void { * Tests the last batch count object. * * @covers ::get_last_batch_count + * @covers ::__construct * * @return void */ diff --git a/tests/unit/indexables/application/next-verification-action-handler-test.php b/tests/unit/indexables/application/next-verification-action-handler-test.php index 2dedef2b74d..d454f2e7bc0 100644 --- a/tests/unit/indexables/application/next-verification-action-handler-test.php +++ b/tests/unit/indexables/application/next-verification-action-handler-test.php @@ -48,6 +48,7 @@ protected function setUp(): void { * Tests the get function. * * @covers ::get_current_verification_action + * @covers ::__construct * @return void */ public function test_get_current_verification_action() { diff --git a/tests/unit/indexables/application/verification-cron-batch-handler-test.php b/tests/unit/indexables/application/verification-cron-batch-handler-test.php index 1eda36419ac..48572f6fd1c 100644 --- a/tests/unit/indexables/application/verification-cron-batch-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-batch-handler-test.php @@ -49,6 +49,7 @@ protected function setUp(): void { * Tests the get function. * * @covers ::get_current_post_indexables_batch + * @covers ::__construct * @return void */ public function test_get_current_post_indexables_batch() { diff --git a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php index 8e1c5358479..b5a706cdd1e 100644 --- a/tests/unit/indexables/application/verification-cron-schedule-handler-test.php +++ b/tests/unit/indexables/application/verification-cron-schedule-handler-test.php @@ -32,6 +32,13 @@ class Verification_Cron_Schedule_Handler_Test extends TestCase { */ private $cron_verification_gate; + /** + * The options helper. + * + * @var \Mockery\MockInterface|Options_Helper + */ + private $option_helper; + /** * The setup function. * @@ -41,22 +48,22 @@ protected function setUp(): void { parent::setUp(); $this->cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class ); - $options_helper = Mockery::mock( Options_Helper::class ); - $options_helper->expects( 'get' )->with( 'activation_redirect_timestamp_free', 0 )->andReturn( 2 ); + $this->option_helper = Mockery::mock( Options_Helper::class ); - $this->instance = new Verification_Cron_Schedule_Handler( $this->cron_verification_gate, $options_helper ); + $this->instance = new Verification_Cron_Schedule_Handler( $this->cron_verification_gate, $this->option_helper ); } /** * Tests the schedule_indexable_verification method. * * @covers ::schedule_indexable_verification + * @covers ::__construct * * @dataProvider schedule_indexable_verification_provider * - * @param bool $should_verify If the indexable verification is enabled. - * @param bool $post_scheduled If the cron is scheduled. - * @param bool $timestamp_scheduled If the cron is scheduled. + * @param bool $should_verify If the indexable verification is enabled. + * @param bool $post_scheduled If the cron is scheduled. + * @param bool $timestamp_scheduled If the cron is scheduled. * @param int $time_wp_schedule_event How many times this functions should be called. * * @return void @@ -68,6 +75,8 @@ public function test_schedule_indexable_verification( $time_wp_schedule_event ) { $this->cron_verification_gate->expects( 'should_verify_on_cron' )->twice()->andReturn( $should_verify ); + $this->option_helper->expects( 'get' )->with( 'activation_redirect_timestamp_free', 0 )->andReturn( 2 ); + if ( $should_verify ) { Monkey\Functions\expect( 'wp_next_scheduled' ) ->once() @@ -125,4 +134,83 @@ public function schedule_indexable_verification_provider() { 'time_wp_schedule_event' => 1, ]; } + + /** + * Tests the unschedule_verify_post_indexables_cron method. + * + * @covers ::unschedule_verify_post_indexables_cron + * + * @return void + */ + public function test_unschedule_verify_post_indexables_cron() { + + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) + ->andReturn( true ); + + Monkey\Functions\expect( 'wp_unschedule_event' ) + ->once() + ->with( true, Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ); + + $this->instance->unschedule_verify_post_indexables_cron(); + } + + /** + * Tests the unschedule_verify_post_indexables_cron method. + * + * @covers ::unschedule_verify_post_indexables_cron + * + * @return void + */ + public function test_unschedule_verify_post_indexables_cron_without_running_cron() { + + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME ) + ->andReturn( false ); + + Monkey\Functions\expect( 'wp_unschedule_event' ) + ->never(); + $this->instance->unschedule_verify_post_indexables_cron(); + } + + /** + * Tests the unschedule_verify_post_indexables_cron method. + * + * @covers ::unschedule_verify_non_timestamped_indexables_cron + * + * @return void + */ + public function test_unschedule_verify_non_timestamped_indexables_cron() { + + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) + ->andReturn( true ); + + Monkey\Functions\expect( 'wp_unschedule_event' ) + ->once() + ->with( true, Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ); + $this->instance->unschedule_verify_non_timestamped_indexables_cron(); + } + + /** + * Tests the unschedule_verify_non_timestamped_indexables_cron method. + * + * @covers ::unschedule_verify_non_timestamped_indexables_cron + * + * @return void + */ + public function test_unschedule_verify_non_timestamped_indexables_cron_without_running_cron() { + + Monkey\Functions\expect( 'wp_next_scheduled' ) + ->once() + ->with( Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_NON_TIMESTAMPED_INDEXABLES_NAME ) + ->andReturn( false ); + + Monkey\Functions\expect( 'wp_unschedule_event' ) + ->never(); + $this->instance->unschedule_verify_non_timestamped_indexables_cron(); + } } diff --git a/tests/unit/indexables/domain/batch-size-test.php b/tests/unit/indexables/domain/batch-size-test.php index 6484a3fc59f..a0cb5522337 100644 --- a/tests/unit/indexables/domain/batch-size-test.php +++ b/tests/unit/indexables/domain/batch-size-test.php @@ -46,7 +46,7 @@ public function test_get_batch_size() { /** * Tests the get function. * - * @covers ::get_batch_size + * @covers ::should_keep_going * @covers ::__construct * @return void */ diff --git a/tests/unit/indexables/domain/outdated-post-indexables-list-test.php b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php index 2344ef0b423..fb1fa7189ca 100644 --- a/tests/unit/indexables/domain/outdated-post-indexables-list-test.php +++ b/tests/unit/indexables/domain/outdated-post-indexables-list-test.php @@ -38,6 +38,7 @@ protected function setUp(): void { * Tests the add_post_indexable function. * * @covers ::add_post_indexable + * @covers ::current * @covers ::__construct * @return void */ @@ -54,6 +55,7 @@ public function test_add_post_indexable() { * @covers ::key * @covers ::next * @covers ::rewind + * @covers ::valid * @covers ::count * @return void */ diff --git a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php new file mode 100644 index 00000000000..c12551c0caa --- /dev/null +++ b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php @@ -0,0 +1,86 @@ +cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + + $this->instance = new Schedule_Verification_Cron_Integration( $this->cron_schedule_handler ); + } + + /** + * Tests the register_hooks function. + * + * @covers ::register_hooks + * @covers ::__construct + * @return void + */ + public function test_register_hooks() { + Monkey\Functions\expect( 'add_action', ) + ->with( + 'wpseo_activate', + [$this->cron_schedule_handler, + 'schedule_indexable_verification'] + ); + + $this->instance->register_hooks(); + } + + /** + * Tests the get function. + * + * @covers ::get_conditionals + * @return void + */ + public function test_get_conditionals() { + $this->assertEquals( + [ + Admin_Conditional::class, + ], + Schedule_Verification_Cron_Integration::get_conditionals() + ); + } +} diff --git a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php index a54f8a5c74b..689247e9bdd 100644 --- a/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-no-timestamp-cron-callback-integration-test.php @@ -95,6 +95,7 @@ protected function setUp(): void { * Tests the register_hooks function. * * @covers ::register_hooks + * @covers ::__construct * @return void */ public function test_register_hooks() { diff --git a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php index fe036cfe670..1213307b6cf 100644 --- a/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php +++ b/tests/unit/indexables/user-interface/verification-posts-cron-callback-integration-test.php @@ -75,6 +75,7 @@ protected function setUp(): void { * Tests the register_hooks function. * * @covers ::register_hooks + * @covers ::__construct * @return void */ public function test_register_hooks() { From 4a1bdbb8b8d28831e6726befeae5618d3bccaec9 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Mon, 11 Dec 2023 09:23:09 +0100 Subject: [PATCH 36/41] cs. --- .../verify-post-indexables-command-handler-test.php | 2 +- .../schedule-verification-cron-integration-test.php | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php index 8d93dfc2155..eb072b8f927 100644 --- a/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php +++ b/tests/unit/indexables/application/commands/verify-post-indexables-command-handler-test.php @@ -145,7 +145,7 @@ public function test_handle_with_action_not_found() { * @return void */ public function test_handle_with_no_next_batch() { - $this->command = new Verify_Post_Indexables_Command( 10, 0 ); + $this->command = new Verify_Post_Indexables_Command( 10, 0 ); $indexable_list = new Outdated_Post_Indexables_List(); $indexable_mock = Mockery::mock( Indexable::class ); $indexable_mock1 = Mockery::mock( Indexable::class ); diff --git a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php index c12551c0caa..35e46b33a1f 100644 --- a/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php +++ b/tests/unit/indexables/user-interface/schedule-verification-cron-integration-test.php @@ -46,9 +46,9 @@ class Schedule_Verification_Cron_Integration_Test extends TestCase { protected function setUp(): void { parent::setUp(); - $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); + $this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class ); - $this->instance = new Schedule_Verification_Cron_Integration( $this->cron_schedule_handler ); + $this->instance = new Schedule_Verification_Cron_Integration( $this->cron_schedule_handler ); } /** @@ -59,11 +59,13 @@ protected function setUp(): void { * @return void */ public function test_register_hooks() { - Monkey\Functions\expect( 'add_action', ) + Monkey\Functions\expect( 'add_action' ) ->with( 'wpseo_activate', - [$this->cron_schedule_handler, - 'schedule_indexable_verification'] + [ + $this->cron_schedule_handler, + 'schedule_indexable_verification', + ] ); $this->instance->register_hooks(); From cf8749bb64b69f82c767d8c6a04d97657571202b Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 12 Dec 2023 13:21:47 +0100 Subject: [PATCH 37/41] Add test for laptop transfer. --- ...tdated_Post_Indexables_Repository_Test.php | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php diff --git a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php new file mode 100644 index 00000000000..281b5088311 --- /dev/null +++ b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php @@ -0,0 +1,113 @@ +user_id = self::factory()->user->create_and_get( + [ + 'user_login' => 'user', + 'user_pass' => 'password', + ] + )->ID; + $this->instance = new Outdated_Post_Indexables_Repository( + $wpdb, + YoastSEO()->helpers->post_type, + YoastSEO()->helpers->post, + YoastSEO()->classes->get( Indexable_Repository::class ) ); + + $post1 = self::factory()->post->create_and_get( + [ + 'post_type' => 'post', + 'post_date' => '2024-09-13 08:50:00', + 'post_modified_gmt' => '2024-09-13 08:50:00', + 'post_status' => 'publish', + 'post_author' => $this->user_id, + ] + ); + + $this->post2 = self::factory()->post->create_and_get( + [ + 'post_type' => 'post', + 'post_date' => '2024-09-13 08:50:00', + 'post_modified_gmt' => '2024-09-13 08:50:00', + 'post_status' => 'publish', + 'post_author' => $this->user_id, + ] + ); + + $indexable = new Indexable(); + $indexable->orm = ORM::for_table( 'wp_yoast_indexable' ); + + YoastSEO()->classes->get( Indexable_Builder::class )->build_for_id_and_type( $post1->ID, 'post' ); + YoastSEO()->classes->get( Indexable_Builder::class )->build_for_id_and_type( $this->post2->ID, 'post' ); + } + + /** + * Tests the get_outdated_post_indexables method. + * + * @covers ::get_outdated_post_indexables + * + */ + public function test_get_no_outdated_indexables() { + $last_batch = new Last_Batch_Count( 0 ); + $this->expectException( No_Outdated_Posts_Found_Exception::class ); + $this->instance->get_outdated_post_indexables( $last_batch ); + } + + /** + * Tests the get_outdated_post_indexables method. + * + * @covers ::get_outdated_post_indexables + * + */ + public function test_get_outdated_indexables_with_outdated_post() { + $last_batch = new Last_Batch_Count( 0 ); + global $wpdb; + $db_result = $wpdb->query( "UPDATE ".$wpdb->posts." SET post_modified_gmt='2022-11-24 13:10:39' where id=".$this->post2->ID ); + + $result = $this->instance->get_outdated_post_indexables( $last_batch ); + + var_dump($result);die; + $this->assertSame($result->count(),1); + + $this->assertSame((int) $result->current()->ID, (int) $this->post2->ID); + } +} From 1a50886791f86e5b0de19e89ee1e43058a5def0b Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Wed, 13 Dec 2023 14:06:40 +0100 Subject: [PATCH 38/41] Adds integration tests. --- .../verify-term-links-indexables-action.php | 10 +- .../Verify_General_Indexables_Action_Test.php | 59 ++++++++++ ...t_Type_Archives_Indexables_Action_Test.php | 103 ++++++++++++++++++ .../Verify_Term_Indexables_Action_Test.php | 88 +++++++++++++++ ...rify_Term_Links_Indexables_Action_Test.php | 91 ++++++++++++++++ ...tdated_Post_Indexables_Repository_Test.php | 49 +++++---- 6 files changed, 370 insertions(+), 30 deletions(-) create mode 100644 tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php create mode 100644 tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php create mode 100644 tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php create mode 100644 tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index a26e3de4084..15f6f7568ac 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -70,15 +70,14 @@ public function __construct( */ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { $query = $this->get_query( $last_batch_count->get_last_batch(), $batch_size->get_batch_size() ); - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_query returns a prepared query. $terms = $this->wpdb->get_results( $query ); $indexables = []; foreach ( $terms as $term ) { - $indexable = $this->repository->find_by_id_and_type( (int) $term->id, 'term' ); + $indexable = $this->repository->find_by_id_and_type( (int) $term->term_id, 'term' ); if ( $indexable ) { - $this->link_builder->build( $indexable, $term->content ); + $this->link_builder->build( $indexable, $term->description ); $indexables[] = $indexable; } @@ -110,7 +109,8 @@ public function set_wpdb( \wpdb $wpdb ) { private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); - $replacements = $public_taxonomies; + $replacements[] = $taxonomy_table; + $replacements = array_merge( $replacements, $public_taxonomies ); $limit_query = 'LIMIT %d'; $replacements[] = $batch_size; @@ -119,7 +119,6 @@ private function get_query( $limit, $batch_size ) { $offset_query = 'OFFSET %d'; $replacements[] = ( $limit + $batch_size ); } - // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: These can be removed in the next version of WPCS. return $this->wpdb->prepare( ' @@ -127,7 +126,6 @@ private function get_query( $limit, $batch_size ) { FROM %i AS T WHERE taxonomy IN (' . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") $limit_query $offset_query", - $taxonomy_table, $replacements ); } diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php new file mode 100644 index 00000000000..6373e863967 --- /dev/null +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php @@ -0,0 +1,59 @@ +instance = new Verify_General_Indexables_Action( + YoastSEO()->classes->get( Indexable_Repository::class ), + YoastSEO()->classes->get( Indexable_Builder::class ) + ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables() { + $repo = YoastSEO()->classes->get( Indexable_Repository::class ); + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 10 ); + $this->instance->re_build_indexables( $last_batch, $batch_size ); + + $this->assertInstanceOf( Indexable::class, $repo->find_for_system_page( '404', false ) ); + $this->assertInstanceOf( Indexable::class, $repo->find_for_system_page( 'search-result', false ) ); + $this->assertInstanceOf( Indexable::class, $repo->find_for_date_archive( false ) ); + $this->assertInstanceOf( Indexable::class, $repo->find_for_home_page( false ) ); + } +} diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php new file mode 100644 index 00000000000..1b6b0d67d1c --- /dev/null +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php @@ -0,0 +1,103 @@ +instance = new Verify_Post_Type_Archives_Indexables_Action( + YoastSEO()->helpers->post_type, + YoastSEO()->classes->get( Indexable_Builder::class ), + YoastSEO()->classes->get( Indexable_Repository::class ) + ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables() { + $repo = YoastSEO()->classes->get( Indexable_Repository::class ); + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 10 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $archives = YoastSEO()->helpers->post_type->get_indexable_post_archives(); + + + foreach ( $archives as $post_type_archive ) { + $archive_indexable = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_for_post_type_archive( $post_type_archive->name, false ); + $this->assertInstanceOf( Indexable::class, $archive_indexable ); + } + $this->assertFalse( $should_continue ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables_should_continue() { + for ( $i = 0; $i < 10; $i++ ) { + \register_post_type( + 'post_type_' . $i, + [ + 'public' => true, + 'has_archive' => true, + 'description' => 'a cool post type', + 'label' => 'post_type_' . $i, + ] + ); + $post = [ + 'post_date' => '1978-09-13 08:50:00', + 'post_status' => 'publish', + 'post_type' => 'post_type_' . $i, + ]; + self::factory()->post->create( $post ); + } + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 2 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $archives = YoastSEO()->helpers->post_type->get_indexable_post_archives(); + + $archives = \array_slice( $archives, $last_batch->get_last_batch(), ( $last_batch->get_last_batch() + $batch_size->get_batch_size() ) ); + + foreach ( $archives as $post_type_archive ) { + $archive_indexable = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_for_post_type_archive( $post_type_archive->name, false ); + $this->assertInstanceOf( Indexable::class, $archive_indexable ); + } + $this->assertTrue( $should_continue ); + } +} diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php new file mode 100644 index 00000000000..6fb44c062fd --- /dev/null +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php @@ -0,0 +1,88 @@ +instance = new Verify_Term_Indexables_Action( + YoastSEO()->helpers->taxonomy, + YoastSEO()->classes->get( Indexable_Repository::class ) + ); + $this->instance->set_wpdb( $wpdb ); + + self::factory()->category->create( + [ + 'name' => 'test_term', + 'taxonomy' => 'category', + ] + ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables() { + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 10 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_all_with_type( 'term', false ); + + foreach ( $taxonomies as $taxonomy ) { + $this->assertInstanceOf( Indexable::class, $taxonomy ); + } + $this->assertFalse( $should_continue ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables_with_continue() { + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 1 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_all_with_type( 'term', false ); + + foreach ( $taxonomies as $taxonomy ) { + $this->assertInstanceOf( Indexable::class, $taxonomy ); + } + $this->assertTrue( $should_continue ); + } +} diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php new file mode 100644 index 00000000000..46f4b055319 --- /dev/null +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php @@ -0,0 +1,91 @@ +instance = new Verify_Term_Links_Indexables_Action( + YoastSEO()->helpers->taxonomy, + YoastSEO()->classes->get( Indexable_Repository::class ), + YoastSEO()->classes->get( Indexable_Link_Builder::class ) + ); + $this->instance->set_wpdb( $wpdb ); + + self::factory()->category->create( + [ + 'name' => 'test_term', + 'taxonomy' => 'category', + ] + ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables() { + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 10 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_all_with_type( 'term', false ); + + foreach ( $taxonomies as $taxonomy ) { + $this->assertInstanceOf( Indexable::class, $taxonomy ); + } + $this->assertFalse( $should_continue ); + } + + /** + * Tests the re_build_indexables method. + * + * @covers ::re_build_indexables + */ + public function test_re_build_indexables_with_continue() { + $last_batch = new Last_Batch_Count( 0 ); + $batch_size = new Batch_Size( 1 ); + $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); + $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + ->find_all_with_type( 'term', false ); + + foreach ( $taxonomies as $taxonomy ) { + $this->assertInstanceOf( Indexable::class, $taxonomy ); + } + $this->assertTrue( $should_continue ); + } +} diff --git a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php index 281b5088311..2479f84798a 100644 --- a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php +++ b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php @@ -18,6 +18,12 @@ * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository */ class Dismiss_New_Route_Test extends TestCase { + + /** + * The post object. + * + * @var \WP_Post + */ protected $post2; /** @@ -51,40 +57,35 @@ public function setUp(): void { $wpdb, YoastSEO()->helpers->post_type, YoastSEO()->helpers->post, - YoastSEO()->classes->get( Indexable_Repository::class ) ); + YoastSEO()->classes->get( Indexable_Repository::class ) + ); $post1 = self::factory()->post->create_and_get( [ - 'post_type' => 'post', - 'post_date' => '2024-09-13 08:50:00', - 'post_modified_gmt' => '2024-09-13 08:50:00', - 'post_status' => 'publish', - 'post_author' => $this->user_id, + 'post_type' => 'post', + 'post_date' => '2022-09-13 08:50:00', + 'post_modified_gmt' => '2022-09-13 08:50:00', + 'post_status' => 'publish', + 'post_author' => $this->user_id, ] ); $this->post2 = self::factory()->post->create_and_get( [ - 'post_type' => 'post', - 'post_date' => '2024-09-13 08:50:00', - 'post_modified_gmt' => '2024-09-13 08:50:00', - 'post_status' => 'publish', - 'post_author' => $this->user_id, + 'post_type' => 'post', + 'post_date' => '2022-09-13 08:50:00', + 'post_modified_gmt' => '2022-09-13 08:50:00', + 'post_status' => 'publish', + 'post_author' => $this->user_id, ] ); - - $indexable = new Indexable(); - $indexable->orm = ORM::for_table( 'wp_yoast_indexable' ); - - YoastSEO()->classes->get( Indexable_Builder::class )->build_for_id_and_type( $post1->ID, 'post' ); - YoastSEO()->classes->get( Indexable_Builder::class )->build_for_id_and_type( $this->post2->ID, 'post' ); } /** * Tests the get_outdated_post_indexables method. * * @covers ::get_outdated_post_indexables - * + * @covers ::__construct */ public function test_get_no_outdated_indexables() { $last_batch = new Last_Batch_Count( 0 ); @@ -96,18 +97,18 @@ public function test_get_no_outdated_indexables() { * Tests the get_outdated_post_indexables method. * * @covers ::get_outdated_post_indexables - * */ public function test_get_outdated_indexables_with_outdated_post() { $last_batch = new Last_Batch_Count( 0 ); global $wpdb; - $db_result = $wpdb->query( "UPDATE ".$wpdb->posts." SET post_modified_gmt='2022-11-24 13:10:39' where id=".$this->post2->ID ); - + // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Will be supported later. + $db_result = $wpdb->query( $wpdb->prepare( " UPDATE %i SET %i='2022-11-24 13:10:39' where id=%d", [ $wpdb->posts, 'post_modified_gmt', $this->post2->ID ] ) ); + // phpcs:enable $result = $this->instance->get_outdated_post_indexables( $last_batch ); - var_dump($result);die; - $this->assertSame($result->count(),1); - $this->assertSame((int) $result->current()->ID, (int) $this->post2->ID); + $this->assertSame( $result->count(), 1 ); + + $this->assertSame( (int) $result->current()->ID, (int) $this->post2->ID ); } } From 7ff3314f201fbe2e3259b263992643e6281d2fa7 Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Wed, 13 Dec 2023 14:44:59 +0100 Subject: [PATCH 39/41] CS... --- .../Actions/Verify_General_Indexables_Action_Test.php | 4 ++-- ...rify_Post_Type_Archives_Indexables_Action_Test.php | 6 ++++-- .../Actions/Verify_Term_Indexables_Action_Test.php | 4 ++-- .../Verify_Term_Links_Indexables_Action_Test.php | 11 ++--------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php index 6373e863967..f25a3716162 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php @@ -1,6 +1,6 @@ Date: Thu, 25 Jan 2024 14:46:14 +0100 Subject: [PATCH 40/41] CS --- src/generators/schema/webpage.php | 2 +- ...fy-indexables-action-factory-interface.php | 3 +-- .../verify-indexables-action-interface.php | 5 ++-- .../no-verification-action-left-exception.php | 4 +++- .../verify-action-not-found-exception.php | 4 +++- .../domain/outdated-post-indexables-list.php | 4 +++- .../verify-general-indexables-action.php | 7 +++--- ...y-post-type-archives-indexables-action.php | 7 +++--- .../actions/verify-term-indexables-action.php | 19 ++++++++------- .../verify-term-links-indexables-action.php | 9 +++---- .../outdated-post-indexables-repository.php | 4 ++-- ...cation-posts-cron-callback-integration.php | 1 - .../Verify_Indexable_Action_Factory_Test.php | 2 +- ...estamp_Indexables_Command_Handler_Test.php | 2 +- ..._Non_Timestamp_Indexables_Command_Test.php | 2 +- .../Verify_Post_Indexables_Command_Test.php | 3 +-- ...y_Post_Indexables_Command_Handler_Test.php | 11 +-------- .../Cron_Verification_Gate_Test.php | 10 ++++---- .../Next_Verification_Action_Handler_Test.php | 5 ++-- .../Verification_Cron_Batch_Handler_Test.php | 5 ++-- ...erification_Cron_Schedule_Handler_Test.php | 10 ++++---- .../Indexables/Domain/Batch_Size_Test.php | 2 +- .../Current_Verification_Action_Test.php | 3 +-- .../Domain/Last_Batch_Count_Test.php | 5 ++-- .../Outdated_Post_Indexables_List_Test.php | 5 ++-- ...ule_Verification_Cron_Integration_Test.php | 11 +++------ ...mestamp_Cron_Callback_Integration_Test.php | 16 +++++++------ ...n_Posts_Cron_Callback_Integration_Test.php | 11 +++++---- .../Verify_General_Indexables_Action_Test.php | 12 ++++------ ...t_Type_Archives_Indexables_Action_Test.php | 24 +++++++------------ .../Verify_Term_Indexables_Action_Test.php | 17 ++++--------- ...rify_Term_Links_Indexables_Action_Test.php | 13 +++++----- ...tdated_Post_Indexables_Repository_Test.php | 16 +++++-------- 33 files changed, 116 insertions(+), 138 deletions(-) diff --git a/src/generators/schema/webpage.php b/src/generators/schema/webpage.php index 309ad4cf9e0..615b21da6c7 100644 --- a/src/generators/schema/webpage.php +++ b/src/generators/schema/webpage.php @@ -83,7 +83,7 @@ public function generate() { * Adds an author property to the $data if the WebPage is not represented. * * @param array> $data The WebPage schema. - * @param WP_Post $post The post the context is representing. + * @param WP_Post $post The post the context is representing. * * @return array> The WebPage schema. */ diff --git a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php index a3fc839a217..536a29fbb7c 100644 --- a/src/indexables/domain/actions/verify-indexables-action-factory-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-factory-interface.php @@ -33,6 +33,5 @@ public function get( Current_Verification_Action $verification_action ): Verify_ * @throws No_Verification_Action_Left_Exception Throws when there are no verification actions left. * @return Current_Verification_Action */ - public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object - ): Current_Verification_Action; + public function determine_next_verify_action( Current_Verification_Action $current_verification_action_object ): Current_Verification_Action; } diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 1c23e7053b3..801a7ab81f3 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -3,6 +3,7 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Domain\Actions; +use wpdb; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; @@ -24,10 +25,10 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb instance. * - * @param \wpdb $wpdb The wpdb instance. + * @param wpdb $wpdb The wpdb instance. * * @return mixed * @required */ - public function set_wpdb( \wpdb $wpdb ); + public function set_wpdb( wpdb $wpdb ); } diff --git a/src/indexables/domain/exceptions/no-verification-action-left-exception.php b/src/indexables/domain/exceptions/no-verification-action-left-exception.php index 53348942794..28af2c7df79 100644 --- a/src/indexables/domain/exceptions/no-verification-action-left-exception.php +++ b/src/indexables/domain/exceptions/no-verification-action-left-exception.php @@ -3,10 +3,12 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Domain\Exceptions; +use Exception; + /** * The No_Verification_Action_Left_Exception exception. */ -class No_Verification_Action_Left_Exception extends \Exception { +class No_Verification_Action_Left_Exception extends Exception { /** * Named constructor to create this exception for when there are no verification actions left. diff --git a/src/indexables/domain/exceptions/verify-action-not-found-exception.php b/src/indexables/domain/exceptions/verify-action-not-found-exception.php index 7d0fd74d0c4..efcdde48cd6 100644 --- a/src/indexables/domain/exceptions/verify-action-not-found-exception.php +++ b/src/indexables/domain/exceptions/verify-action-not-found-exception.php @@ -3,9 +3,11 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Domain\Exceptions; +use Exception; + /** * A named exception. */ -class Verify_Action_Not_Found_Exception extends \Exception { +class Verify_Action_Not_Found_Exception extends Exception { } diff --git a/src/indexables/domain/outdated-post-indexables-list.php b/src/indexables/domain/outdated-post-indexables-list.php index a7b4eb5203e..600407c1720 100644 --- a/src/indexables/domain/outdated-post-indexables-list.php +++ b/src/indexables/domain/outdated-post-indexables-list.php @@ -2,12 +2,14 @@ namespace Yoast\WP\SEO\Indexables\Domain; +use Countable; +use Iterator; use Yoast\WP\SEO\Models\Indexable; /** * The Outdated_Post_Indexables_List class. */ -class Outdated_Post_Indexables_List implements \Iterator, \Countable { +class Outdated_Post_Indexables_List implements Iterator, Countable { /** * The post indexables list. diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index 9a6ef107777..ee9bfd78962 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -3,6 +3,7 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Infrastructure\Actions; +use wpdb; use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Interface; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; @@ -31,7 +32,7 @@ class Verify_General_Indexables_Action implements Verify_Indexables_Action_Inter /** * The wp query. * - * @var \wpdb $wpdb + * @var wpdb $wpdb */ private $wpdb; @@ -74,12 +75,12 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb instance. * - * @param \wpdb $wpdb The instance. + * @param wpdb $wpdb The instance. * * @return void * @required */ - public function set_wpdb( \wpdb $wpdb ) { + public function set_wpdb( wpdb $wpdb ) { $this->wpdb = $wpdb; } } diff --git a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php index a3aa643d965..afe91a2c931 100644 --- a/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-post-type-archives-indexables-action.php @@ -3,6 +3,7 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Infrastructure\Actions; +use wpdb; use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Helpers\Post_Type_Helper; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Interface; @@ -27,7 +28,7 @@ class Verify_Post_Type_Archives_Indexables_Action implements Verify_Indexables_A /** * The wp query. * - * @var \wpdb $wpdb + * @var wpdb $wpdb */ private $wpdb; @@ -88,12 +89,12 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb instance. * - * @param \wpdb $wpdb The wpdb instance. + * @param wpdb $wpdb The wpdb instance. * * @return void * @required */ - public function set_wpdb( \wpdb $wpdb ) { + public function set_wpdb( wpdb $wpdb ) { $this->wpdb = $wpdb; } } diff --git a/src/indexables/infrastructure/actions/verify-term-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-indexables-action.php index 27c6a2fdda0..ed9c925e702 100644 --- a/src/indexables/infrastructure/actions/verify-term-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-indexables-action.php @@ -3,6 +3,7 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Infrastructure\Actions; +use wpdb; use Yoast\WP\SEO\Helpers\Taxonomy_Helper; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Interface; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; @@ -28,6 +29,13 @@ class Verify_Term_Indexables_Action implements Verify_Indexables_Action_Interfac */ private $repository; + /** + * The wp query. + * + * @var wpdb $wpdb + */ + private $wpdb; + /** * The constructor. * @@ -39,13 +47,6 @@ public function __construct( Taxonomy_Helper $taxonomy, Indexable_Repository $re $this->repository = $repository; } - /** - * The wp query. - * - * @var \wpdb $wpdb - */ - private $wpdb; - /** * Re builds indexables for term indexables. * @@ -69,12 +70,12 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb instance. * - * @param \wpdb $wpdb The wpdb instance. + * @param wpdb $wpdb The wpdb instance. * * @return void * @required */ - public function set_wpdb( \wpdb $wpdb ) { + public function set_wpdb( wpdb $wpdb ) { $this->wpdb = $wpdb; } diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index 15f6f7568ac..061492c4938 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -3,6 +3,7 @@ // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. namespace Yoast\WP\SEO\Indexables\Infrastructure\Actions; +use wpdb; use Yoast\WP\SEO\Builders\Indexable_Link_Builder; use Yoast\WP\SEO\Helpers\Taxonomy_Helper; use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Interface; @@ -39,7 +40,7 @@ class Verify_Term_Links_Indexables_Action implements Verify_Indexables_Action_In /** * The wp query. * - * @var \wpdb $wpdb + * @var wpdb $wpdb */ private $wpdb; @@ -89,12 +90,12 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S /** * Sets the wpdb. * - * @param \wpdb $wpdb The wpdb instance. + * @param wpdb $wpdb The wpdb instance. * * @return void * @required */ - public function set_wpdb( \wpdb $wpdb ) { + public function set_wpdb( wpdb $wpdb ) { $this->wpdb = $wpdb; } @@ -110,7 +111,7 @@ private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); $replacements[] = $taxonomy_table; - $replacements = array_merge( $replacements, $public_taxonomies ); + $replacements = \array_merge( $replacements, $public_taxonomies ); $limit_query = 'LIMIT %d'; $replacements[] = $batch_size; diff --git a/src/indexables/infrastructure/outdated-post-indexables-repository.php b/src/indexables/infrastructure/outdated-post-indexables-repository.php index 08c2f945ed8..72da5e65868 100644 --- a/src/indexables/infrastructure/outdated-post-indexables-repository.php +++ b/src/indexables/infrastructure/outdated-post-indexables-repository.php @@ -20,7 +20,7 @@ class Outdated_Post_Indexables_Repository implements Outdated_Post_Indexables_Re /** * The wp query. * - * @var \wpdb $wpdb + * @var wpdb $wpdb */ private $wpdb; @@ -48,7 +48,7 @@ class Outdated_Post_Indexables_Repository implements Outdated_Post_Indexables_Re /** * The constructor. * - * @param \wpdb $wpdb The wpdb instance. + * @param wpdb $wpdb The wpdb instance. * @param Post_Type_Helper $post_type_helper The post type helper. * @param Post_Helper $post_helper The post helper. * @param Indexable_Repository $indexable_repository The indexable repository. diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 9730ea7849c..16a19abbe13 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Indexables\User_Interface; use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait; -use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; diff --git a/tests/Unit/Indexables/Application/Actions/Verify_Indexable_Action_Factory_Test.php b/tests/Unit/Indexables/Application/Actions/Verify_Indexable_Action_Factory_Test.php index 56b6cf0aa3a..5bd7bb110ce 100644 --- a/tests/Unit/Indexables/Application/Actions/Verify_Indexable_Action_Factory_Test.php +++ b/tests/Unit/Indexables/Application/Actions/Verify_Indexable_Action_Factory_Test.php @@ -24,7 +24,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Actions\Verify_Indexable_Action_Factory */ -class Verify_Indexable_Action_Factory_Test extends TestCase { +final class Verify_Indexable_Action_Factory_Test extends TestCase { /** * The term action. diff --git a/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Handler_Test.php b/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Handler_Test.php index 3f1c38e617a..0fadc610142 100644 --- a/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Handler_Test.php +++ b/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Handler_Test.php @@ -26,7 +26,7 @@ * * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ -class Verify_Non_Timestamp_Indexables_Command_Handler_Test extends TestCase { +final class Verify_Non_Timestamp_Indexables_Command_Handler_Test extends TestCase { /** * The instance. diff --git a/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Test.php b/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Test.php index 6805dbd3bee..72e777c6a17 100644 --- a/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Test.php +++ b/tests/Unit/Indexables/Application/Commands/Verify_Non_Timestamp_Indexables_Command_Test.php @@ -16,7 +16,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command */ -class Verify_Non_Timestamp_Indexables_Command_Test extends TestCase { +final class Verify_Non_Timestamp_Indexables_Command_Test extends TestCase { /** * The instance to test. diff --git a/tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Test.php b/tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Test.php index c5c3f883cfa..3359a2e29bc 100644 --- a/tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Test.php +++ b/tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Test.php @@ -3,7 +3,6 @@ // @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. namespace Yoast\WP\SEO\Tests\Unit\Indexables\Application\Commands; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; @@ -16,7 +15,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command */ -class Verify_Post_Indexables_Command_Test extends TestCase { +final class Verify_Post_Indexables_Command_Test extends TestCase { /** * The instance to test. diff --git a/tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php b/tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php index eb072b8f927..e05634c5d3a 100644 --- a/tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php +++ b/tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php @@ -7,20 +7,13 @@ use Mockery\MockInterface; use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; -use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Application\Ports\Outdated_Post_Indexables_Repository_Interface; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; -use Yoast\WP\SEO\Indexables\Domain\Actions\Verify_Indexables_Action_Factory_Interface; -use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; -use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Verification_Action_Left_Exception; -use Yoast\WP\SEO\Indexables\Domain\Exceptions\Verify_Action_Not_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List; -use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -31,7 +24,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler */ -class Verify_Post_Indexables_Command_Handler_Test extends TestCase { +final class Verify_Post_Indexables_Command_Handler_Test extends TestCase { /** * The instance. @@ -113,7 +106,6 @@ public function test_handle_with_next_batch() { ->with( $this->command->get_last_batch_count() ) ->andReturn( $indexable_list ); - $this->indexables_builder->expects()->build( $indexable_mock ); $this->indexables_builder->expects()->build( $indexable_mock1 ); $this->indexables_builder->expects()->build( $indexable_mock2 ); @@ -159,7 +151,6 @@ public function test_handle_with_no_next_batch() { ->with( $this->command->get_last_batch_count() ) ->andReturn( $indexable_list ); - $this->indexables_builder->expects()->build( $indexable_mock ); $this->indexables_builder->expects()->build( $indexable_mock1 ); $this->indexables_builder->expects()->build( $indexable_mock2 ); diff --git a/tests/Unit/Indexables/Application/Cron_Verification_Gate_Test.php b/tests/Unit/Indexables/Application/Cron_Verification_Gate_Test.php index 8ef79647c55..73a59325a54 100644 --- a/tests/Unit/Indexables/Application/Cron_Verification_Gate_Test.php +++ b/tests/Unit/Indexables/Application/Cron_Verification_Gate_Test.php @@ -3,7 +3,9 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Application; use Brain\Monkey; +use Generator; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Helpers\Indexable_Helper; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -15,7 +17,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate */ -class Cron_Verification_Gate_Test extends TestCase { +final class Cron_Verification_Gate_Test extends TestCase { /** * The instance. @@ -27,7 +29,7 @@ class Cron_Verification_Gate_Test extends TestCase { /** * The indexable helper. * - * @var \Mockery\MockInterface|Indexable_Helper + * @var MockInterface|Indexable_Helper */ private $indexable_helper; @@ -47,7 +49,7 @@ protected function setUp(): void { /** * Tests if the should verify on cron function gives the expected response. * - * @param bool $expected The expected result. + * @param bool $expected The expected result. * @param string $should_index What the helper should return. * @param string $filter_value What the filter should return. * @@ -66,7 +68,7 @@ public function test_should_verify_on_cron( $expected, $should_index, $filter_va /** * Data provider for the `test_should_verify_on_cron` test. * - * @return \Generator + * @return Generator */ public function should_verify_on_cron_dataprovider() { yield [ diff --git a/tests/Unit/Indexables/Application/Next_Verification_Action_Handler_Test.php b/tests/Unit/Indexables/Application/Next_Verification_Action_Handler_Test.php index d454f2e7bc0..41d6f326930 100644 --- a/tests/Unit/Indexables/Application/Next_Verification_Action_Handler_Test.php +++ b/tests/Unit/Indexables/Application/Next_Verification_Action_Handler_Test.php @@ -3,6 +3,7 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Application; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; @@ -15,7 +16,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler */ -class Next_Verification_Action_Handler_Test extends TestCase { +final class Next_Verification_Action_Handler_Test extends TestCase { /** * The instance. @@ -27,7 +28,7 @@ class Next_Verification_Action_Handler_Test extends TestCase { /** * The options helper. * - * @var \Mockery\MockInterface|Options_Helper + * @var MockInterface|Options_Helper */ private $options_helper; diff --git a/tests/Unit/Indexables/Application/Verification_Cron_Batch_Handler_Test.php b/tests/Unit/Indexables/Application/Verification_Cron_Batch_Handler_Test.php index 48572f6fd1c..88e9b75b6d7 100644 --- a/tests/Unit/Indexables/Application/Verification_Cron_Batch_Handler_Test.php +++ b/tests/Unit/Indexables/Application/Verification_Cron_Batch_Handler_Test.php @@ -3,6 +3,7 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Application; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; @@ -16,7 +17,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler */ -class Verification_Cron_Batch_Handler_Test extends TestCase { +final class Verification_Cron_Batch_Handler_Test extends TestCase { /** * The instance. @@ -28,7 +29,7 @@ class Verification_Cron_Batch_Handler_Test extends TestCase { /** * The options helper. * - * @var \Mockery\MockInterface|Options_Helper + * @var MockInterface|Options_Helper */ private $options_helper; diff --git a/tests/Unit/Indexables/Application/Verification_Cron_Schedule_Handler_Test.php b/tests/Unit/Indexables/Application/Verification_Cron_Schedule_Handler_Test.php index b5a706cdd1e..82364e04278 100644 --- a/tests/Unit/Indexables/Application/Verification_Cron_Schedule_Handler_Test.php +++ b/tests/Unit/Indexables/Application/Verification_Cron_Schedule_Handler_Test.php @@ -3,7 +3,9 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Application; use Brain\Monkey; +use Generator; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; @@ -16,7 +18,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler */ -class Verification_Cron_Schedule_Handler_Test extends TestCase { +final class Verification_Cron_Schedule_Handler_Test extends TestCase { /** * The instance. @@ -28,14 +30,14 @@ class Verification_Cron_Schedule_Handler_Test extends TestCase { /** * The cron verification gate. * - * @var \Mockery\MockInterface|Cron_Verification_Gate + * @var MockInterface|Cron_Verification_Gate */ private $cron_verification_gate; /** * The options helper. * - * @var \Mockery\MockInterface|Options_Helper + * @var MockInterface|Options_Helper */ private $option_helper; @@ -98,7 +100,7 @@ public function test_schedule_indexable_verification( /** * Data provider for `test_schedule_indexable_verification` * - * @return \Generator + * @return Generator */ public function schedule_indexable_verification_provider() { yield 'Both crons already scheduled.' => [ diff --git a/tests/Unit/Indexables/Domain/Batch_Size_Test.php b/tests/Unit/Indexables/Domain/Batch_Size_Test.php index a0cb5522337..ee96f4e3be4 100644 --- a/tests/Unit/Indexables/Domain/Batch_Size_Test.php +++ b/tests/Unit/Indexables/Domain/Batch_Size_Test.php @@ -12,7 +12,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Domain\Batch_Size */ -class Batch_Size_Test extends TestCase { +final class Batch_Size_Test extends TestCase { /** * The instance. diff --git a/tests/Unit/Indexables/Domain/Current_Verification_Action_Test.php b/tests/Unit/Indexables/Domain/Current_Verification_Action_Test.php index 9db0719e954..64190962e79 100644 --- a/tests/Unit/Indexables/Domain/Current_Verification_Action_Test.php +++ b/tests/Unit/Indexables/Domain/Current_Verification_Action_Test.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain; -use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -13,7 +12,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Domain\Current_Verification_Action */ -class Current_Verification_Action_Test extends TestCase { +final class Current_Verification_Action_Test extends TestCase { /** * The instance. diff --git a/tests/Unit/Indexables/Domain/Last_Batch_Count_Test.php b/tests/Unit/Indexables/Domain/Last_Batch_Count_Test.php index 1e0a1f99f9f..7eb3882a439 100644 --- a/tests/Unit/Indexables/Domain/Last_Batch_Count_Test.php +++ b/tests/Unit/Indexables/Domain/Last_Batch_Count_Test.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain; -use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -13,12 +12,12 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count */ -class Last_Batch_Count_Test extends TestCase { +final class Last_Batch_Count_Test extends TestCase { /** * The instance. * - * @var \Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count + * @var Last_Batch_Count */ private $instance; diff --git a/tests/Unit/Indexables/Domain/Outdated_Post_Indexables_List_Test.php b/tests/Unit/Indexables/Domain/Outdated_Post_Indexables_List_Test.php index fb1fa7189ca..208f7f38534 100644 --- a/tests/Unit/Indexables/Domain/Outdated_Post_Indexables_List_Test.php +++ b/tests/Unit/Indexables/Domain/Outdated_Post_Indexables_List_Test.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain; -use Yoast\WP\SEO\Indexables\Domain\Batch_Size; use Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List; use Yoast\WP\SEO\Tests\Unit\Doubles\Models\Indexable_Double; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -14,12 +13,12 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List */ -class Outdated_Post_Indexables_List_Test extends TestCase { +final class Outdated_Post_Indexables_List_Test extends TestCase { /** * The instance. * - * @var \Yoast\WP\SEO\Indexables\Domain\Outdated_Post_Indexables_List + * @var Outdated_Post_Indexables_List */ private $instance; diff --git a/tests/Unit/Indexables/User_Interface/Schedule_Verification_Cron_Integration_Test.php b/tests/Unit/Indexables/User_Interface/Schedule_Verification_Cron_Integration_Test.php index 35e46b33a1f..13a879f8aa4 100644 --- a/tests/Unit/Indexables/User_Interface/Schedule_Verification_Cron_Integration_Test.php +++ b/tests/Unit/Indexables/User_Interface/Schedule_Verification_Cron_Integration_Test.php @@ -4,15 +4,10 @@ use Brain\Monkey; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Conditionals\Admin_Conditional; -use Yoast\WP\SEO\Helpers\Options_Helper; -use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler; -use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; -use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler; -use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler; use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler; use Yoast\WP\SEO\Indexables\User_Interface\Schedule_Verification_Cron_Integration; -use Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration; use Yoast\WP\SEO\Tests\Unit\TestCase; /** @@ -22,7 +17,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\User_Interface\Schedule_Verification_Cron_Integration */ -class Schedule_Verification_Cron_Integration_Test extends TestCase { +final class Schedule_Verification_Cron_Integration_Test extends TestCase { /** * The instance. @@ -34,7 +29,7 @@ class Schedule_Verification_Cron_Integration_Test extends TestCase { /** * The cron schedule handler. * - * @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler + * @var MockInterface|Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; diff --git a/tests/Unit/Indexables/User_Interface/Verification_No_Timestamp_Cron_Callback_Integration_Test.php b/tests/Unit/Indexables/User_Interface/Verification_No_Timestamp_Cron_Callback_Integration_Test.php index 689247e9bdd..1719fe2cd8b 100644 --- a/tests/Unit/Indexables/User_Interface/Verification_No_Timestamp_Cron_Callback_Integration_Test.php +++ b/tests/Unit/Indexables/User_Interface/Verification_No_Timestamp_Cron_Callback_Integration_Test.php @@ -4,6 +4,7 @@ use Brain\Monkey; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Conditionals\Admin_Conditional; use Yoast\WP\SEO\Helpers\Options_Helper; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler; @@ -20,9 +21,10 @@ * @group indexables * * @coversDefaultClass \Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration + * * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded */ -class Verification_No_Timestamp_Cron_Callback_Integration_Test extends TestCase { +final class Verification_No_Timestamp_Cron_Callback_Integration_Test extends TestCase { /** * The instance. @@ -34,42 +36,42 @@ class Verification_No_Timestamp_Cron_Callback_Integration_Test extends TestCase /** * The options helper. * - * @var \Mockery\MockInterface|Options_Helper + * @var MockInterface|Options_Helper */ private $options_helper; /** * The cron schedule handler. * - * @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler + * @var MockInterface|Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; /** * The cron verification gate. * - * @var \Mockery\MockInterface|Cron_Verification_Gate + * @var MockInterface|Cron_Verification_Gate */ private $cron_verification_gate; /** * The verification cron batch handler. * - * @var \Mockery\MockInterface|Verification_Cron_Batch_Handler + * @var MockInterface|Verification_Cron_Batch_Handler */ private $verification_cron_batch_handler; /** * The command handler. * - * @var \Mockery\MockInterface|Verify_Non_Timestamp_Indexables_Command_Handler + * @var MockInterface|Verify_Non_Timestamp_Indexables_Command_Handler */ private $verify_non_timestamp_indexables_command_handler; /** * The next action handler. * - * @var \Mockery\MockInterface|Next_Verification_Action_Handler + * @var MockInterface|Next_Verification_Action_Handler */ private $next_verification_action_handler; diff --git a/tests/Unit/Indexables/User_Interface/Verification_Posts_Cron_Callback_Integration_Test.php b/tests/Unit/Indexables/User_Interface/Verification_Posts_Cron_Callback_Integration_Test.php index 1213307b6cf..b3d9242f35b 100644 --- a/tests/Unit/Indexables/User_Interface/Verification_Posts_Cron_Callback_Integration_Test.php +++ b/tests/Unit/Indexables/User_Interface/Verification_Posts_Cron_Callback_Integration_Test.php @@ -4,6 +4,7 @@ use Brain\Monkey; use Mockery; +use Mockery\MockInterface; use Yoast\WP\SEO\Conditionals\Admin_Conditional; use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler; use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate; @@ -19,7 +20,7 @@ * * @coversDefaultClass \Yoast\WP\SEO\Indexables\User_Interface\Verification_Posts_Cron_Callback_Integration */ -class Verification_Posts_Cron_Callback_Integration_Test extends TestCase { +final class Verification_Posts_Cron_Callback_Integration_Test extends TestCase { /** * The instance. @@ -31,28 +32,28 @@ class Verification_Posts_Cron_Callback_Integration_Test extends TestCase { /** * The cron schedule handler. * - * @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler + * @var MockInterface|Verification_Cron_Schedule_Handler */ private $cron_schedule_handler; /** * The cron verification gate. * - * @var \Mockery\MockInterface|Cron_Verification_Gate + * @var MockInterface|Cron_Verification_Gate */ private $cron_verification_gate; /** * The verification cron batch handler. * - * @var \Mockery\MockInterface|Verification_Cron_Batch_Handler + * @var MockInterface|Verification_Cron_Batch_Handler */ private $verification_cron_batch_handler; /** * The command handler. * - * @var \Mockery\MockInterface|Verify_Post_Indexables_Command_Handler + * @var MockInterface|Verify_Post_Indexables_Command_Handler */ private $verify_posts_indexables_command_handler; diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php index f25a3716162..4c4dd9f3857 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php @@ -2,24 +2,20 @@ // @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. namespace Yoast\WP\SEO\Tests\WP\Indexables\Infrastructure\Actions; -use Yoast\WP\Lib\ORM; use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; -use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; -use Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Repository; use Yoast\WP\SEO\Tests\WP\TestCase; -use function YoastSEO; /** * Integration Test Class for Verify_General_Indexables_Action. * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action */ -class Verify_General_Indexables_Action_Test extends TestCase { +final class Verify_General_Indexables_Action_Test extends TestCase { /** * The instance to test. @@ -35,8 +31,8 @@ public function setUp(): void { parent::setUp(); $this->instance = new Verify_General_Indexables_Action( - YoastSEO()->classes->get( Indexable_Repository::class ), - YoastSEO()->classes->get( Indexable_Builder::class ) + \YoastSEO()->classes->get( Indexable_Repository::class ), + \YoastSEO()->classes->get( Indexable_Builder::class ) ); } @@ -46,7 +42,7 @@ public function setUp(): void { * @covers ::re_build_indexables */ public function test_re_build_indexables() { - $repo = YoastSEO()->classes->get( Indexable_Repository::class ); + $repo = \YoastSEO()->classes->get( Indexable_Repository::class ); $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 10 ); $this->instance->re_build_indexables( $last_batch, $batch_size ); diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php index eac9e90b923..acd6d6f3d1d 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php @@ -2,18 +2,13 @@ // @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. namespace Yoast\WP\SEO\Tests\WP\Indexables\Infrastructure\Actions; -use Yoast\WP\Lib\ORM; use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; -use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action; -use Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Repository; use Yoast\WP\SEO\Tests\WP\TestCase; -use function YoastSEO; /** * Integration Test Class for Verify_Post_Type_Archives_Indexables_Action. @@ -22,7 +17,7 @@ * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action */ -class Verify_Post_Type_Archives_Indexables_Action_Test extends TestCase { +final class Verify_Post_Type_Archives_Indexables_Action_Test extends TestCase { /** * The instance to test. @@ -38,9 +33,9 @@ public function setUp(): void { parent::setUp(); $this->instance = new Verify_Post_Type_Archives_Indexables_Action( - YoastSEO()->helpers->post_type, - YoastSEO()->classes->get( Indexable_Builder::class ), - YoastSEO()->classes->get( Indexable_Repository::class ) + \YoastSEO()->helpers->post_type, + \YoastSEO()->classes->get( Indexable_Builder::class ), + \YoastSEO()->classes->get( Indexable_Repository::class ) ); } @@ -50,15 +45,14 @@ public function setUp(): void { * @covers ::re_build_indexables */ public function test_re_build_indexables() { - $repo = YoastSEO()->classes->get( Indexable_Repository::class ); + $repo = \YoastSEO()->classes->get( Indexable_Repository::class ); $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 10 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $archives = YoastSEO()->helpers->post_type->get_indexable_post_archives(); - + $archives = \YoastSEO()->helpers->post_type->get_indexable_post_archives(); foreach ( $archives as $post_type_archive ) { - $archive_indexable = YoastSEO()->classes->get( Indexable_Repository::class ) + $archive_indexable = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_for_post_type_archive( $post_type_archive->name, false ); $this->assertInstanceOf( Indexable::class, $archive_indexable ); } @@ -91,12 +85,12 @@ public function test_re_build_indexables_should_continue() { $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 2 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $archives = YoastSEO()->helpers->post_type->get_indexable_post_archives(); + $archives = \YoastSEO()->helpers->post_type->get_indexable_post_archives(); $archives = \array_slice( $archives, $last_batch->get_last_batch(), ( $last_batch->get_last_batch() + $batch_size->get_batch_size() ) ); foreach ( $archives as $post_type_archive ) { - $archive_indexable = YoastSEO()->classes->get( Indexable_Repository::class ) + $archive_indexable = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_for_post_type_archive( $post_type_archive->name, false ); $this->assertInstanceOf( Indexable::class, $archive_indexable ); } diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php index 5546a2950df..2275d6716b5 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php @@ -2,26 +2,19 @@ // @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. namespace Yoast\WP\SEO\Tests\WP\Indexables\Infrastructure\Actions; -use Yoast\WP\Lib\ORM; -use Yoast\WP\SEO\Builders\Indexable_Builder; use Yoast\WP\SEO\Indexables\Domain\Batch_Size; -use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; -use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_General_Indexables_Action; -use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Post_Type_Archives_Indexables_Action; use Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action; -use Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Repository; use Yoast\WP\SEO\Tests\WP\TestCase; -use function YoastSEO; /** * Integration Test Class for Verify_Term_Indexables_Action. * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Indexables_Action */ -class Verify_Term_Indexables_Action_Test extends TestCase { +final class Verify_Term_Indexables_Action_Test extends TestCase { /** * The instance to test. @@ -37,8 +30,8 @@ public function setUp(): void { parent::setUp(); global $wpdb; $this->instance = new Verify_Term_Indexables_Action( - YoastSEO()->helpers->taxonomy, - YoastSEO()->classes->get( Indexable_Repository::class ) + \YoastSEO()->helpers->taxonomy, + \YoastSEO()->classes->get( Indexable_Repository::class ) ); $this->instance->set_wpdb( $wpdb ); @@ -59,7 +52,7 @@ public function test_re_build_indexables() { $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 10 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + $taxonomies = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_all_with_type( 'term', false ); foreach ( $taxonomies as $taxonomy ) { @@ -77,7 +70,7 @@ public function test_re_build_indexables_with_continue() { $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 1 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + $taxonomies = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_all_with_type( 'term', false ); foreach ( $taxonomies as $taxonomy ) { diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php index 37e1c9721da..1c800e83199 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php @@ -9,14 +9,13 @@ use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Repository; use Yoast\WP\SEO\Tests\WP\TestCase; -use function YoastSEO; /** * Integration Test Class for Verify_Term_Links_Indexables_Action. * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Actions\Verify_Term_Links_Indexables_Action */ -class Verify_Term_Links_Indexables_Action_Test extends TestCase { +final class Verify_Term_Links_Indexables_Action_Test extends TestCase { /** * The instance to test. @@ -32,9 +31,9 @@ public function setUp(): void { parent::setUp(); global $wpdb; $this->instance = new Verify_Term_Links_Indexables_Action( - YoastSEO()->helpers->taxonomy, - YoastSEO()->classes->get( Indexable_Repository::class ), - YoastSEO()->classes->get( Indexable_Link_Builder::class ) + \YoastSEO()->helpers->taxonomy, + \YoastSEO()->classes->get( Indexable_Repository::class ), + \YoastSEO()->classes->get( Indexable_Link_Builder::class ) ); $this->instance->set_wpdb( $wpdb ); @@ -55,7 +54,7 @@ public function test_re_build_indexables() { $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 10 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + $taxonomies = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_all_with_type( 'term', false ); foreach ( $taxonomies as $taxonomy ) { @@ -73,7 +72,7 @@ public function test_re_build_indexables_with_continue() { $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 1 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); - $taxonomies = YoastSEO()->classes->get( Indexable_Repository::class ) + $taxonomies = \YoastSEO()->classes->get( Indexable_Repository::class ) ->find_all_with_type( 'term', false ); foreach ( $taxonomies as $taxonomy ) { diff --git a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php index 2479f84798a..5ae21173d77 100644 --- a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php +++ b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php @@ -2,27 +2,24 @@ namespace Yoast\WP\SEO\Tests\WP\Indexables\Infrastructure; -use Yoast\WP\Lib\ORM; -use Yoast\WP\SEO\Builders\Indexable_Builder; +use WP_Post; use Yoast\WP\SEO\Indexables\Domain\Exceptions\No_Outdated_Posts_Found_Exception; use Yoast\WP\SEO\Indexables\Domain\Last_Batch_Count; use Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository; -use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Repository; use Yoast\WP\SEO\Tests\WP\TestCase; -use function YoastSEO; /** * Integration Test Class for Outdated_Post_Indexables_Repository. * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository */ -class Dismiss_New_Route_Test extends TestCase { +final class Dismiss_New_Route_Test extends TestCase { /** * The post object. * - * @var \WP_Post + * @var WP_Post */ protected $post2; @@ -55,9 +52,9 @@ public function setUp(): void { )->ID; $this->instance = new Outdated_Post_Indexables_Repository( $wpdb, - YoastSEO()->helpers->post_type, - YoastSEO()->helpers->post, - YoastSEO()->classes->get( Indexable_Repository::class ) + \YoastSEO()->helpers->post_type, + \YoastSEO()->helpers->post, + \YoastSEO()->classes->get( Indexable_Repository::class ) ); $post1 = self::factory()->post->create_and_get( @@ -106,7 +103,6 @@ public function test_get_outdated_indexables_with_outdated_post() { // phpcs:enable $result = $this->instance->get_outdated_post_indexables( $last_batch ); - $this->assertSame( $result->count(), 1 ); $this->assertSame( (int) $result->current()->ID, (int) $this->post2->ID ); From af58d70d471a987a4ebf58b8d518306e04c4ecda Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Fri, 26 Jan 2024 10:27:19 +0100 Subject: [PATCH 41/41] more CS --- composer.json | 2 +- ...verify-post-indexables-command-handler.php | 2 ++ .../verify-indexables-action-interface.php | 2 +- .../verify-general-indexables-action.php | 2 +- .../verify-term-links-indexables-action.php | 1 + ...schedule-verification-cron-integration.php | 2 ++ ...no-timestamp-cron-callback-integration.php | 26 ++++++------------- ...cation-posts-cron-callback-integration.php | 2 ++ src/repositories/indexable-repository.php | 6 ++--- ..._Post_Indexables_Command_Handler_Test.php} | 0 .../Verify_General_Indexables_Action_Test.php | 4 +++ ...t_Type_Archives_Indexables_Action_Test.php | 7 ++++- .../Verify_Term_Indexables_Action_Test.php | 6 +++++ ...rify_Term_Links_Indexables_Action_Test.php | 6 +++++ ...tdated_Post_Indexables_Repository_Test.php | 20 ++++++-------- 15 files changed, 51 insertions(+), 37 deletions(-) rename tests/Unit/Indexables/Application/Commands/{verify_Post_Indexables_Command_Handler_Test.php => Verify_Post_Indexables_Command_Handler_Test.php} (100%) diff --git a/composer.json b/composer.json index df7aab7de25..2ea62bbbe59 100644 --- a/composer.json +++ b/composer.json @@ -91,7 +91,7 @@ "Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards" ], "check-cs-thresholds": [ - "@putenv YOASTCS_THRESHOLD_ERRORS=2679", + "@putenv YOASTCS_THRESHOLD_ERRORS=2665", "@putenv YOASTCS_THRESHOLD_WARNINGS=297", "Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds" ], diff --git a/src/indexables/application/commands/verify-post-indexables-command-handler.php b/src/indexables/application/commands/verify-post-indexables-command-handler.php index 7e4c27d4ce9..e5a990f8246 100644 --- a/src/indexables/application/commands/verify-post-indexables-command-handler.php +++ b/src/indexables/application/commands/verify-post-indexables-command-handler.php @@ -70,6 +70,8 @@ public function __construct( * Handles the Verify_Post_Indexables_Command command. * * @param Verify_Post_Indexables_Command $verify_post_indexables_command The command. + * + * @return void */ public function handle( Verify_Post_Indexables_Command $verify_post_indexables_command ): void { try { diff --git a/src/indexables/domain/actions/verify-indexables-action-interface.php b/src/indexables/domain/actions/verify-indexables-action-interface.php index 801a7ab81f3..38d3a58f8ca 100644 --- a/src/indexables/domain/actions/verify-indexables-action-interface.php +++ b/src/indexables/domain/actions/verify-indexables-action-interface.php @@ -27,7 +27,7 @@ public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_S * * @param wpdb $wpdb The wpdb instance. * - * @return mixed + * @return void * @required */ public function set_wpdb( wpdb $wpdb ); diff --git a/src/indexables/infrastructure/actions/verify-general-indexables-action.php b/src/indexables/infrastructure/actions/verify-general-indexables-action.php index ee9bfd78962..83fa199ba6e 100644 --- a/src/indexables/infrastructure/actions/verify-general-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-general-indexables-action.php @@ -55,7 +55,7 @@ public function __construct( Indexable_Repository $repository, Indexable_Builder * * @return bool */ - public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { + public function re_build_indexables( Last_Batch_Count $last_batch_count, Batch_Size $batch_size ): bool { // @phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Because these come from the interface, and are not used for this particular implementation $system_page = $this->repository->find_for_system_page( '404', false ); $this->indexable_builder->build_for_system_page( '404', $system_page ); diff --git a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php index 061492c4938..e0d732928fa 100644 --- a/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php +++ b/src/indexables/infrastructure/actions/verify-term-links-indexables-action.php @@ -110,6 +110,7 @@ public function set_wpdb( wpdb $wpdb ) { private function get_query( $limit, $batch_size ) { $taxonomy_table = $this->wpdb->term_taxonomy; $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); + $replacements = []; $replacements[] = $taxonomy_table; $replacements = \array_merge( $replacements, $public_taxonomies ); diff --git a/src/indexables/user-interface/schedule-verification-cron-integration.php b/src/indexables/user-interface/schedule-verification-cron-integration.php index 68e2868f71e..0e34c951f3a 100644 --- a/src/indexables/user-interface/schedule-verification-cron-integration.php +++ b/src/indexables/user-interface/schedule-verification-cron-integration.php @@ -31,6 +31,8 @@ public function __construct( Verification_Cron_Schedule_Handler $cron_schedule_h /** * Registers the action with WordPress. + * + * @return void */ public function register_hooks() { \add_action( 'wpseo_activate', [ $this->cron_schedule_handler, 'schedule_indexable_verification' ] ); diff --git a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php index c5e066f8dea..cb9f727c01a 100644 --- a/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-no-timestamp-cron-callback-integration.php @@ -66,24 +66,12 @@ class Verification_No_Timestamp_Cron_Callback_Integration implements Integration /** * The constructor. * - * @param Cron_Verification_Gate $cron_verification_gate The cron - * verification - * gate. - * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron - * schedule - * handler. - * @param Options_Helper $options_helper The options - * helper. - * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch - * handler. - * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler The non - * timestamp - * indexables - * command - * handler. - * @param Next_Verification_Action_Handler $verification_action_handler The - * verification - * action handler. + * @param Cron_Verification_Gate $cron_verification_gate The cron verification gate. + * @param Verification_Cron_Schedule_Handler $cron_schedule_handler The cron schedule handler. + * @param Options_Helper $options_helper The options helper. + * @param Verification_Cron_Batch_Handler $cron_batch_handler The cron batch handler. + * @param Verify_Non_Timestamp_Indexables_Command_Handler $non_timestamp_indexables_command_handler The non timestamp indexables command handler. + * @param Next_Verification_Action_Handler $verification_action_handler The verification action handler. */ public function __construct( Cron_Verification_Gate $cron_verification_gate, @@ -103,6 +91,8 @@ public function __construct( /** * Registers the hooks with WordPress. + * + * @return void */ public function register_hooks() { \add_action( diff --git a/src/indexables/user-interface/verification-posts-cron-callback-integration.php b/src/indexables/user-interface/verification-posts-cron-callback-integration.php index 16a19abbe13..37a10373022 100644 --- a/src/indexables/user-interface/verification-posts-cron-callback-integration.php +++ b/src/indexables/user-interface/verification-posts-cron-callback-integration.php @@ -69,6 +69,8 @@ public function __construct( /** * Registers the hooks with WordPress. + * + * @return void */ public function register_hooks() { \add_action( diff --git a/src/repositories/indexable-repository.php b/src/repositories/indexable-repository.php index f731ff012c6..b2cc6202321 100644 --- a/src/repositories/indexable-repository.php +++ b/src/repositories/indexable-repository.php @@ -412,7 +412,7 @@ public function find_by_multiple_ids_and_type( $object_ids, $object_type, $auto_ /** * Finds the indexables by id's. * - * @param array $indexable_ids The indexable id's. + * @param array $indexable_ids The indexable id's. * * @return Indexable[] The found indexables. */ @@ -468,8 +468,8 @@ public function get_ancestors( Indexable $indexable ) { /** * Returns all subpages with a given post_parent. * - * @param int $post_parent The post parent. - * @param array $exclude_ids The id's to exclude. + * @param int $post_parent The post parent. + * @param array $exclude_ids The id's to exclude. * * @return Indexable[] array of indexables. */ diff --git a/tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php b/tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Handler_Test.php similarity index 100% rename from tests/Unit/Indexables/Application/Commands/verify_Post_Indexables_Command_Handler_Test.php rename to tests/Unit/Indexables/Application/Commands/Verify_Post_Indexables_Command_Handler_Test.php diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php index 4c4dd9f3857..46b927d82dc 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_General_Indexables_Action_Test.php @@ -26,6 +26,8 @@ final class Verify_General_Indexables_Action_Test extends TestCase { /** * Sets up the test class. + * + * @return void */ public function setUp(): void { parent::setUp(); @@ -40,6 +42,8 @@ public function setUp(): void { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables() { $repo = \YoastSEO()->classes->get( Indexable_Repository::class ); diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php index acd6d6f3d1d..fda5bd9b8d2 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Post_Type_Archives_Indexables_Action_Test.php @@ -28,6 +28,8 @@ final class Verify_Post_Type_Archives_Indexables_Action_Test extends TestCase { /** * Sets up the test class. + * + * @return void */ public function setUp(): void { parent::setUp(); @@ -43,9 +45,10 @@ public function setUp(): void { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables() { - $repo = \YoastSEO()->classes->get( Indexable_Repository::class ); $last_batch = new Last_Batch_Count( 0 ); $batch_size = new Batch_Size( 10 ); $should_continue = $this->instance->re_build_indexables( $last_batch, $batch_size ); @@ -63,6 +66,8 @@ public function test_re_build_indexables() { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables_should_continue() { for ( $i = 0; $i < 10; $i++ ) { diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php index 2275d6716b5..1e98a9eec41 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Indexables_Action_Test.php @@ -25,6 +25,8 @@ final class Verify_Term_Indexables_Action_Test extends TestCase { /** * Sets up the test class. + * + * @return void */ public function setUp(): void { parent::setUp(); @@ -47,6 +49,8 @@ public function setUp(): void { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables() { $last_batch = new Last_Batch_Count( 0 ); @@ -65,6 +69,8 @@ public function test_re_build_indexables() { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables_with_continue() { $last_batch = new Last_Batch_Count( 0 ); diff --git a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php index 1c800e83199..ca051683399 100644 --- a/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php +++ b/tests/WP/Indexables/Infrastructure/Actions/Verify_Term_Links_Indexables_Action_Test.php @@ -26,6 +26,8 @@ final class Verify_Term_Links_Indexables_Action_Test extends TestCase { /** * Sets up the test class. + * + * @return void */ public function setUp(): void { parent::setUp(); @@ -49,6 +51,8 @@ public function setUp(): void { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables() { $last_batch = new Last_Batch_Count( 0 ); @@ -67,6 +71,8 @@ public function test_re_build_indexables() { * Tests the re_build_indexables method. * * @covers ::re_build_indexables + * + * @return void */ public function test_re_build_indexables_with_continue() { $last_batch = new Last_Batch_Count( 0 ); diff --git a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php index 5ae21173d77..f0f6a195d44 100644 --- a/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php +++ b/tests/WP/Indexables/Infrastructure/Outdated_Post_Indexables_Repository_Test.php @@ -14,7 +14,7 @@ * * @coversDefaultClass Yoast\WP\SEO\Indexables\Infrastructure\Outdated_Post_Indexables_Repository */ -final class Dismiss_New_Route_Test extends TestCase { +final class Outdated_Post_Indexables_Repository_Test extends TestCase { /** * The post object. @@ -39,6 +39,8 @@ final class Dismiss_New_Route_Test extends TestCase { /** * Sets up the test class. + * + * @return void */ public function setUp(): void { parent::setUp(); @@ -57,16 +59,6 @@ public function setUp(): void { \YoastSEO()->classes->get( Indexable_Repository::class ) ); - $post1 = self::factory()->post->create_and_get( - [ - 'post_type' => 'post', - 'post_date' => '2022-09-13 08:50:00', - 'post_modified_gmt' => '2022-09-13 08:50:00', - 'post_status' => 'publish', - 'post_author' => $this->user_id, - ] - ); - $this->post2 = self::factory()->post->create_and_get( [ 'post_type' => 'post', @@ -83,6 +75,8 @@ public function setUp(): void { * * @covers ::get_outdated_post_indexables * @covers ::__construct + * + * @return void */ public function test_get_no_outdated_indexables() { $last_batch = new Last_Batch_Count( 0 ); @@ -94,12 +88,14 @@ public function test_get_no_outdated_indexables() { * Tests the get_outdated_post_indexables method. * * @covers ::get_outdated_post_indexables + * + * @return void */ public function test_get_outdated_indexables_with_outdated_post() { $last_batch = new Last_Batch_Count( 0 ); global $wpdb; // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Will be supported later. - $db_result = $wpdb->query( $wpdb->prepare( " UPDATE %i SET %i='2022-11-24 13:10:39' where id=%d", [ $wpdb->posts, 'post_modified_gmt', $this->post2->ID ] ) ); + $wpdb->query( $wpdb->prepare( " UPDATE %i SET %i='2022-11-24 13:10:39' where id=%d", [ $wpdb->posts, 'post_modified_gmt', $this->post2->ID ] ) ); // phpcs:enable $result = $this->instance->get_outdated_post_indexables( $last_batch );