rebase on oct-10-2023
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Yoast\WP\SEO\Commands;
|
||||
|
||||
use WP_CLI;
|
||||
use WP_CLI\ExitException;
|
||||
use WP_CLI\Utils;
|
||||
use Yoast\WP\SEO\Integrations\Cleanup_Integration;
|
||||
use Yoast\WP\SEO\Main;
|
||||
use function get_sites;
|
||||
use function WP_CLI\Utils\make_progress_bar;
|
||||
|
||||
/**
|
||||
* A WP CLI command that helps with cleaning up unwanted records from our custom tables.
|
||||
@@ -78,10 +78,10 @@ final class Cleanup_Command implements Command_Interface {
|
||||
*/
|
||||
public function cleanup( $args = null, $assoc_args = null ) {
|
||||
if ( isset( $assoc_args['interval'] ) && (int) $assoc_args['interval'] < 0 ) {
|
||||
\WP_CLI::error( __( 'The value for \'interval\' must be a positive integer.', 'wordpress-seo' ) );
|
||||
WP_CLI::error( \__( 'The value for \'interval\' must be a positive integer.', 'wordpress-seo' ) );
|
||||
}
|
||||
if ( isset( $assoc_args['batch-size'] ) && (int) $assoc_args['batch-size'] < 1 ) {
|
||||
\WP_CLI::error( __( 'The value for \'batch-size\' must be a positive integer higher than equal to 1.', 'wordpress-seo' ) );
|
||||
WP_CLI::error( \__( 'The value for \'batch-size\' must be a positive integer higher than equal to 1.', 'wordpress-seo' ) );
|
||||
}
|
||||
|
||||
if ( isset( $assoc_args['network'] ) && \is_multisite() ) {
|
||||
@@ -91,7 +91,7 @@ final class Cleanup_Command implements Command_Interface {
|
||||
$total_removed = $this->cleanup_current_site( $assoc_args );
|
||||
}
|
||||
|
||||
\WP_CLI::success(
|
||||
WP_CLI::success(
|
||||
\sprintf(
|
||||
/* translators: %1$d is the number of records that are removed. */
|
||||
\_n(
|
||||
@@ -141,9 +141,9 @@ final class Cleanup_Command implements Command_Interface {
|
||||
$site_url = \site_url();
|
||||
$total_removed = 0;
|
||||
|
||||
if ( ! \is_plugin_active( WPSEO_BASENAME ) ) {
|
||||
if ( ! \is_plugin_active( \WPSEO_BASENAME ) ) {
|
||||
/* translators: %1$s is the site url of the site that is skipped. %2$s is Yoast SEO. */
|
||||
\WP_CLI::warning( \sprintf( \__( 'Skipping %1$s. %2$s is not active on this site.', 'wordpress-seo' ), $site_url, 'Yoast SEO' ) );
|
||||
WP_CLI::warning( \sprintf( \__( 'Skipping %1$s. %2$s is not active on this site.', 'wordpress-seo' ), $site_url, 'Yoast SEO' ) );
|
||||
|
||||
return $total_removed;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ final class Cleanup_Command implements Command_Interface {
|
||||
|
||||
/* translators: %1$s is the site url of the site that is cleaned up. %2$s is the name of the cleanup task that is currently running. */
|
||||
$progress_bar_title_format = \__( 'Cleaning up %1$s [%2$s]', 'wordpress-seo' );
|
||||
$progress = make_progress_bar( \sprintf( $progress_bar_title_format, $site_url, \key( $tasks ) ), count( $tasks ) );
|
||||
$progress = Utils\make_progress_bar( \sprintf( $progress_bar_title_format, $site_url, \key( $tasks ) ), \count( $tasks ) );
|
||||
|
||||
foreach ( $tasks as $task_name => $task ) {
|
||||
// Update the progressbar title with the current task name.
|
||||
@@ -177,7 +177,7 @@ final class Cleanup_Command implements Command_Interface {
|
||||
$progress->finish();
|
||||
|
||||
$this->cleanup_integration->reset_cleanup();
|
||||
\WP_CLI::log(
|
||||
WP_CLI::log(
|
||||
\sprintf(
|
||||
/* translators: %1$d is the number of records that were removed. %2$s is the site url. */
|
||||
\_n(
|
||||
|
||||
@@ -14,6 +14,7 @@ use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface;
|
||||
use Yoast\WP\SEO\Actions\Indexing\Indexing_Prepare_Action;
|
||||
use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action;
|
||||
use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action;
|
||||
use Yoast\WP\SEO\Helpers\Indexable_Helper;
|
||||
use Yoast\WP\SEO\Main;
|
||||
|
||||
/**
|
||||
@@ -77,6 +78,13 @@ class Index_Command implements Command_Interface {
|
||||
*/
|
||||
private $prepare_indexing_action;
|
||||
|
||||
/**
|
||||
* Represents the indexable helper.
|
||||
*
|
||||
* @var Indexable_Helper
|
||||
*/
|
||||
protected $indexable_helper;
|
||||
|
||||
/**
|
||||
* Generate_Indexables_Command constructor.
|
||||
*
|
||||
@@ -96,6 +104,7 @@ class Index_Command implements Command_Interface {
|
||||
* action.
|
||||
* @param Term_Link_Indexing_Action $term_link_indexing_action The term link indexation
|
||||
* action.
|
||||
* @param Indexable_Helper $indexable_helper The indexable helper.
|
||||
*/
|
||||
public function __construct(
|
||||
Indexable_Post_Indexation_Action $post_indexation_action,
|
||||
@@ -105,7 +114,8 @@ class Index_Command implements Command_Interface {
|
||||
Indexable_Indexing_Complete_Action $complete_indexation_action,
|
||||
Indexing_Prepare_Action $prepare_indexing_action,
|
||||
Post_Link_Indexing_Action $post_link_indexing_action,
|
||||
Term_Link_Indexing_Action $term_link_indexing_action
|
||||
Term_Link_Indexing_Action $term_link_indexing_action,
|
||||
Indexable_Helper $indexable_helper
|
||||
) {
|
||||
$this->post_indexation_action = $post_indexation_action;
|
||||
$this->term_indexation_action = $term_indexation_action;
|
||||
@@ -115,6 +125,7 @@ class Index_Command implements Command_Interface {
|
||||
$this->prepare_indexing_action = $prepare_indexing_action;
|
||||
$this->post_link_indexing_action = $post_link_indexing_action;
|
||||
$this->term_link_indexing_action = $term_link_indexing_action;
|
||||
$this->indexable_helper = $indexable_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,6 +169,14 @@ class Index_Command implements Command_Interface {
|
||||
* @return void
|
||||
*/
|
||||
public function index( $args = null, $assoc_args = null ) {
|
||||
if ( ! $this->indexable_helper->should_index_indexables() ) {
|
||||
WP_CLI::log(
|
||||
\__( 'Your WordPress environment is running on a non-production site. Indexables can only be created on production environments. Please check your `WP_ENVIRONMENT_TYPE` settings.', 'wordpress-seo' )
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $assoc_args['network'] ) ) {
|
||||
$this->run_indexation_actions( $assoc_args );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user