-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from Automattic/alpha
Release Oct 08
- Loading branch information
Showing
40 changed files
with
2,300 additions
and
611 deletions.
There are no files selected for viewing
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
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
75 changes: 75 additions & 0 deletions
75
includes/cli/backfillers/class-membership-plan-updated.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,75 @@ | ||
<?php | ||
/** | ||
* Data Backfiller for membership_plan_updated events. | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Backfillers; | ||
|
||
use Newspack_Network\Data_Backfill; | ||
use Newspack_Network\Woocommerce_Memberships\Admin as Memberships_Admin; | ||
use Newspack_Network\Woocommerce_Memberships\Events as Memberships_Events; | ||
use WP_Cli; | ||
use WC_Memberships_Membership_Plan; | ||
|
||
/** | ||
* Backfiller class. | ||
*/ | ||
class Membership_Plan_Updated extends Abstract_Backfiller { | ||
|
||
/** | ||
* Gets the output line about the processed item being processed in verbose mode. | ||
* | ||
* @param \Newspack_Network\Incoming_Events\Abstract_Incoming_Event $event The event. | ||
* | ||
* @return string | ||
*/ | ||
protected function get_processed_item_output( $event ) { | ||
return sprintf( 'Membership Plan #%d', $event->get_id() ); | ||
} | ||
|
||
/** | ||
* Gets the events to be processed | ||
* | ||
* @return \Newspack_Network\Incoming_Events\Abstract_Incoming_Event[] $events An array of events. | ||
*/ | ||
public function get_events() { | ||
|
||
if ( ! class_exists( 'WC_Memberships_Membership_Plan' ) ) { | ||
return []; | ||
} | ||
|
||
// Get all memberships created or updated between $start and $end. | ||
$membership_plans = get_posts( | ||
[ | ||
'post_type' => Memberships_Admin::MEMBERSHIP_PLANS_CPT, | ||
'post_status' => 'any', | ||
'numberposts' => -1, | ||
'date_query' => [ | ||
'column' => 'post_modified_gmt', | ||
'after' => $this->start, | ||
'before' => $this->end, | ||
'inclusive' => true, | ||
], | ||
] | ||
); | ||
|
||
$this->maybe_initialize_progress_bar( 'Processing membership plans', count( $membership_plans ) ); | ||
|
||
$events = []; | ||
WP_CLI::line( '' ); | ||
WP_CLI::line( sprintf( 'Found %s membership plan(s) eligible for sync.', count( $membership_plans ) ) ); | ||
WP_CLI::line( '' ); | ||
|
||
foreach ( $membership_plans as $plan ) { | ||
$membership_data = Memberships_Events::membership_plan_updated( $plan->ID ); | ||
|
||
$timestamp = strtotime( $plan->post_modified_gmt ); | ||
|
||
$events[] = new \Newspack_Network\Incoming_Events\Membership_Plan_Updated( get_bloginfo( 'url' ), $membership_data, $timestamp ); | ||
} | ||
|
||
return $events; | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
/** | ||
* Data Backfiller for order_changed events. | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Backfillers; | ||
|
||
use Newspack_Network\Woocommerce\Events as Woo_Listeners; | ||
|
||
/** | ||
* Backfiller class. | ||
*/ | ||
class Order_Changed extends Abstract_Backfiller { | ||
|
||
/** | ||
* Gets the output line about the processed item being processed in verbose mode. | ||
* | ||
* @param \Newspack_Network\Incoming_Events\Abstract_Incoming_Event $event The event. | ||
* | ||
* @return string | ||
*/ | ||
protected function get_processed_item_output( $event ) { | ||
return sprintf( 'Order #%d with status %s.', $event->get_id(), $event->get_status_after() ); | ||
} | ||
|
||
/** | ||
* Gets the events to be processed | ||
* | ||
* @return \Newspack_Network\Incoming_Events\Abstract_Incoming_Event[] $events An array of events. | ||
*/ | ||
public function get_events() { | ||
$params = [ | ||
'limit' => -1, | ||
]; | ||
|
||
if ( $this->start || $this->end ) { | ||
if ( ! $this->end ) { | ||
$params['date_created'] = '>=' . $this->start; | ||
} elseif ( ! $this->start ) { | ||
$params['date_created'] = '<=' . $this->end; | ||
} else { | ||
$params['date_created'] = $this->start . '...' . $this->end; | ||
} | ||
} | ||
|
||
$orders = wc_get_orders( $params ); | ||
|
||
$this->maybe_initialize_progress_bar( 'Processing orders', count( $orders ) ); | ||
|
||
$events = []; | ||
|
||
foreach ( $orders as $order ) { | ||
|
||
$order_data = Woo_Listeners::item_changed( $order->get_id(), '', $order->get_status(), $order ); | ||
|
||
$timestamp = strtotime( $order->get_date_created() ); | ||
|
||
$event = new \Newspack_Network\Incoming_Events\Order_Changed( get_bloginfo( 'url' ), $order_data, $timestamp ); | ||
|
||
$events[] = $event; | ||
} | ||
|
||
return $events; | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
/** | ||
* Data Backfiller for subscription_changed events. | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Backfillers; | ||
|
||
use Newspack_Network\Woocommerce\Events as Woo_Listeners; | ||
|
||
/** | ||
* Backfiller class. | ||
*/ | ||
class Subscription_Changed extends Abstract_Backfiller { | ||
|
||
/** | ||
* Gets the output line about the processed item being processed in verbose mode. | ||
* | ||
* @param \Newspack_Network\Incoming_Events\Abstract_Incoming_Event $event The event. | ||
* | ||
* @return string | ||
*/ | ||
protected function get_processed_item_output( $event ) { | ||
return sprintf( 'Subscription #%d with status %s.', $event->get_id(), $event->get_status_after() ); | ||
} | ||
|
||
/** | ||
* Gets the events to be processed | ||
* | ||
* @return \Newspack_Network\Incoming_Events\Abstract_Incoming_Event[] $events An array of events. | ||
*/ | ||
public function get_events() { | ||
$params = [ | ||
'subscription_status' => 'any', | ||
'subscriptions_per_page' => -1, | ||
]; | ||
|
||
if ( $this->start || $this->end ) { | ||
$params['meta_query'] = [ 'relation' => 'AND' ]; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | ||
|
||
if ( $this->start ) { | ||
$params['meta_query'][] = [ | ||
'key' => wcs_get_date_meta_key( 'start' ), | ||
'compare' => '>=', | ||
'value' => $this->start, | ||
]; | ||
} | ||
|
||
if ( $this->end ) { | ||
$params['meta_query'][] = [ | ||
'key' => wcs_get_date_meta_key( 'start' ), | ||
'compare' => '<=', | ||
'value' => $this->end, | ||
]; | ||
} | ||
} | ||
|
||
$subscriptions = wcs_get_subscriptions( $params ); | ||
|
||
$this->maybe_initialize_progress_bar( 'Processing subscriptions', count( $subscriptions ) ); | ||
|
||
$events = []; | ||
|
||
foreach ( $subscriptions as $subscription ) { | ||
|
||
$subscription_data = Woo_Listeners::subscription_changed( $subscription->get_id(), '', $subscription->get_status(), $subscription ); | ||
|
||
$timestamp = strtotime( $subscription->get_date_created() ); | ||
|
||
$event = new \Newspack_Network\Incoming_Events\Subscription_Changed( get_bloginfo( 'url' ), $subscription_data, $timestamp ); | ||
|
||
$events[] = $event; | ||
} | ||
|
||
return $events; | ||
} | ||
} |
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
Oops, something went wrong.