-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GP Profiles: Add notifier for suggesting strings and approval.
See WordPress/five-for-the-future#196 git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11929 74240141-8908-4e6f-9713-ba540dce6ec7
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/profiles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Plugin name: GlotPress Profiles Activity Notifier | ||
* Description: Adds activity to profiles.wordpress.org when contributors do noteworthy things. | ||
* Author: WordPress.org | ||
* License: GPLv2 or later | ||
*/ | ||
|
||
namespace WordPressdotorg\GlotPress\Profiles; | ||
|
||
use WordPressdotorg\Profiles as Profiles_API; | ||
use GP_Translation; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
/* | ||
* Requests will always fail when in local environments, unless the dev is proxied. Proxied devs could test | ||
* locally if they're careful (especially with user IDs), but it's better to test on w.org sandboxes with | ||
* test accounts. That prevents real profiles from having test data accidentally added to them. | ||
*/ | ||
if ( 'local' === wp_get_environment_type() ) { | ||
return; | ||
} | ||
|
||
add_action( 'gp_translation_created', __NAMESPACE__ . '\add_translation_activity' ); | ||
add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_translation_activity' ); | ||
|
||
/** | ||
* Add a activity when strings are suggested and approved. | ||
*/ | ||
function add_translation_activity( GP_Translation $translation ) : void { | ||
if ( 'waiting' === $translation->status ) { | ||
$type = 'glotpress_translation_suggested'; | ||
} elseif ( 'current' === $translation->status ) { | ||
$type = 'glotpress_translation_approved'; | ||
} else { | ||
return; | ||
} | ||
|
||
$request_body = array( | ||
'action' => 'wporg_handle_activity', | ||
'component' => 'glotpress', | ||
'type' => $type, | ||
'user_id' => $translation->user_id, | ||
); | ||
|
||
Profiles_API\api( $request_body ); | ||
} |
56 changes: 56 additions & 0 deletions
56
wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/tests/e2e.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* ⚠️ These tests run against the production database and object cache on w.org and profiles.w.org. | ||
* Make sure that any modifications are hardcoded to only affect test sites and test user accounts. | ||
* | ||
* usage: wp eval-file e2e.php test_name | ||
*/ | ||
|
||
namespace WordPressdotorg\GlotPress\Profiles\Tests; | ||
|
||
use WordPressdotorg\GlotPress\Profiles as GlotPress_Profiles; | ||
use Exception, WP_User, GP_Translation; | ||
|
||
ini_set( 'display_errors', 'On' ); // won't do anything if fatal errors | ||
|
||
if ( 'staging' !== wp_get_environment_type() || 'cli' !== php_sapi_name() ) { | ||
die( 'Error: Wrong environment.' ); | ||
} | ||
|
||
if ( 700 !== get_current_blog_id() ) { | ||
die( 'Must be run on translate-test.wordpress.org.' ); | ||
} | ||
|
||
const TEST_USERNAME = 'iandunn-test'; | ||
|
||
/** @var array $args */ | ||
main( $args[0] ); | ||
|
||
function main( $case ) { | ||
$user = get_user_by( 'slug', TEST_USERNAME ); | ||
|
||
try { | ||
call_user_func( __NAMESPACE__ . "\\test_$case", $user ); | ||
|
||
} catch ( Exception $exception ) { | ||
echo $exception->getMessage(); | ||
|
||
} | ||
} | ||
|
||
function test_add( WP_User $user ) { | ||
$translation = new GP_Translation( array( | ||
'user_id' => $user->ID, | ||
'status' => 'waiting', | ||
) ); | ||
GlotPress_Profiles\add_translation_activity( $translation ); | ||
|
||
$translation = new GP_Translation( array( | ||
'user_id' => $user->ID, | ||
'status' => 'current', | ||
) ); | ||
GlotPress_Profiles\add_translation_activity( $translation ); | ||
|
||
echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n"; | ||
} |