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

Add Indexable visibility columns #17757

Open
wants to merge 58 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b3fd2cd
Ensure array return type
diedexx Nov 12, 2021
87c11c3
Allow for deprecating columns
diedexx Nov 12, 2021
2eef6e2
Add method for creating a noindex query for indexables
diedexx Nov 15, 2021
b5bc8db
Rename is_public to is_publicly_viewable and number_of_public_posts t…
diedexx Nov 15, 2021
6c015ba
Use PHP 5.6 syntax
diedexx Nov 16, 2021
3d96968
Add migrations
diedexx Nov 16, 2021
acdf97a
Deprecate is_public instead of immediately replacing it
diedexx Nov 16, 2021
e18c9ac
Keep the method name the same and deprecate
diedexx Nov 16, 2021
58d6a71
Access properties that were renamed earlier
diedexx Nov 16, 2021
b7cfa04
Make the homepage get a number_of_publicly_viewable_posts and is_publ…
diedexx Nov 16, 2021
c2d121e
Use new column name
diedexx Nov 16, 2021
38b552d
Add deprecation tags
diedexx Nov 16, 2021
2fdce2f
Fix cs
diedexx Nov 16, 2021
3a18f72
Mark enabled date archives as publicly viewable
diedexx Nov 26, 2021
5e89640
Delegate logic to central helper
diedexx Nov 26, 2021
0a38f49
Make global namespace usage explicit
diedexx Nov 26, 2021
81e7421
Flip argument order
diedexx Nov 26, 2021
1564f53
Allow for considering empty archives as indexed
diedexx Nov 26, 2021
ecae28e
Update deperatation based on the expected release version
diedexx Nov 26, 2021
ea0a46e
Prevent new integrators from accessing is_public
diedexx Nov 26, 2021
6ccacd5
Update tests
diedexx Nov 26, 2021
ccf7f9b
Remove resolved todo comment
diedexx Nov 26, 2021
af7b219
Rebuild date archive indexable when disabling date archives
diedexx Nov 26, 2021
510f9de
Fix cs
diedexx Nov 26, 2021
ed46abb
Prevent deprecation warnings when (re)indexing
diedexx Nov 26, 2021
ff247f9
Include password protected posts in aggegrate queries
diedexx Nov 30, 2021
ca85a07
Keep the most recent last modified date.
diedexx Nov 30, 2021
faf1180
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Nov 30, 2021
f6a8adf
Adhere to naming conventions
diedexx Dec 2, 2021
274df53
Don't hardcode the deprecation version number
diedexx Dec 2, 2021
d51829e
Update deprecation versions and descriptions
diedexx Dec 2, 2021
5c1193a
Rename migration
diedexx Dec 2, 2021
661e9a3
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 3, 2021
82f8a78
Fix cs
diedexx Dec 3, 2021
66d6e4d
Update tests
diedexx Dec 3, 2021
cf56df4
Fill WP 5.7 function
diedexx Dec 3, 2021
68aba31
Mock calls to newly introduced functions
diedexx Dec 3, 2021
3329a1b
Polyfill WP 5.7 function
diedexx Dec 3, 2021
e906ace
Lower error threshold
diedexx Dec 3, 2021
29739ee
Remove unused function that never made it into trunk
diedexx Dec 3, 2021
66c9433
Remove test double funtion that was removed in its parent
diedexx Dec 6, 2021
9eb9263
Make global namespace explicit
diedexx Dec 7, 2021
0c9ac1a
Ensure that post_types is an array
diedexx Dec 7, 2021
2059186
Automatically update date-archive indexables
diedexx Dec 7, 2021
b95492e
Use the type of the originally requested property in case of replaced…
diedexx Dec 10, 2021
101edcf
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 10, 2021
5d095a5
Fix CS warnings and errors
diedexx Dec 10, 2021
d8f754f
Fix tests
diedexx Dec 10, 2021
f613dfc
Clarify that the comment is about a function
diedexx Dec 17, 2021
3e7e755
Add instructions to remove related code
diedexx Dec 17, 2021
c24488e
Reduce risk of using the same builder version twice.
diedexx Dec 17, 2021
4ed8b38
Update post relation indexables when a post is set to private
diedexx Dec 17, 2021
275c423
Fix cs
diedexx Dec 18, 2021
08c1f5f
Fix precedence issues in query
diedexx Dec 19, 2021
e1c5055
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 20, 2021
6cf15bf
Increase threhshold
diedexx Dec 20, 2021
bad2929
Exclude password protected posts from the publicly_viewable_count
diedexx Dec 21, 2021
148d47c
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into FIX-22-nu…
Dec 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix cs
  • Loading branch information
diedexx committed Nov 16, 2021
commit 2fdce2fa88d397a99e673078426ae75400b8829f
10 changes: 7 additions & 3 deletions lib/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function set_orm( $orm ) {
*/
public function __get( $property ) {
$property = $this->handleDeprecation( $property );
$value = $this->orm->get( $property );
$value = $this->orm->get( $property );

if ( $value !== null && \in_array( $property, $this->boolean_columns, true ) ) {
return (bool) $value;
Expand Down Expand Up @@ -748,7 +748,11 @@ protected function handleDeprecation( $property ) {

if ( ! empty( $deprecation['replacement'] ) ) {
// There is no _deprecated_property. This matches our usecase best.
_deprecated_argument( __FUNCTION__, '17.7', 'Use the \"' . $deprecation['replacement'] . '\" property instead of \"' . $property . '\" ' );
_deprecated_argument(
__FUNCTION__,
'17.7',
'Use the \"' . esc_html( $deprecation['replacement'] ) . '\" property instead of \"' . esc_html( $property ) . '\" '
);

if ( $deprecation['automatically_use_replacement'] === true ) {
return $deprecation['replacement'];
Expand All @@ -757,7 +761,7 @@ protected function handleDeprecation( $property ) {
return $property;
}
// There is no _deprecated_property. This matches our usecase best.
diedexx marked this conversation as resolved.
Show resolved Hide resolved
_deprecated_argument( __FUNCTION__, '17.7', 'The \"' . $property . '\" property will be removed in a future version' );
_deprecated_argument( __FUNCTION__, '17.7', 'The \"' . esc_html( $property ) . '\" property will be removed in a future version' );

return $property;
}
Expand Down
17 changes: 11 additions & 6 deletions src/builders/indexable-author-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public function build( $user_id, Indexable $indexable ) {
return $indexable;
}

/**
* Sets the aggregate values for an author indexable.
*
* @param Indexable $indexable The indexable to set the aggregates for.
*
* @return Indexable The indexable with set aggregates.
*/
public function set_aggregate_values( Indexable $indexable ) {
$aggregates = $this->get_public_post_archive_aggregates( $indexable->object_id );
$indexable->object_published_at = $aggregates->first_published_at;
Expand Down Expand Up @@ -183,20 +190,18 @@ protected function find_alternative_image( Indexable $indexable ) {
protected function get_public_post_archive_aggregates( $author_id ) {
$post_statuses = $this->post_helper->get_public_post_statuses();
$post_types = $this->author_archive->get_author_archive_post_types();
// TODO DIEDE: Protected pages krijgen _geen_ noindex. en staan gewoon in het author archive. moeten die meegeteld worden?
// Private werkt wel zoals verwacht.

$sql = "
SELECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea: how about getting post ID's for an author first and iterating over those - using primary keys seems more efficient than where-ing over a set of fields.

COUNT(p.ID) as number_of_public_posts,
MAX(p.post_modified_gmt) AS most_recent_last_modified,
MIN(p.post_date_gmt) AS first_published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (" . implode( ', ', array_fill( 0, count( $post_statuses ), '%s' ) ) . ")
AND p.post_password = ''
WHERE p.post_status IN (" . implode( ', ', array_fill( 0, count( $post_statuses ), '%s' ) ) . ')
AND p.post_password = \'\'
AND p.post_author = %d
AND p.post_type IN (" . implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ) . ")
";
AND p.post_type IN (' . implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ) . ')
';

$replacements = \array_merge( $post_statuses, [ $author_id ], $post_types );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a check if $post_types is array here, before merging it to the $replacement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! that could've been a nasty bug. I added validation higher up in the get_author_post_types so we're sure that we get an array.


Expand Down
7 changes: 7 additions & 0 deletions src/builders/indexable-home-page-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public function build( $indexable ) {
return $indexable;
}

/**
* Sets the aggregate values for a home page indexable.
*
* @param Indexable $indexable The indexable to set the aggregates for.
*
* @return Indexable The indexable with set aggregates.
*/
public function set_aggregate_values( Indexable $indexable ) {
$aggregates = $this->get_public_post_archive_aggregates();
$indexable->object_published_at = $aggregates->first_published_at;
Expand Down
2 changes: 2 additions & 0 deletions src/builders/indexable-post-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ protected function get_permalink( $post_type, $post_id ) {
*
* @return bool|null Whether the post type is public. Null if no override is set.
*
* @codeCoverageIgnore
* @deprecated 17.7
*/
protected function is_public( $indexable ) {
Expand Down Expand Up @@ -219,6 +220,7 @@ protected function is_public( $indexable ) {
*
* @return bool|null False when it has no parent. Null when it has a parent.
*
* @codeCoverageIgnore
* @deprecated 17.7
*/
protected function is_public_attachment( $indexable ) {
Expand Down
7 changes: 7 additions & 0 deletions src/builders/indexable-post-type-archive-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function build( $post_type, Indexable $indexable ) {
return $indexable;
}

/**
* Sets the aggregate values for a post type archive indexable.
*
* @param Indexable $indexable The indexable to set the aggregates for.
*
* @return Indexable The indexable with set aggregates.
*/
public function set_aggregate_values( Indexable $indexable ) {
$aggregates = $this->get_public_post_archive_aggregates( $indexable->object_sub_type );
$indexable->object_published_at = $aggregates->first_published_at;
Expand Down
7 changes: 7 additions & 0 deletions src/builders/indexable-term-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public function build( $term_id, $indexable ) {
return $indexable;
}

/**
* Sets the aggregate values for a term indexable.
*
* @param Indexable $indexable The indexable to set the aggregates for.
*
* @return Indexable The indexable with set aggregates.
*/
public function set_aggregate_values( Indexable $indexable ) {
$aggregates = $this->get_public_post_archive_aggregates( $indexable->object_id, $indexable->object_sub_type );
$indexable->object_published_at = $aggregates->first_published_at;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\WP\SEO\Config\Migrations
*/

namespace Yoast\WP\SEO\Config\Migrations;

Expand Down Expand Up @@ -40,7 +35,6 @@ public function up() {
'number_of_publicly_viewable_posts',
'integer'
);

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\WP\SEO\Config\Migrations
*/

namespace Yoast\WP\SEO\Config\Migrations;

Expand Down Expand Up @@ -37,7 +32,8 @@ public function up() {
[
'null' => true,
'default' => null,
] );
]
);
}

/**
Expand All @@ -51,11 +47,10 @@ public function down() {

$this->remove_column(
$table_name,
'is_publicly_viewable',
'is_publicly_viewable'
);
}


/**
* Retrieves the table name to use.
*
Expand Down
23 changes: 3 additions & 20 deletions src/helpers/author-archive-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@
*/
class Author_Archive_Helper {

/**
* @var Indexable_Repository
*/
private $indexable_repository;

/**
* Sets the indexable repository. Done to avoid circular dependencies.
*
* @required
*
* @param Indexable_Repository $indexable_repository
*
* @return void
*/
public function setIndexableRepository( Indexable_Repository $indexable_repository ) {
$this->indexable_repository = $indexable_repository;
}

/**
* Gets the array of post types that are shown on an author's archive.
*
Expand All @@ -49,10 +31,11 @@ public function get_author_archive_post_types() {
*
* @return bool|null Whether the author has at least one public post.
*
* @codeCoverageIgnore
* @deprecated 17.7
*/
public function author_has_public_posts( $author_id ) {
_deprecated_function( __METHOD__, '17.7',Indexable_Repository::class.'::noindex_query');
_deprecated_function( __METHOD__, '17.7', esc_html( Indexable_Repository::class ) . '::noindex_query' );
// First check if the author has at least one public post.
$has_public_post = $this->author_has_a_public_post( $author_id );
if ( $has_public_post ) {
Expand Down Expand Up @@ -110,7 +93,7 @@ protected function author_has_a_public_post( $author_id ) {
*
* @return bool Whether the author has at least one post with the is public null.
*
* @deprecated 17.7
* @deprecated 17.7
*/
protected function author_has_a_post_with_is_public_null( $author_id ) {
$cache_key = 'author_has_a_post_with_is_public_null_' . $author_id;
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/post-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct( String_Helper $string ) {
*
* @return void
*/
public function setIndexableBuilder( Indexable_Builder $indexable_builder ) {
public function set_indexable_builder( Indexable_Builder $indexable_builder ) {
$this->indexable_builder = $indexable_builder;
}

Expand Down Expand Up @@ -135,6 +135,8 @@ public function get_post( $post_id ) {
return \get_post( $post_id );
}

// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Signature kept the same after deprecation.

/**
* Updates the number_of_publicly_viewable_posts field on attachments for a post_parent.
*
Expand All @@ -159,6 +161,8 @@ public function update_has_public_posts_on_attachments( $post_parent, $has_publi
return true;
}

// phpcs:enable

/**
* Determines if the post can be indexed.
*
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/robots-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
class Robots_Helper {

/**
* A helper to get and set plugin options.
*
* @var Options_Helper
*/
private $options_helper;

/**
* @param Options_Helper $options_helper The indexable version manager.
* Robots_Helper constructor.
*
* @param Options_Helper $options_helper A helper to get and set plugin options.
*/
public function __construct( Options_Helper $options_helper ) {
$this->options_helper = $options_helper;
Expand Down Expand Up @@ -45,7 +49,7 @@ public function set_robots_no_index( $robots ) {
*
* @return bool Whether the site default is set to noindex for the requested object type.
*/
public function get_default_noindex_for_object( $object_type, $object_sub_type = "" ) {
public function get_default_noindex_for_object( $object_type, $object_sub_type = '' ) {
switch ( $object_type ) {
case 'post':
return (bool) $this->options_helper->get( 'noindex-' . $object_sub_type );
Expand Down
1 change: 0 additions & 1 deletion src/integrations/watchers/indexable-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ protected function get_related_term_indexables( $post_id ) {
return $this->repository->find_by_multiple_ids_and_type( $term_ids, 'term', false );
}


/**
* Tests if the site is multisite and switched.
*
Expand Down
5 changes: 5 additions & 0 deletions src/models/indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class Indexable extends Model {
'number_of_publicly_viewable_posts',
];

/**
* Which columns are deprecated.
*
* @var array
*/
protected $deprecated_columns = [
'has_public_posts' => [
'since' => '17.7',
Expand Down
Loading