Skip to content

Commit

Permalink
[N/A] WP Crontrol / Ending Soon Emails Debugging (#918)
Browse files Browse the repository at this point in the history
* [N/A] Added WP Crontrol Plugin (Not Activated)

* [N/A] Debug Logging

* [N/A] Additional Auction Debug info
  • Loading branch information
bd-viget authored Apr 18, 2024
1 parent e06ed52 commit 8dd3de4
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 57 deletions.
1 change: 1 addition & 0 deletions client-mu-plugins/goodbids/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"wpackagist-plugin/woocommerce": "^8.6",
"wpackagist-plugin/woocommerce-gateway-stripe": "^8.2",
"wpackagist-plugin/woocommerce-services": "^2.5",
"wpackagist-plugin/wp-crontrol": "^1.16",
"wpackagist-plugin/zapier": "^1.0",
"wpengine/advanced-custom-fields-pro": "^6.2"
},
Expand Down
20 changes: 19 additions & 1 deletion client-mu-plugins/goodbids/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions client-mu-plugins/goodbids/src/assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,10 @@ tr.separator td {
table.fixed {
position: static !important;
}

.gb-auction-metrics p,
.gb-auction-debug-info p {
display: flex;
gap: 1rem;
margin-bottom: 0.15rem;
}
7 changes: 7 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public function info_meta_box(): void {

// Display the Auction Metrics.
goodbids()->load_view( 'admin/auctions/metrics.php', compact( 'auction_id' ) );

if ( is_super_admin() ) {
echo '<hr style="margin-left:-1.5rem;width:calc(100% + 3rem);" />';

// Display the Auction Debug Info.
goodbids()->load_view( 'admin/auctions/debug.php', compact( 'auction_id' ) );
}
}

/**
Expand Down
16 changes: 8 additions & 8 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Auctions {
const AUCTION_CLOSE_META_KEY = '_auction_close';

/**
* @since 1.0.0
* @since 1.0.1
* @var string
*/
const CRON_AUCTION_ENDING_SOON_CHECK_HOOK = 'goodbids_auction_ending_soon_event';
Expand Down Expand Up @@ -399,7 +399,7 @@ public function get_unclaimed_reward_auction_emails(): array {
/**
* Gets auctions ending in specific timeframe
*
* @since 1.0.0
* @since 1.0.1
*
* @return array
*/
Expand All @@ -408,21 +408,21 @@ public function get_ending_soon(): array {
[
'meta_query' => [
[
'key' => self::AUCTION_CLOSED_META_KEY,
'value' => '0',
'compare' => '=',
'key' => self::AUCTION_CLOSED_META_KEY,
'value' => '0',
],
[
'key' => self::AUCTION_STARTED_META_KEY,
'value' => '1',
'compare' => '=',
'key' => self::AUCTION_STARTED_META_KEY,
'value' => '1',
],
],
]
);

$ending_soon = [];

Log::debug( 'Checking ' . count( $live_auctions->posts ) . ' Auctions if they are ending soon' );

foreach ( $live_auctions->posts as $auction_id ) {
$auction = $this->get( $auction_id );
if ( $auction->is_ending_soon() ) {
Expand Down
61 changes: 33 additions & 28 deletions client-mu-plugins/goodbids/src/classes/Auctions/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,38 @@ class Cron {
* @since 1.0.0
*/
public function __construct() {
// Disable Auctions on Main Site.
// Disable Cron on Main Site.
if ( is_main_site() ) {
return;
}

// Set up Cron Schedules.
$this->cron_intervals['30sec'] = [
'interval' => 30,
'name' => '30sec',
'display' => __( 'Every 30 Seconds', 'goodbids' ),
];
$this->cron_intervals['every_minute'] = [
'interval' => MINUTE_IN_SECONDS,
'name' => 'every_minute',
'display' => __( 'Every Minute', 'goodbids' ),
];
$this->cron_intervals['30min'] = [
'interval' => 30 * MINUTE_IN_SECONDS,
'name' => '30min',
'display' => __( 'Once Every 30 Minutes', 'goodbids' ),
];
$this->cron_intervals['hourly'] = [
'interval' => HOUR_IN_SECONDS,
'name' => 'hourly',
'display' => __( 'Once Hourly', 'goodbids' ),
];
$this->cron_intervals['daily'] = [
'interval' => DAY_IN_SECONDS,
'name' => 'daily',
'display' => __( 'Once Daily', 'goodbids' ),
$this->cron_intervals = [
'30sec' => [
'interval' => 30,
'name' => '30sec',
'display' => __( 'Every 30 Seconds', 'goodbids' ),
],
'every_minute' => [
'interval' => MINUTE_IN_SECONDS,
'name' => 'every_minute',
'display' => __( 'Every Minute', 'goodbids' ),
],
'30min' => [
'interval' => 30 * MINUTE_IN_SECONDS,
'name' => '30min',
'display' => __( 'Once Every 30 Minutes', 'goodbids' ),
],
'hourly' => [
'interval' => HOUR_IN_SECONDS,
'name' => 'hourly',
'display' => __( 'Once Hourly', 'goodbids' ),
],
'daily' => [
'interval' => DAY_IN_SECONDS,
'name' => 'daily',
'display' => __( 'Once Daily', 'goodbids' ),
],
];

// Attempt to trigger events for opened/closed auctions.
Expand All @@ -90,14 +92,14 @@ public function __construct() {
// Schedule a cron job to remind users to claim their rewards.
$this->schedule_reward_claim_reminder();

// Schedule a cron job to check for auctions ending soon.
$this->schedule_auction_ending_soon_check();

// Use cron action to start auctions.
$this->cron_check_for_starting_auctions();

// Use cron action to close auctions.
$this->cron_check_for_closing_auctions();

// Schedule a cron job to check for auctions ending soon.
$this->schedule_auction_ending_soon_check();
}

/**
Expand Down Expand Up @@ -217,9 +219,12 @@ private function schedule_auction_ending_soon_check(): void {
'init',
function (): void {
if ( wp_next_scheduled( Auctions::CRON_AUCTION_ENDING_SOON_CHECK_HOOK ) ) {
Log::debug( 'Auction Ending Soon Cron Check already scheduled' );
return;
}

Log::debug( 'Scheduling Auction Ending Soon Cron Check' );

// Event is not scheduled, so schedule it.
wp_schedule_event(
strtotime( current_time( 'mysql' ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function load_email_classes(): void {
$this->email_classes = [
'AuctionClosed' => new AuctionClosed(),
'AuctionFreeBidUsed' => new AuctionFreeBidUsed(),
'AuctionIsEndingSoon' => new AuctionIsEndingSoon(),
'AuctionIsEndingSoon' => new AuctionIsEndingSoon(),
'AuctionIsLive' => new AuctionIsLive(),
'AuctionIsLiveAdmin' => new AuctionIsLiveAdmin(),
'AuctionOutbid' => new AuctionOutbid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
/**
* Auction is Ending Soon: Email the Watchers when an Auction is close to closing.
*
* @since 1.0.0
* @since 1.0.1
* @package GoodBids
*/

namespace GoodBids\Plugins\WooCommerce\Emails;

use GoodBids\Auctions\Auctions as Auctions;
use GoodBids\Auctions\Auctions;
use GoodBids\Utilities\Log;

defined( 'ABSPATH' ) || exit;

/**
* Auction Ending Soon Email
*
* @since 1.0.0
* @since 1.0.1
* @extends Email
*/
class AuctionIsEndingSoon extends Email {

/**
* Set the unique Email ID
*
* @since 1.0.0
* @since 1.0.1
* @var string
*/
public $id = 'goodbids_auction_ending_soon';

/**
* Set email defaults
*
* @since 1.0.0
* @since 1.0.1
*
* @return void
*/
Expand All @@ -49,21 +50,26 @@ public function __construct() {
}

/**
* Trigger this email when an Auction is within 4 hours of closing
* Trigger this email when an Auction is within 1/3 of the bidding window closing.
*
* @since 1.0.0
* @since 1.0.1
*
* @return void
*/
private function cron_check_for_auctions_ending_soon(): void {
Log::debug( 'Init: Check for Auctions Ending Soon' );
add_action(
Auctions::CRON_AUCTION_ENDING_SOON_CHECK_HOOK,
function (): void {
Log::debug( 'Checking for Auctions Ending Soon' );
$auctions = goodbids()->auctions->get_ending_soon();
if ( ! $auctions ) {
Log::debug( 'No Auctions Ending Soon found' );
return;
}

Log::debug( 'Found ' . count( $auctions ) . ' Auctions Ending Soon' );

foreach ( $auctions as $auction_id ) {
$auction = goodbids()->auctions->get( $auction_id );
$this->send_to_bidders( $auction );
Expand All @@ -76,7 +82,7 @@ function (): void {
/**
* Get email subject.
*
* @since 1.0.0
* @since 1.0.1
* @return string
*/
public function get_default_subject(): string {
Expand All @@ -91,7 +97,7 @@ public function get_default_subject(): string {
/**
* Get email heading.
*
* @since 1.0.0
* @since 1.0.1
* @return string
*/
public function get_default_heading(): string {
Expand All @@ -101,7 +107,7 @@ public function get_default_heading(): string {
/**
* Get button text
*
* @since 1.0.0
* @since 1.0.1
* @return string
*/
public function get_default_button_text(): string {
Expand All @@ -111,7 +117,7 @@ public function get_default_button_text(): string {
/**
* Set Button URL
*
* @since 1.0.0
* @since 1.0.1
*
* @return string
*/
Expand Down
30 changes: 30 additions & 0 deletions client-mu-plugins/goodbids/views/admin/auctions/debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Auction Debug Info Meta Box Content
*
* @global int $auction_id
*
* @since 1.0.1
* @package GoodBids
*/

?>
<div class="gb-auction-debug-info">
<h3><?php esc_html_e( 'Debug Info', 'goodbids' ); ?></h3>

<?php
$auction = goodbids()->auctions->get( $auction_id );

printf(
'<p><strong>%s</strong><span>%s</span></p>',
esc_html__( 'Start Triggered', 'goodbids' ),
esc_html( $auction->start_triggered() ? __( 'Yes', 'goodbids' ) : __( 'No', 'goodbids' ) )
);

printf(
'<p><strong>%s</strong><span>%s</span></p>',
esc_html__( 'End Triggered', 'goodbids' ),
esc_html( $auction->end_triggered() ? __( 'Yes', 'goodbids' ) : __( 'No', 'goodbids' ) )
);
?>
</div>
7 changes: 5 additions & 2 deletions client-mu-plugins/goodbids/views/admin/auctions/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@
);

if ( $reward_product ) {
$reward_title = $reward_product->get_name();
$reward_title = wp_trim_words( $reward_title, 10, '...' );

if ( in_array( $auction->get_status(), [ Auction::STATUS_LIVE, Auction::STATUS_CLOSED ] ) && ! is_super_admin() ) {
printf(
'<p><strong>%s</strong><br>%s</p>',
esc_html__( 'Reward Product', 'goodbids' ),
esc_html( $reward_product->get_name() )
esc_html( $reward_title )
);
} else {
printf(
'<p><strong>%s</strong><br>%s (<a href="%s">%s</a>)</p>',
esc_html__( 'Reward Product', 'goodbids' ),
esc_html( $reward_product->get_name() ),
esc_html( $reward_title ),
esc_html( goodbids()->auctions->wizard->get_wizard_url( Wizard::EDIT_MODE_OPTION, $auction_id, $reward_product->get_id() ) ),
esc_html__( 'Edit', 'goodbids' )
);
Expand Down
Loading

0 comments on commit 8dd3de4

Please sign in to comment.