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
Add base RemoteSpecsEngine class, add logging for errors in all remote specs #44775
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6243127
Add basic RemoteSpecEngine class, add logging for errors
ilyasfoo 4ddb97a
Changelog
ilyasfoo c39de1a
Fix logic error
ilyasfoo 4b982fa
Add log name
ilyasfoo 31d6e42
Merge remote-tracking branch 'origin/trunk' into fix/44248-add-loggin…
ilyasfoo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
plugins/woocommerce/changelog/fix-44248-add-logging-remote-specs
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,4 @@ | ||
Significance: patch | ||
Type: dev | ||
|
||
Add base RemoteSpecsEngine class, add logging for errors in all remote specs |
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
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
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
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
39 changes: 39 additions & 0 deletions
39
plugins/woocommerce/src/Admin/RemoteSpecs/RemoteSpecsEngine.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,39 @@ | ||
<?php | ||
|
||
namespace Automattic\WooCommerce\Admin\RemoteSpecs; | ||
|
||
/** | ||
* RemoteSpecsEngine class. | ||
*/ | ||
abstract class RemoteSpecsEngine { | ||
/** | ||
* Log errors. | ||
* | ||
* @param array $errors Array of errors from \Throwable interface. | ||
*/ | ||
public static function log_errors( $errors = array() ) { | ||
if ( | ||
true !== defined( 'WP_ENVIRONMENT_TYPE' ) || | ||
! in_array( constant( 'WP_ENVIRONMENT_TYPE' ), array( 'development', 'local' ), true ) | ||
) { | ||
return; | ||
} | ||
$logger = wc_get_logger(); | ||
$error_messages = array(); | ||
|
||
foreach ( $errors as $error ) { | ||
if ( isset( $error ) && method_exists( $error, 'getMessage' ) ) { | ||
$error_messages[] = $error->getMessage(); | ||
} | ||
} | ||
|
||
$logger->error( | ||
'Error while evaluating specs', | ||
array( | ||
'source' => 'remotespecsengine-errors', | ||
'class' => static::class, | ||
'errors' => $error_messages, | ||
), | ||
); | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -7,15 +7,14 @@ | |
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
use Automattic\WooCommerce\Admin\DataSourcePoller; | ||
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\EvaluateSuggestion; | ||
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\PaymentGatewaySuggestionsDataSourcePoller as PaymentGatewaySuggestionsDataSourcePoller; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused imports |
||
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets; | ||
use Automattic\WooCommerce\Admin\RemoteSpecs\RemoteSpecsEngine; | ||
|
||
/** | ||
* WC Pay Promotion engine. | ||
*/ | ||
class Init { | ||
class Init extends RemoteSpecsEngine { | ||
const EXPLAT_VARIATION_PREFIX = 'woocommerce_wc_pay_promotion_payment_methods_table_'; | ||
|
||
/** | ||
|
@@ -131,6 +130,7 @@ public static function get_promotions() { | |
// Unlike payment gateway suggestions, we don't have a non-empty default set of promotions to fall back to. | ||
// So just set the specs transient with expired time to 3 hours. | ||
WCPayPromotionDataSourcePoller::get_instance()->set_specs_transient( array( $locale => $specs ), 3 * HOUR_IN_SECONDS ); | ||
self::log_errors( $results['errors'] ); | ||
} | ||
|
||
return $results['suggestions']; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set to private since this can now produce fatal errors.