mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-21 10:33:44 +03:00
Contributors: Add user data for users that don't have expected meta.
Some users don't have any of the expected meta fields. The previous commit caused them to be skipped, resulting in distorted stats.
This commit is contained in:
parent
f9701f3bf1
commit
3a939bb9ad
|
@ -711,17 +711,23 @@ function add_user_data_to_xprofile( array $xprofiles ) : array {
|
||||||
// phpcs:disable -- `$id_placeholders` is safely created above.
|
// phpcs:disable -- `$id_placeholders` is safely created above.
|
||||||
$established_users = $wpdb->get_results( $wpdb->prepare( "
|
$established_users = $wpdb->get_results( $wpdb->prepare( "
|
||||||
SELECT
|
SELECT
|
||||||
u.ID, u.user_email, u.user_registered, u.user_nicename,
|
u.ID, u.user_email, u.user_registered, u.user_nicename,
|
||||||
GROUP_CONCAT( um.meta_key ) AS meta_keys,
|
um.meta_keys, um.meta_values
|
||||||
GROUP_CONCAT( um.meta_value ) AS meta_values
|
|
||||||
FROM `$wpdb->users` u
|
FROM `$wpdb->users` u
|
||||||
JOIN `$wpdb->usermeta` um ON u.ID = um.user_id
|
LEFT JOIN (
|
||||||
WHERE
|
SELECT
|
||||||
um.user_id IN ( $id_placeholders ) AND
|
user_id,
|
||||||
um.meta_key IN ( 'last_logged_in', '5ftf_last_inactivity_email', 'first_name' )
|
GROUP_CONCAT( meta_key ) AS meta_keys,
|
||||||
GROUP BY um.user_id
|
GROUP_CONCAT( meta_value ) AS meta_values
|
||||||
|
FROM `$wpdb->usermeta`
|
||||||
|
WHERE
|
||||||
|
user_id IN ( $id_placeholders ) AND
|
||||||
|
meta_key IN ( 'last_logged_in', '5ftf_last_inactivity_email', 'first_name' )
|
||||||
|
GROUP BY user_id
|
||||||
|
) um ON u.ID = um.user_id
|
||||||
|
WHERE u.ID IN ( $id_placeholders )
|
||||||
ORDER BY u.ID",
|
ORDER BY u.ID",
|
||||||
$user_ids
|
array_merge( $user_ids, $user_ids )
|
||||||
) );
|
) );
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
|
|
||||||
|
@ -734,11 +740,13 @@ function add_user_data_to_xprofile( array $xprofiles ) : array {
|
||||||
'user_nicename' => $user->user_nicename,
|
'user_nicename' => $user->user_nicename,
|
||||||
);
|
);
|
||||||
|
|
||||||
$keys = explode( ',', $user->meta_keys );
|
if ( ! empty( $user->meta_keys ) ) {
|
||||||
$values = explode( ',', $user->meta_values );
|
$keys = explode( ',', $user->meta_keys );
|
||||||
|
$values = explode( ',', $user->meta_values );
|
||||||
|
|
||||||
foreach ( $keys as $index => $key ) {
|
foreach ( $keys as $index => $key ) {
|
||||||
$full_user[ $key ] = maybe_unserialize( $values[ $index ] );
|
$full_user[ $key ] = maybe_unserialize( $values[ $index ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$full_user['last_logged_in'] = intval( strtotime( $full_user['last_logged_in'] ?? '' ) ); // Convert `false` to `0`.
|
$full_user['last_logged_in'] = intval( strtotime( $full_user['last_logged_in'] ?? '' ) ); // Convert `false` to `0`.
|
||||||
|
|
|
@ -45,6 +45,14 @@ function database_setup_before_class( WP_UnitTest_Factory $factory ) : array {
|
||||||
)
|
)
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
// Some users don't have any of the expected fields, so make sure they're included in tests.
|
||||||
|
$fixtures['users']['kimi'] = $factory->user->create_and_get( array(
|
||||||
|
'user_login' => 'kimi',
|
||||||
|
'user_email' => 'kimi@example.org',
|
||||||
|
'meta_input' => array()
|
||||||
|
) );
|
||||||
|
delete_user_meta( $fixtures['users']['kimi']->ID, 'first_name' );
|
||||||
|
|
||||||
$fixtures['users']['andrea'] = $factory->user->create_and_get( array(
|
$fixtures['users']['andrea'] = $factory->user->create_and_get( array(
|
||||||
'user_login' => 'andrea',
|
'user_login' => 'andrea',
|
||||||
'user_email' => 'andrea@example.org',
|
'user_email' => 'andrea@example.org',
|
||||||
|
@ -107,6 +115,8 @@ function database_set_up( array $user_ids ) : void {
|
||||||
(NULL, 30, %d, 'a:1:{i:0;s:9:\"Core Team\";}', '2019-12-03 11:00:00' ),
|
(NULL, 30, %d, 'a:1:{i:0;s:9:\"Core Team\";}', '2019-12-03 11:00:00' ),
|
||||||
(NULL, 29, %d, '35', '2019-12-02 10:00:00' ),
|
(NULL, 29, %d, '35', '2019-12-02 10:00:00' ),
|
||||||
(NULL, 30, %d, 'a:1:{i:0;s:18:\"Documentation Team\";}', '2019-12-03 11:00:00' ),
|
(NULL, 30, %d, 'a:1:{i:0;s:18:\"Documentation Team\";}', '2019-12-03 11:00:00' ),
|
||||||
|
(NULL, 29, %d, '5', '2019-12-02 10:00:00' ),
|
||||||
|
(NULL, 30, %d, 'a:2:{i:0;s:9:\"Meta Team\";i:1;s:13:\"Training Team\";}', '2019-12-03 11:00:00' ),
|
||||||
(NULL, 29, %d, '7', '2019-12-02 10:00:00' ),
|
(NULL, 29, %d, '7', '2019-12-02 10:00:00' ),
|
||||||
(NULL, 30, %d, 'a:1:{i:0;s:14:\"Polyglots Team\";}', '2019-12-03 11:00:00' ),
|
(NULL, 30, %d, 'a:1:{i:0;s:14:\"Polyglots Team\";}', '2019-12-03 11:00:00' ),
|
||||||
(NULL, 29, %d, '4', '2019-12-02 10:00:00' ),
|
(NULL, 29, %d, '4', '2019-12-02 10:00:00' ),
|
||||||
|
@ -118,7 +128,9 @@ function database_set_up( array $user_ids ) : void {
|
||||||
$user_ids[2],
|
$user_ids[2],
|
||||||
$user_ids[2],
|
$user_ids[2],
|
||||||
$user_ids[3],
|
$user_ids[3],
|
||||||
$user_ids[3]
|
$user_ids[3],
|
||||||
|
$user_ids[4],
|
||||||
|
$user_ids[4]
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Test_Stats extends WP_UnitTestCase {
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'company_sponsored_hours' => 75,
|
'company_sponsored_hours' => 75,
|
||||||
'self_sponsored_hours' => 11,
|
'self_sponsored_hours' => 16,
|
||||||
|
|
||||||
'team_company_sponsored_contributors' => array(
|
'team_company_sponsored_contributors' => array(
|
||||||
'Core Team' => 1,
|
'Core Team' => 1,
|
||||||
|
@ -73,17 +73,20 @@ class Test_Stats extends WP_UnitTestCase {
|
||||||
),
|
),
|
||||||
|
|
||||||
'team_self_sponsored_contributors' => array(
|
'team_self_sponsored_contributors' => array(
|
||||||
'Meta Team' => 1,
|
'Meta Team' => 2,
|
||||||
'Polyglots Team' => 1,
|
'Polyglots Team' => 1,
|
||||||
|
'Training Team' => 1,
|
||||||
),
|
),
|
||||||
|
|
||||||
'companies' => 2,
|
'companies' => 2,
|
||||||
'company_sponsored_contributors' => 2,
|
'company_sponsored_contributors' => 2,
|
||||||
'self_sponsored_contributors' => 2,
|
'self_sponsored_contributors' => 3,
|
||||||
'self_sponsored_contributor_activity' => 50.0,
|
'self_sponsored_contributor_activity' => 33.33,
|
||||||
'company_sponsored_contributor_activity' => 50.0,
|
'company_sponsored_contributor_activity' => 50.0,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame( $expected, get_snapshot_data() );
|
$actual = get_snapshot_data();
|
||||||
|
|
||||||
|
$this->assertSame( $expected, $actual );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue