Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21404 when indexable creation is disabled cleanups are being scheduled upon post creation #21438

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=2511",
"@putenv YOASTCS_THRESHOLD_ERRORS=2495",
"@putenv YOASTCS_THRESHOLD_WARNINGS=253",
"Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
20 changes: 17 additions & 3 deletions src/integrations/admin/activation-cleanup-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yoast\WP\SEO\Integrations\Admin;

use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Integrations\Cleanup_Integration;
use Yoast\WP\SEO\Integrations\Integration_Interface;
Expand All @@ -14,6 +15,13 @@ class Activation_Cleanup_Integration implements Integration_Interface {

use No_Conditionals;

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
protected $indexable_helper;

/**
* The options helper.
*
Expand All @@ -24,12 +32,15 @@ class Activation_Cleanup_Integration implements Integration_Interface {
/**
* Activation_Cleanup_Integration constructor.
*
* @param Options_Helper $options_helper The options helper.
* @param Options_Helper $options_helper The options helper.
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct(
Options_Helper $options_helper
Options_Helper $options_helper,
Indexable_Helper $indexable_helper
) {
$this->options_helper = $options_helper;
$this->options_helper = $options_helper;
$this->indexable_helper = $indexable_helper;
}

/**
Expand All @@ -47,6 +58,9 @@ public function register_hooks() {
* @return void
*/
public function register_cleanup_routine() {
if ( ! $this->indexable_helper->should_index_indexables() ) {
return;
}
thijsoo marked this conversation as resolved.
Show resolved Hide resolved
$first_activated_on = $this->options_helper->get( 'first_activated_on', false );

if ( ! $first_activated_on || \time() > ( $first_activated_on + ( \MINUTE_IN_SECONDS * 5 ) ) ) {
Expand Down
28 changes: 26 additions & 2 deletions src/integrations/cleanup-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yoast\WP\SEO\Integrations;

use Closure;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Repositories\Indexable_Cleanup_Repository;

/**
Expand All @@ -25,6 +26,13 @@ class Cleanup_Integration implements Integration_Interface {
*/
public const START_HOOK = 'wpseo_start_cleanup_indexables';

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
private $indexable_helper;

/**
* The cleanup repository.
*
Expand All @@ -36,9 +44,14 @@ class Cleanup_Integration implements Integration_Interface {
* The constructor.
*
* @param Indexable_Cleanup_Repository $cleanup_repository The cleanup repository.
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct( Indexable_Cleanup_Repository $cleanup_repository ) {
public function __construct(
Indexable_Cleanup_Repository $cleanup_repository,
Indexable_Helper $indexable_helper
) {
$this->cleanup_repository = $cleanup_repository;
$this->indexable_helper = $indexable_helper;
}

/**
Expand All @@ -57,7 +70,7 @@ public function register_hooks() {
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array The array of conditionals.
* @return array<string> The array of conditionals.
*/
public static function get_conditionals() {
return [];
Expand All @@ -71,6 +84,11 @@ public static function get_conditionals() {
public function run_cleanup() {
$this->reset_cleanup();

if ( ! $this->indexable_helper->should_index_indexables() ) {
\wp_unschedule_hook( self::START_HOOK );
return;
}

$cleanups = $this->get_cleanup_tasks();
$limit = $this->get_limit();

Expand Down Expand Up @@ -263,6 +281,12 @@ public function start_cron_job( $task_name, $schedule_time = 3600 ) {
* @return void
*/
public function run_cleanup_cron() {
if ( ! $this->indexable_helper->should_index_indexables() ) {
$this->reset_cleanup();

return;
}

$current_task_name = \get_option( self::CURRENT_TASK_OPTION );

if ( $current_task_name === false ) {
Expand Down
20 changes: 17 additions & 3 deletions src/integrations/watchers/indexable-attachment-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Config\Indexing_Reasons;
use Yoast\WP\SEO\Helpers\Attachment_Cleanup_Helper;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Indexing_Helper;
use Yoast\WP\SEO\Integrations\Cleanup_Integration;
use Yoast\WP\SEO\Integrations\Integration_Interface;
Expand All @@ -30,6 +31,13 @@ class Indexable_Attachment_Watcher implements Integration_Interface {
*/
protected $attachment_cleanup;

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
protected $indexable_helper;

/**
* The notifications center.
*
Expand All @@ -40,7 +48,7 @@ class Indexable_Attachment_Watcher implements Integration_Interface {
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array
* @return array<string> The conditionals.
*/
public static function get_conditionals() {
return [ Migrations_Conditional::class ];
Expand All @@ -52,15 +60,18 @@ public static function get_conditionals() {
* @param Indexing_Helper $indexing_helper The indexing helper.
* @param Attachment_Cleanup_Helper $attachment_cleanup The attachment cleanup helper.
* @param Yoast_Notification_Center $notification_center The notification center.
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct(
Indexing_Helper $indexing_helper,
Attachment_Cleanup_Helper $attachment_cleanup,
Yoast_Notification_Center $notification_center
Yoast_Notification_Center $notification_center,
Indexable_Helper $indexable_helper
) {
$this->indexing_helper = $indexing_helper;
$this->attachment_cleanup = $attachment_cleanup;
$this->notification_center = $notification_center;
$this->indexable_helper = $indexable_helper;
}

/**
Expand All @@ -79,9 +90,12 @@ public function register_hooks() {
* either it cleans up attachment indexables when it has been toggled to true,
* or it starts displaying a notification for the user to start a new SEO optimization.
*
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*
* @param array $old_value The old value of the wpseo_titles option.
* @param array $new_value The new value of the wpseo_titles option.
*
* @phpcs:enable
* @return void
*/
public function check_option( $old_value, $new_value ) {
Expand Down Expand Up @@ -119,7 +133,7 @@ public function check_option( $old_value, $new_value ) {
$this->attachment_cleanup->remove_attachment_indexables( false );
$this->attachment_cleanup->clean_attachment_links_from_target_indexable_ids( false );

if ( ! \wp_next_scheduled( Cleanup_Integration::START_HOOK ) ) {
if ( $this->indexable_helper->should_index_indexables() && ! \wp_next_scheduled( Cleanup_Integration::START_HOOK ) ) {
// This just schedules the cleanup routine cron again.
\wp_schedule_single_event( ( \time() + ( \MINUTE_IN_SECONDS * 5 ) ), Cleanup_Integration::START_HOOK );
}
Expand Down
22 changes: 21 additions & 1 deletion src/integrations/watchers/indexable-author-archive-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yoast\WP\SEO\Integrations\Watchers;

use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Integrations\Cleanup_Integration;
use Yoast\WP\SEO\Integrations\Integration_Interface;

Expand All @@ -11,6 +12,22 @@
*/
class Indexable_Author_Archive_Watcher implements Integration_Interface {

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
protected $indexable_helper;

/**
* Indexable_Author_Archive_Watcher constructor.
*
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct( Indexable_Helper $indexable_helper ) {
$this->indexable_helper = $indexable_helper;
}

/**
* Check if the author archives are disabled whenever the `wpseo_titles` option
* changes.
Expand Down Expand Up @@ -42,13 +59,16 @@ public static function get_conditionals() {
*
* When author archives are disabled, they can never be indexed.
*
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*
* @param array $old_value The old `wpseo_titles` option value.
* @param array $new_value The new `wpseo_titles` option value.
*
* @phpcs:enable
* @return void
*/
public function reschedule_indexable_cleanup_when_author_archives_are_disabled( $old_value, $new_value ) {
if ( $old_value['disable-author'] !== true && $new_value['disable-author'] === true ) {
if ( $old_value['disable-author'] !== true && $new_value['disable-author'] === true && $this->indexable_helper->should_index_indexables() ) {
$cleanup_not_yet_scheduled = ! \wp_next_scheduled( Cleanup_Integration::START_HOOK );
if ( $cleanup_not_yet_scheduled ) {
\wp_schedule_single_event( ( \time() + ( \MINUTE_IN_SECONDS * 5 ) ), Cleanup_Integration::START_HOOK );
Expand Down
17 changes: 14 additions & 3 deletions src/integrations/watchers/indexable-post-type-change-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional;
use Yoast\WP\SEO\Config\Indexing_Reasons;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Indexing_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
Expand All @@ -26,6 +27,13 @@ class Indexable_Post_Type_Change_Watcher implements Integration_Interface {
*/
protected $indexing_helper;

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
private $indexable_helper;

/**
* Holds the Options_Helper instance.
*
Expand All @@ -50,7 +58,7 @@ class Indexable_Post_Type_Change_Watcher implements Integration_Interface {
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array
* @return array<string> The conditionals.
*/
public static function get_conditionals() {
return [ Not_Admin_Ajax_Conditional::class, Admin_Conditional::class, Migrations_Conditional::class ];
Expand All @@ -63,17 +71,20 @@ public static function get_conditionals() {
* @param Indexing_Helper $indexing_helper The indexing helper.
* @param Post_Type_Helper $post_type_helper The post_typehelper.
* @param Yoast_Notification_Center $notification_center The notification center.
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct(
Options_Helper $options,
Indexing_Helper $indexing_helper,
Post_Type_Helper $post_type_helper,
Yoast_Notification_Center $notification_center
Yoast_Notification_Center $notification_center,
Indexable_Helper $indexable_helper
) {
$this->options = $options;
$this->indexing_helper = $indexing_helper;
$this->post_type_helper = $post_type_helper;
$this->notification_center = $notification_center;
$this->indexable_helper = $indexable_helper;
}

/**
Expand Down Expand Up @@ -135,7 +146,7 @@ public function check_post_types_public_availability() {
}

// There are post types that have been made private.
if ( $newly_made_non_public_post_types ) {
if ( $newly_made_non_public_post_types && $this->indexable_helper->should_index_indexables() ) {
// Schedule a cron job to remove all the posts whose post type has been made private.
$cleanup_not_yet_scheduled = ! \wp_next_scheduled( Cleanup_Integration::START_HOOK );
if ( $cleanup_not_yet_scheduled ) {
Expand Down
6 changes: 4 additions & 2 deletions src/integrations/watchers/indexable-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Indexable_Post_Watcher implements Integration_Interface {
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array
* @return array<string> The conditionals.
*/
public static function get_conditionals() {
return [ Migrations_Conditional::class ];
Expand Down Expand Up @@ -240,7 +240,9 @@ protected function update_has_public_posts( $indexable ) {
$author_indexable->has_public_posts = $this->author_archive->author_has_public_posts( $author_indexable->object_id );
$this->indexable_helper->save_indexable( $author_indexable );

$this->reschedule_cleanup_if_author_has_no_posts( $author_indexable );
if ( $this->indexable_helper->should_index_indexable( $author_indexable ) ) {
$this->reschedule_cleanup_if_author_has_no_posts( $author_indexable );
}
}
} catch ( Exception $exception ) {
$this->logger->log( LogLevel::ERROR, $exception->getMessage() );
Expand Down
17 changes: 14 additions & 3 deletions src/integrations/watchers/indexable-taxonomy-change-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional;
use Yoast\WP\SEO\Config\Indexing_Reasons;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Indexing_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Taxonomy_Helper;
Expand All @@ -28,6 +29,13 @@ class Indexable_Taxonomy_Change_Watcher implements Integration_Interface {
*/
protected $indexing_helper;

/**
* The indexable helper.
*
* @var Indexable_Helper
*/
protected $indexable_helper;

/**
* Holds the Options_Helper instance.
*
Expand All @@ -52,7 +60,7 @@ class Indexable_Taxonomy_Change_Watcher implements Integration_Interface {
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array
* @return array<string> The conditionals.
*/
public static function get_conditionals() {
return [ Not_Admin_Ajax_Conditional::class, Admin_Conditional::class, Migrations_Conditional::class ];
Expand All @@ -65,17 +73,20 @@ public static function get_conditionals() {
* @param Options_Helper $options The options helper.
* @param Taxonomy_Helper $taxonomy_helper The taxonomy helper.
* @param Yoast_Notification_Center $notification_center The notification center.
* @param Indexable_Helper $indexable_helper The indexable helper.
*/
public function __construct(
Indexing_Helper $indexing_helper,
Options_Helper $options,
Taxonomy_Helper $taxonomy_helper,
Yoast_Notification_Center $notification_center
Yoast_Notification_Center $notification_center,
Indexable_Helper $indexable_helper
) {
$this->indexing_helper = $indexing_helper;
$this->options = $options;
$this->taxonomy_helper = $taxonomy_helper;
$this->notification_center = $notification_center;
$this->indexable_helper = $indexable_helper;
}

/**
Expand Down Expand Up @@ -137,7 +148,7 @@ public function check_taxonomy_public_availability() {
}

// There are taxonomies that have been made private.
if ( ! empty( $newly_made_non_public_taxonomies ) ) {
if ( ! empty( $newly_made_non_public_taxonomies ) && $this->indexable_helper->should_index_indexables() ) {
// Schedule a cron job to remove all the terms whose taxonomy has been made private.
$cleanup_not_yet_scheduled = ! \wp_next_scheduled( Cleanup_Integration::START_HOOK );
if ( $cleanup_not_yet_scheduled ) {
Expand Down
Loading
Loading