- Timestamp:
- 02/10/2022 09:38:45 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/index.php
r11099 r11544 7 7 $trac = preg_replace( '![^a-z]!', '', $_GET['trac'] ?? '' ); 8 8 $ticket = intval( $_GET['ticket'] ?? 0 ); 9 $author = wp_unslash( $_GET['author'] ?? '' ); 9 10 $authenticated = ! empty( $_GET['authenticated'] ); // Longer caches for logged out requests. 10 11 11 if ( empty( $trac ) || empty( $ticket ) ) { 12 header( 'Content-Type: application/json' ); 13 header( 'Access-Control-Allow-Origin: *' ); 14 15 if ( empty( $trac ) || ( empty( $ticket ) && empty( $author ) ) ) { 12 16 header( 'HTTP/1.0 400 Bad Request' ); 13 header( 'Content-Type: application/json' ); 14 die( '{"error":"Ticket number is invalid."}' ); 17 die( '{"error":"Trac, Ticket number, or Author is invalid."}' ); 18 } 19 20 // Type one: Return PRs by Author. 21 if ( $author ) { 22 header( 'Cache-Control: max-age=' . HOUR_IN_SECONDS ); 23 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() + HOUR_IN_SECONDS ) ); 24 25 $user_id = get_user_by( 'slug', $author )->ID ?? 0; 26 27 $tickets = $wpdb->get_col( $wpdb->prepare( 28 "SELECT `ticket` 29 FROM `trac_github_prs` 30 WHERE trac = %s AND author = %d", 31 $trac, 32 $user_id 33 ) ); 34 35 echo wp_json_encode( $tickets ); 36 die(); 15 37 } 16 38 17 39 // Fetch any linked PRs 18 40 $prs = $wpdb->get_results( $wpdb->prepare( 19 "SELECT `repo`, `pr`, `data`, `last_checked` 41 "SELECT `repo`, `pr`, `data`, `last_checked`, `author` 20 42 FROM `trac_github_prs` 21 43 WHERE trac = %s AND ticket = %s", … … 65 87 unset( $data->data->trac_ticket ); 66 88 89 // Check if we now have an author for this PR, the author may link their account after creating the PR. 90 if ( ! $data->author ) { 91 $data->author = (int) find_wporg_user_by_github( $pr_data->user->name, 'ID' ); 92 } 93 67 94 $wpdb->update( 68 95 'trac_github_prs', … … 70 97 'data' => json_encode( $pr_data ), 71 98 'last_checked' => gmdate( 'Y-m-d H:i:s' ), 99 'author' => $data->author, 72 100 ], 73 101 [ … … 98 126 header( 'Cache-Control: max-age=' . $expiry ); 99 127 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() + $expiry ) ); 100 header( 'Content-Type: application/json' );101 header( 'Access-Control-Allow-Origin: *' );102 128 103 129 // Only return the actual PR data needed
Note: See TracChangeset
for help on using the changeset viewer.