2013-08-07 08:38:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class TracTickets {
|
|
|
|
/**
|
2017-08-22 13:51:11 +02:00
|
|
|
* When open tickets for a Trac installation is requested, the results are stored here.
|
2013-08-07 08:38:38 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $trac_ticket_cache = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if track ticket #$ticket_id is resolved
|
|
|
|
*
|
|
|
|
* @return bool|null true if the ticket is resolved, false if not resolved, null on error
|
|
|
|
*/
|
2019-07-01 10:00:12 +02:00
|
|
|
public static function isTracTicketClosed( $trac_url, $ticket_id ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
2014-02-12 21:39:21 +01:00
|
|
|
if ( ! extension_loaded( 'openssl' ) ) {
|
2017-12-01 00:09:33 +01:00
|
|
|
$trac_url = preg_replace( '/^https:/', 'http:', $trac_url );
|
2014-02-12 21:39:21 +01:00
|
|
|
}
|
|
|
|
|
2013-08-07 08:38:38 +02:00
|
|
|
if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) {
|
|
|
|
// In case you're running the tests offline, keep track of open tickets.
|
2017-12-01 00:09:33 +01:00
|
|
|
$file = DIR_TESTDATA . '/.trac-ticket-cache.' . str_replace( array( 'http://', 'https://', '/' ), array( '', '', '-' ), rtrim( $trac_url, '/' ) );
|
2013-08-07 08:38:38 +02:00
|
|
|
$tickets = @file_get_contents( $trac_url . '/query?status=%21closed&format=csv&col=id' );
|
|
|
|
// Check if our HTTP request failed.
|
|
|
|
if ( false === $tickets ) {
|
|
|
|
if ( file_exists( $file ) ) {
|
|
|
|
register_shutdown_function( array( 'TracTickets', 'usingLocalCache' ) );
|
|
|
|
$tickets = file_get_contents( $file );
|
|
|
|
} else {
|
|
|
|
register_shutdown_function( array( 'TracTickets', 'forcingKnownBugs' ) );
|
|
|
|
self::$trac_ticket_cache[ $trac_url ] = array();
|
|
|
|
return true; // Assume the ticket is closed, which means it gets run.
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-29 01:43:23 +01:00
|
|
|
$tickets = substr( $tickets, 2 ); // Remove 'id' column header.
|
2013-08-07 08:38:38 +02:00
|
|
|
$tickets = trim( $tickets );
|
|
|
|
file_put_contents( $file, $tickets );
|
|
|
|
}
|
2017-12-01 00:09:33 +01:00
|
|
|
$tickets = explode( "\r\n", $tickets );
|
2013-08-07 08:38:38 +02:00
|
|
|
self::$trac_ticket_cache[ $trac_url ] = $tickets;
|
|
|
|
}
|
|
|
|
|
2019-07-08 02:55:20 +02:00
|
|
|
return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ], true );
|
2013-08-07 08:38:38 +02:00
|
|
|
}
|
|
|
|
|
2019-07-01 10:00:12 +02:00
|
|
|
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
2013-08-07 08:38:38 +02:00
|
|
|
public static function usingLocalCache() {
|
|
|
|
echo PHP_EOL . "\x1b[0m\x1b[30;43m\x1b[2K";
|
2020-02-01 22:36:44 +01:00
|
|
|
echo 'Info: Trac was inaccessible, so a local ticket status cache was used.' . PHP_EOL;
|
2013-08-07 08:38:38 +02:00
|
|
|
echo "\x1b[0m\x1b[2K";
|
|
|
|
}
|
|
|
|
|
2019-07-01 10:00:12 +02:00
|
|
|
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
2013-08-07 08:38:38 +02:00
|
|
|
public static function forcingKnownBugs() {
|
|
|
|
echo PHP_EOL . "\x1b[0m\x1b[37;41m\x1b[2K";
|
I18N: Remove the "Error:" prefix from error messages.
For a number of years, most of the WordPress error messages have been prefixed with "Error:". However, these messages appear in a context where it's already clear an error occurred. Whether it's an error, a warning, or any other classification, that's not so relevant for users. The content of the message is the relevant part. The "Error:" prefix doesn't add great value while it does add unnecessary complexity for the message readability.
Also, revises some of these messages to improve clarity and removes HTML from translatable strings.
Props garrett-eclipse, ramiy, SergeyBiryukov, afercia, sabernhardt, quadthemes, audrasjb.
See #47003, #43037, #42945, #15887.
Fixes #47656.
git-svn-id: https://develop.svn.wordpress.org/trunk@48059 602fd350-edb4-49c9-b593-d223f7449a82
2020-06-16 17:33:37 +02:00
|
|
|
echo "Trac was inaccessible, so known bugs weren't able to be skipped." . PHP_EOL;
|
2013-08-07 08:38:38 +02:00
|
|
|
echo "\x1b[0m\x1b[2K";
|
|
|
|
}
|
|
|
|
}
|