Skip to content

Commit

Permalink
Lots 'o comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsoo committed Jun 19, 2023
1 parent bbf4fcb commit ea1d393
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,56 @@
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',
'post-type-archives',
'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,
Expand All @@ -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() ) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
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 {

/**
* @var Current_Verification_Action $current_action The current verification action in progress.
*/
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.
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@

class Verify_Post_Indexables_Command extends Abstract_Indexables_Command {



}
4 changes: 3 additions & 1 deletion src/indexables/application/cron-verfication-gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
class Cron_Verification_Gate {

/**
* @var \Yoast\WP\SEO\Helpers\Indexable_Helper
*
*
* @var Indexable_Helper
*/
protected $indexable_helper;

Expand Down
28 changes: 24 additions & 4 deletions src/indexables/application/next-verification-action-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class Verification_Cron_Batch_Handler {

/**
* The Options_Helper instance.
*
* @var Options_Helper
*/
protected $options_helper;
Expand Down
33 changes: 31 additions & 2 deletions src/indexables/application/verification-cron-schedule-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand All @@ -30,13 +49,23 @@ 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 ) {
\wp_unschedule_event( $scheduled, self::INDEXABLE_VERIFY_POST_INDEXABLES_NAME );
}
}

/**
* 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 ) {
Expand Down
Loading

0 comments on commit ea1d393

Please sign in to comment.