plugin updates
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Yoast\WP\SEO\Integrations\Watchers;
|
||||
|
||||
use wpdb;
|
||||
use Yoast\WP\SEO\Builders\Indexable_Hierarchy_Builder;
|
||||
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
|
||||
use Yoast\WP\SEO\Helpers\Permalink_Helper;
|
||||
@@ -40,13 +39,6 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
*/
|
||||
protected $indexable_hierarchy_repository;
|
||||
|
||||
/**
|
||||
* Represents the WordPress database object.
|
||||
*
|
||||
* @var wpdb
|
||||
*/
|
||||
protected $wpdb;
|
||||
|
||||
/**
|
||||
* Represents the permalink helper.
|
||||
*
|
||||
@@ -67,7 +59,6 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
* @param Indexable_Repository $indexable_repository The indexable repository.
|
||||
* @param Indexable_Hierarchy_Builder $indexable_hierarchy_builder The indexable hierarchy builder.
|
||||
* @param Indexable_Hierarchy_Repository $indexable_hierarchy_repository The indexable hierarchy repository.
|
||||
* @param wpdb $wpdb The wpdb object.
|
||||
* @param Permalink_Helper $permalink_helper The permalink helper.
|
||||
* @param Post_Type_Helper $post_type_helper The post type helper.
|
||||
*/
|
||||
@@ -75,13 +66,11 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
Indexable_Repository $indexable_repository,
|
||||
Indexable_Hierarchy_Builder $indexable_hierarchy_builder,
|
||||
Indexable_Hierarchy_Repository $indexable_hierarchy_repository,
|
||||
wpdb $wpdb,
|
||||
Permalink_Helper $permalink_helper,
|
||||
Post_Type_Helper $post_type_helper
|
||||
) {
|
||||
$this->indexable_repository = $indexable_repository;
|
||||
$this->indexable_hierarchy_builder = $indexable_hierarchy_builder;
|
||||
$this->wpdb = $wpdb;
|
||||
$this->indexable_hierarchy_repository = $indexable_hierarchy_repository;
|
||||
$this->permalink_helper = $permalink_helper;
|
||||
$this->post_type_helper = $post_type_helper;
|
||||
@@ -99,7 +88,7 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Returns the conditionals based on which this loadable should be active.
|
||||
*
|
||||
* @return array
|
||||
* @return array<Migrations_Conditional>
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [ Migrations_Conditional::class ];
|
||||
@@ -139,10 +128,10 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Finds all child indexables for the given term.
|
||||
*
|
||||
* @param int $term_id Term to fetch the indexable for.
|
||||
* @param Indexable[] $child_indexables The already known child indexables.
|
||||
* @param int $term_id Term to fetch the indexable for.
|
||||
* @param array<Indexable> $child_indexables The already known child indexables.
|
||||
*
|
||||
* @return array The list of additional child indexables for a given term.
|
||||
* @return array<Indexable> The list of additional child indexables for a given term.
|
||||
*/
|
||||
public function get_children_for_term( $term_id, array $child_indexables ) {
|
||||
// Finds object_ids (posts) for the term.
|
||||
@@ -195,26 +184,29 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Retrieves the object id's for a term based on the term-post relationship.
|
||||
*
|
||||
* @param int $term_id The term to get the object id's for.
|
||||
* @param Indexable[] $child_indexables The child indexables.
|
||||
* @param int $term_id The term to get the object id's for.
|
||||
* @param array<Indexable> $child_indexables The child indexables.
|
||||
*
|
||||
* @return array List with object ids for the term.
|
||||
* @return array<int> List with object ids for the term.
|
||||
*/
|
||||
protected function get_object_ids_for_term( $term_id, $child_indexables ) {
|
||||
global $wpdb;
|
||||
|
||||
$filter_terms = static function ( $child ) {
|
||||
return $child->object_type === 'term';
|
||||
};
|
||||
|
||||
$child_terms = \array_filter( $child_indexables, $filter_terms );
|
||||
$child_object_ids = \wp_list_pluck( $child_terms, 'object_id' );
|
||||
$child_object_ids = \array_merge( [ $term_id ], \wp_list_pluck( $child_terms, 'object_id' ) );
|
||||
|
||||
// Get the term-taxonomy id's for the term and its children.
|
||||
$term_taxonomy_ids = $this->wpdb->get_col(
|
||||
$this->wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$term_taxonomy_ids = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
'SELECT term_taxonomy_id
|
||||
FROM ' . $this->wpdb->term_taxonomy . '
|
||||
WHERE term_id IN( ' . \implode( ', ', \array_fill( 0, ( \count( $child_object_ids ) + 1 ), '%s' ) ) . ' )',
|
||||
$term_id,
|
||||
FROM %i
|
||||
WHERE term_id IN( ' . \implode( ', ', \array_fill( 0, ( \count( $child_object_ids ) ), '%s' ) ) . ' )',
|
||||
$wpdb->term_taxonomy,
|
||||
...$child_object_ids
|
||||
)
|
||||
);
|
||||
@@ -225,11 +217,13 @@ class Indexable_Ancestor_Watcher implements Integration_Interface {
|
||||
}
|
||||
|
||||
// Get the (post) object id's that are attached to the term.
|
||||
return $this->wpdb->get_col(
|
||||
$this->wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
return $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
'SELECT DISTINCT object_id
|
||||
FROM ' . $this->wpdb->term_relationships . '
|
||||
FROM %i
|
||||
WHERE term_taxonomy_id IN( ' . \implode( ', ', \array_fill( 0, \count( $term_taxonomy_ids ), '%s' ) ) . ' )',
|
||||
$wpdb->term_relationships,
|
||||
...$term_taxonomy_ids
|
||||
)
|
||||
);
|
||||
|
||||
@@ -28,7 +28,7 @@ class Option_Titles_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Returns the conditionals based on which this loadable should be active.
|
||||
*
|
||||
* @return array
|
||||
* @return array<Migrations_Conditional>
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [ Migrations_Conditional::class ];
|
||||
@@ -37,8 +37,8 @@ class Option_Titles_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Checks if one of the relevant options has been changed.
|
||||
*
|
||||
* @param array $old_value The old value of the option.
|
||||
* @param array $new_value The new value of the option.
|
||||
* @param array<string,int,bool> $old_value The old value of the option.
|
||||
* @param array<string,int,bool> $new_value The new value of the option.
|
||||
*
|
||||
* @return bool Whether or not the ancestors are removed.
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ class Option_Titles_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Retrieves the relevant keys.
|
||||
*
|
||||
* @return array Array with the relevant keys.
|
||||
* @return array<string> Array with the relevant keys.
|
||||
*/
|
||||
protected function get_relevant_keys() {
|
||||
$post_types = \get_post_types( [ 'public' => true ], 'names' );
|
||||
@@ -95,7 +95,7 @@ class Option_Titles_Watcher implements Integration_Interface {
|
||||
/**
|
||||
* Removes the ancestors for given post types.
|
||||
*
|
||||
* @param array $post_types The post types to remove hierarchy for.
|
||||
* @param array<string> $post_types The post types to remove hierarchy for.
|
||||
*
|
||||
* @return bool True when delete query was successful.
|
||||
*/
|
||||
@@ -105,21 +105,23 @@ class Option_Titles_Watcher implements Integration_Interface {
|
||||
}
|
||||
|
||||
$wpdb = Wrapper::get_wpdb();
|
||||
$total = \count( $post_types );
|
||||
$hierarchy_table = Model::get_table_name( 'Indexable_Hierarchy' );
|
||||
$indexable_table = Model::get_table_name( 'Indexable' );
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Delete query.
|
||||
$result = $wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"
|
||||
DELETE FROM `$hierarchy_table`
|
||||
DELETE FROM %i
|
||||
WHERE indexable_id IN(
|
||||
SELECT id
|
||||
FROM `$indexable_table`
|
||||
FROM %i
|
||||
WHERE object_type = 'post'
|
||||
AND object_sub_type IN( " . \implode( ', ', \array_fill( 0, $total, '%s' ) ) . ' )
|
||||
AND object_sub_type IN( " . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ' )
|
||||
)',
|
||||
$post_types
|
||||
$hierarchy_table,
|
||||
$indexable_table,
|
||||
...$post_types
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user