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
Deprecate is_public instead of immediately replacing it
is_public is replaced by a different approach in querying data and
by is_publicly_viewable. If we would immediately replace is_public
with is_publicly_viewable, that would be a BC break.
  • Loading branch information
diedexx committed Nov 16, 2021
commit acdf97a6ad3b99ece006bf09122435e19ba24d28
15 changes: 10 additions & 5 deletions lib/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Model implements JsonSerializable {
protected $float_columns = [];

/**
* Which columns are deprecated and optionally: what are their replacements.
* Which columns are deprecated.
*
* @var array
*/
Expand Down Expand Up @@ -599,6 +599,7 @@ public function __isset( $property ) {
*/
public function get( $property ) {
$property = $this->handleDeprecation( $property );

return $this->orm->get( $property );
}

Expand Down Expand Up @@ -743,13 +744,17 @@ protected function handleDeprecation( $property ) {
if ( ! array_key_exists( $property, $this->deprecated_columns ) ) {
return $property;
}
$replacement = $this->deprecated_columns[ $property ];
$deprecation = $this->deprecated_columns[ $property ];

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

if ( $deprecation['automatically_use_replacement'] === true ) {
return $deprecation['replacement'];
}

return $replacement;
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' );
Expand Down
1 change: 1 addition & 0 deletions src/builders/indexable-author-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function build( $user_id, Indexable $indexable ) {
$indexable->is_robots_noarchive = null;
$indexable->is_robots_noimageindex = null;
$indexable->is_robots_nosnippet = null;
$indexable->is_public = ( $indexable->is_robots_noindex ) ? false : null;
$indexable->blog_id = \get_current_blog_id();

$this->reset_social_images( $indexable );
Expand Down
16 changes: 9 additions & 7 deletions src/builders/indexable-date-archive-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public function __construct(
* @return Indexable The extended indexable.
*/
public function build( $indexable ) {
$indexable->object_type = 'date-archive';
$indexable->title = $this->options->get( 'title-archive-wpseo' );
$indexable->description = $this->options->get( 'metadesc-archive-wpseo' );
$indexable->is_robots_noindex = $this->options->get( 'noindex-archive-wpseo' );
$indexable->blog_id = \get_current_blog_id();
$indexable->permalink = null;
$indexable->version = $this->version;
$indexable->object_type = 'date-archive';
$indexable->title = $this->options->get( 'title-archive-wpseo' );
$indexable->description = $this->options->get( 'metadesc-archive-wpseo' );
$indexable->is_robots_noindex = $this->options->get( 'noindex-archive-wpseo' );
$indexable->is_public = ( (int) $indexable->is_robots_noindex !== 1 );
$indexable->is_publicly_viewable = (bool) $this->options->get( 'disable-date' );
$indexable->blog_id = \get_current_blog_id();
$indexable->permalink = null;
$indexable->version = $this->version;

return $indexable;
}
Expand Down
67 changes: 60 additions & 7 deletions src/builders/indexable-post-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ public function build( $post_id, $indexable ) {
$indexable->author_id = $post->post_author;
$indexable->post_parent = $post->post_parent;

$indexable->number_of_pages = $this->get_number_of_pages_for_post( $post );
$indexable->post_status = $post->post_status;
$indexable->is_protected = $post->post_password !== '';

$indexable->blog_id = \get_current_blog_id();
$indexable->number_of_pages = $this->get_number_of_pages_for_post( $post );
$indexable->post_status = $post->post_status;
$indexable->is_protected = $post->post_password !== '';
$indexable->is_public = $this->is_public( $indexable );
$indexable->is_publicly_viewable = \is_post_publicly_viewable( $post );
$indexable->number_of_publicly_viewable_posts = 0;
$indexable->blog_id = \get_current_blog_id();

$indexable->schema_page_type = $this->get_meta_value( $post_id, 'schema_page_type' );
$indexable->schema_article_type = $this->get_meta_value( $post_id, 'schema_article_type' );

$indexable->object_last_modified = $post->post_modified_gmt;
$indexable->object_published_at = $post->post_date_gmt;

$indexable->number_of_publicly_viewable_posts = 0;
$indexable->is_publicly_viewable = \is_post_publicly_viewable( $post );

$indexable->version = $this->version;

Expand All @@ -178,6 +178,59 @@ protected function get_permalink( $post_type, $post_id ) {
return \wp_get_attachment_url( $post_id );
}

/**
* Determines the value of is_public.
*
* @param Indexable $indexable The indexable.
*
* @return bool|null Whether the post type is public. Null if no override is set.
*
* @deprecated 17.7
*/
protected function is_public( $indexable ) {
if ( $indexable->is_protected === true ) {
return false;
}

if ( $indexable->is_robots_noindex === true ) {
return false;
}

// Attachments behave differently than the other post types, since they inherit from their parent.
if ( $indexable->object_sub_type === 'attachment' ) {
return $this->is_public_attachment( $indexable );
}

if ( ! \in_array( $indexable->post_status, $this->post_helper->get_public_post_statuses(), true ) ) {
return false;
}

if ( $indexable->is_robots_noindex === false ) {
return true;
}

return null;
}

/**
* Determines the value of is_public for attachments.
*
* @param Indexable $indexable The indexable.
*
* @return bool|null False when it has no parent. Null when it has a parent.
*
* @deprecated 17.7
*/
protected function is_public_attachment( $indexable ) {
// If the attachment has no parent, it should not be public.
if ( empty( $indexable->post_parent ) ) {
return false;
}

// If the attachment has a parent, the is_public should be NULL.
return null;
}

/**
* Converts the meta robots noindex value to the indexable value.
*
Expand Down
1 change: 1 addition & 0 deletions src/builders/indexable-post-type-archive-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function build( $post_type, Indexable $indexable ) {
$indexable->breadcrumb_title = $this->get_breadcrumb_title( $post_type );
$indexable->permalink = \get_post_type_archive_link( $post_type );
$indexable->is_robots_noindex = (bool) $this->options->get( 'noindex-ptarchive-' . $post_type );
$indexable->is_public = ( (int) $indexable->is_robots_noindex !== 1 );
$indexable->blog_id = \get_current_blog_id();

$post_type_object = get_post_type_object( $post_type );
Expand Down
1 change: 1 addition & 0 deletions src/builders/indexable-term-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function build( $term_id, $indexable ) {
);

$indexable->is_robots_noindex = $this->get_noindex_value( $this->get_meta_value( 'wpseo_noindex', $term_meta ) );
$indexable->is_public = ( $indexable->is_robots_noindex === null ) ? null : ! $indexable->is_robots_noindex;

$this->reset_social_images( $indexable );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class ReplaceIsPublicOnIndexables extends Migration {
*/
public function up() {
$table_name = $this->get_table_name();

$this->rename_column(
$this->add_column(
$table_name,
'is_public',
'is_publicly_viewable'
);

'is_publicly_viewable',
'boolean',
[
'null' => true,
'default' => null,
] );
}

/**
Expand All @@ -48,10 +49,9 @@ public function up() {
public function down() {
$table_name = $this->get_table_name();

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

Expand Down
11 changes: 6 additions & 5 deletions src/integrations/watchers/indexable-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function __construct(
*/
public function register_hooks() {
\add_action( 'wp_insert_post', [ $this, 'build_indexable' ], \PHP_INT_MAX );
\add_action( 'delete_post', [ $this, 'delete_indexable' ] );
\add_action( 'delete_post', [ $this, 'delete_indexable' ], 10, 2 );
\add_action( 'wpseo_save_indexable', [ $this, 'updated_indexable' ], \PHP_INT_MAX, 2 );

\add_action( 'edit_attachment', [ $this, 'build_indexable' ], \PHP_INT_MAX );
Expand All @@ -130,11 +130,12 @@ public function register_hooks() {
/**
* Deletes the meta when a post is deleted.
*
* @param int $post_id Post ID.
* @param int $post_id Post ID.
* @param \WP_Post $post The to be deleted post.
*
* @return void
*/
public function delete_indexable( $post_id ) {
public function delete_indexable( $post_id, $post ) {
$indexable = $this->repository->find_by_id_and_type( $post_id, 'post', false );

// Only interested in post indexables.
Expand All @@ -145,7 +146,7 @@ public function delete_indexable( $post_id ) {
$this->hierarchy_repository->clear_ancestors( $indexable->id );
$this->link_builder->delete( $indexable );
$indexable->delete();
$this->update_relations( $this->post->get_post( $post_id ) );
$this->update_relations( $post );
}

/**
Expand Down Expand Up @@ -203,7 +204,7 @@ public function build_indexable( $post_id ) {
*/
protected function update_relations( $post ) {
$related_indexables = $this->get_related_indexables( $post );
$now = current_time( 'mysql' );
$now = current_time( 'mysql' );
foreach ( $related_indexables as $related_indexable ) {
$related_indexable->object_last_modified = $now;
$this->builder->recalculate_aggregates( $related_indexable );
Expand Down
14 changes: 11 additions & 3 deletions src/models/indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class Indexable extends Model {
'is_robots_noimageindex',
'is_robots_nosnippet',
'is_cornerstone',
'is_public',
'is_publicly_viewable',
'is_protected',
'calculated_no_index',
];

/**
Expand All @@ -138,8 +138,16 @@ class Indexable extends Model {
];

protected $deprecated_columns = [
'has_public_posts' => 'number_of_publicly_viewable_posts',
'is_public' => 'is_publicly_viewable',
'has_public_posts' => [
'since' => '17.7',
'replacement' => 'number_of_publicly_viewable_posts',
'automatically_use_replacement' => true,
],
'is_public' => [
'since' => '17.7',
'replacement' => 'is_publicly_viewable',
'automatically_use_replacement' => false,
],
];

/**
Expand Down