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

WPGatsby Stability #74

Merged
merged 27 commits into from
Dec 15, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
70c1825
Merge branch 'master' into bug/#59-expensive-meta-queries
jasonbahl Dec 1, 2020
d37ee0e
Merge commit 'd81424852e49536c4a0a431434554bfd5539e65f' into bug/#59-…
jasonbahl Dec 2, 2020
f7ae655
- Move action monitors into their own classes
jasonbahl Dec 8, 2020
051659b
- add support for ACF Field Groups to trigger Action Monitor Actions
jasonbahl Dec 8, 2020
f801a5e
- Update how default JWT Setting is set
jasonbahl Dec 8, 2020
5d26c49
- add phpunit 9.4.1 to allow tests to continue to pass. Seems like ne…
jasonbahl Dec 10, 2020
442c484
- Add "Upcoming" Section to the changelog
jasonbahl Dec 10, 2020
839eb39
Merge commit '1bbc3d34bb8d0b567e0841e75ba48f82839d4260' into feature/…
jasonbahl Dec 10, 2020
b7f9dac
- fix test for user deletes
jasonbahl Dec 11, 2020
ea05ed4
- remove hirak/prestissimo dependency
jasonbahl Dec 11, 2020
96dd639
- update codesniffer installer
jasonbahl Dec 11, 2020
9cbb6ce
no message
jasonbahl Dec 11, 2020
b2df592
no message
jasonbahl Dec 11, 2020
c318e20
no message
jasonbahl Dec 11, 2020
5601181
- update composer.json
jasonbahl Dec 11, 2020
cd6add0
Revert "- update composer.json"
jasonbahl Dec 11, 2020
df58ee3
no message
jasonbahl Dec 11, 2020
24a9ad3
no message
jasonbahl Dec 11, 2020
1ff10fb
- set the PHP version to 7.3 and the WordPress version to 5.4.2 to ma…
jasonbahl Dec 11, 2020
0e11434
no message
jasonbahl Dec 11, 2020
c0dc5b2
- updating action monitor titles and statuses
jasonbahl Dec 11, 2020
323dbac
no message
jasonbahl Dec 11, 2020
7ef5dd4
- updating term ids
jasonbahl Dec 11, 2020
2c1c07a
- updating user ids to be cast as integers
jasonbahl Dec 11, 2020
fcc11bc
- update menu item IDs to use ->ID instead of ->term_id
jasonbahl Dec 11, 2020
52ad7fe
- Update NavMenuMonitor to properly track delete_nav_menu action
jasonbahl Dec 14, 2020
419a6bb
- Update NavMenuMonitor to show only the ID for deleted menus instead…
jasonbahl Dec 15, 2020
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
- Update NavMenuMonitor to show only the ID for deleted menus instead…
… of the name "Menu" as a prefix

- Update code formatting in PostMonitor.php
- remove copy-pasta from UserMonitor.php
- Update action log for delete and re-assign to only log actions for published posts that are being re-assigned
jasonbahl committed Dec 15, 2020
commit 419a6bbdc06e50417e46594999f0979b90b423de
4 changes: 2 additions & 2 deletions src/ActionMonitor/Monitors/NavMenuMonitor.php
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public function log_diffed_menus( array $old_locations, array $new_locations ) {
$this->log_action(
[
'action_type' => 'DELETE',
'title' => 'Menu: ' . $removed_menu_id,
'title' => $removed_menu_id,
// menus don't have post status. This is for Gatsby
'status' => 'trash',
'node_id' => (int) $removed_menu_id,
@@ -174,7 +174,7 @@ public function callback_delete_nav_menu( $term_id ) {
$this->log_action(
[
'action_type' => 'DELETE',
'title' => 'Menu: ' . $term_id,
'title' => '#' . $term_id,
// menus don't have post status. This is for Gatsby
'status' => 'trash',
'node_id' => (int) $term_id,
4 changes: 2 additions & 2 deletions src/ActionMonitor/Monitors/PostMonitor.php
Original file line number Diff line number Diff line change
@@ -312,10 +312,10 @@ public function log_user_update( WP_Post $post ) {

if ( ! $user_monitor->is_published_author( $user->ID ) ) {
$action_type = 'DELETE';
$status = 'trash';
$status = 'trash';
} else {
$action_type = 'UPDATE';
$status = 'publish';
$status = 'publish';
}

$this->log_action(
59 changes: 22 additions & 37 deletions src/ActionMonitor/Monitors/UserMonitor.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ class UserMonitor extends Monitor {

/**
* IDs of posts to reassign
*
* @var array
*/
protected $post_ids_to_reassign;
@@ -24,29 +25,7 @@ class UserMonitor extends Monitor {
*
* @return mixed|void
*/
public function init() {if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {

// If there's a post for the Post ID
if ( ! empty( $post = get_post( absint( $post_id ) ) ) ) {

// Get the post type object
$post_type_object = get_post_type_object( $post->post_type );

// Log an action for the post being re-assigned
$this->log_action( [
'action_type' => 'UPDATE',
'title' => $post->post_title,
'node_id' => (int) $post_id,
'relay_id' => Relay::toGlobalId( 'post', (int) $post_id ),
'graphql_single_name' => $post_type_object->graphql_single_name,
'graphql_plural_name' => $post_type_object->graphql_plural_name,
'status' => 'publish',
] );

}
}
}
public function init() {

$this->post_ids_to_reassign = [];

@@ -181,12 +160,11 @@ public function callback_delete_user( $user_id, $reassign_id ) {
global $wpdb;
$post_types = $this->action_monitor->get_tracked_post_types();
$post_types = implode( "', '", $post_types );
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types')", $user_id ) );
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type IN ('$post_types')", $user_id ) );

if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
$this->post_ids_to_reassign = array_merge( $this->post_ids_to_reassign, $post_ids );
}

}

$this->users_before_delete[ (int) $user_id ] = [
@@ -220,7 +198,7 @@ public function callback_deleted_user( int $user_id ) {
]
);

if ( isset ( $before_delete['reassign']->display_name ) ) {
if ( isset( $before_delete['reassign']->display_name ) ) {
$this->log_action(
[
'action_type' => 'UPDATE',
@@ -233,30 +211,37 @@ public function callback_deleted_user( int $user_id ) {
]
);

if ( ! empty( $this->post_ids_to_reassign ) && is_array( $this->post_ids_to_reassign ) ) {
if ( ! empty( $this->post_ids_to_reassign ) && is_array( $this->post_ids_to_reassign ) ) {

foreach ( $this->post_ids_to_reassign as $post_id ) {

// If there's a post for the Post ID
if ( ! empty( $post = get_post( absint( $post_id ) ) ) ) {

// If the post status is not published, don't track an action for it
if ( 'publish' !== $post->post_status ) {
return;
}

// Get the post type object
$post_type_object = get_post_type_object( $post->post_type );

// Log an action for the post being re-assigned
$this->log_action( [
'action_type' => 'UPDATE',
'title' => $post->post_title,
'node_id' => (int) $post_id,
'relay_id' => Relay::toGlobalId( 'post', (int) $post_id ),
'graphql_single_name' => $post_type_object->graphql_single_name,
'graphql_plural_name' => $post_type_object->graphql_plural_name,
'status' => 'publish',
] );
$this->log_action(
[
'action_type' => 'UPDATE',
'title' => $post->post_title,
'node_id' => (int) $post_id,
'relay_id' => Relay::toGlobalId( 'post', (int) $post_id ),
'graphql_single_name' => $post_type_object->graphql_single_name,
'graphql_plural_name' => $post_type_object->graphql_plural_name,
'status' => 'publish',
]
);

}
}
}

}

}
10 changes: 10 additions & 0 deletions tests/wpunit/ActionMonitorTest.php
Original file line number Diff line number Diff line change
@@ -1278,6 +1278,16 @@ public function testDeleteUserAndReassignPostsCreatesActionMonitorAction() {
'post_title' => 'test'
] );


// Also create a draft page assigned to the user. This should NOT trigger an action
// when it's re-assigned during user deletion
$draft_page_id = $this->factory()->post->create( [
'post_type' => 'page',
'post_status' => 'draft',
'post_author' => $user_id,
'post_title' => 'test'
] );

$this->clear_action_monitor();

// Query for action monitor actions