Move src/Schedulers/* to src-internal/Admin/Schedulers (https://github.com/woocommerce/woocommerce-admin/pull/8316)

* Add psr-4 for the internal classes -- this is a temp. changes. We should remove it once we completely merge to the core

* Register class aliases

* Move WcPayPromotion classes to the internal

* Ignore namespace PHP CS issue

* Make features/WcPayPromotion internal

* Added src-internal directory for Automattic\WooCommerce\Internal\Admin namespace

* Moved src/Features/WcPayPromotion to src-internal/Admin/WcPayPromotion

* Add phpcs rules for src-internal

* Remove phpcs:ignoreFile

* Update letter case to make it PSR4 compatible

* Fix letter cases

* Move the alias array into the function

* Rename WcPayPromotion to WCPayPromotion (letter case update)

* Include src-internal

* Update letter case

* Make src/Schedulers/* internal, except the SchedulerTraits

* Add @internal comment tag

* Clean up incorrect import

* Remove unused import
This commit is contained in:
Moon 2022-02-17 10:48:31 -08:00 committed by GitHub
parent ce0f73aa9b
commit aa554fb1e3
12 changed files with 58 additions and 22 deletions

View File

@ -3,13 +3,12 @@
* Customer syncing related functions and actions. * Customer syncing related functions and actions.
*/ */
namespace Automattic\WooCommerce\Admin\Schedulers; namespace Automattic\WooCommerce\Internal\Admin\Schedulers;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\API\Reports\Cache as ReportsCache; use \Automattic\WooCommerce\Admin\API\Reports\Cache as ReportsCache;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
use \Automattic\WooCommerce\Admin\Schedulers\OrdersScheduler;
/** /**
* CustomersScheduler Class. * CustomersScheduler Class.
@ -24,6 +23,8 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Attach customer lookup update hooks. * Attach customer lookup update hooks.
*
* @internal
*/ */
public static function init() { public static function init() {
add_action( 'woocommerce_new_customer', array( __CLASS__, 'schedule_import' ) ); add_action( 'woocommerce_new_customer', array( __CLASS__, 'schedule_import' ) );
@ -40,6 +41,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Add customer dependencies. * Add customer dependencies.
* *
* @internal
* @return array * @return array
*/ */
public static function get_dependencies() { public static function get_dependencies() {
@ -53,6 +55,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Get the customer IDs and total count that need to be synced. * Get the customer IDs and total count that need to be synced.
* *
* @internal
* @param int $limit Number of records to retrieve. * @param int $limit Number of records to retrieve.
* @param int $page Page number. * @param int $page Page number.
* @param int|bool $days Number of days prior to current date to limit search results. * @param int|bool $days Number of days prior to current date to limit search results.
@ -94,6 +97,7 @@ class CustomersScheduler extends ImportScheduler {
* *
* Meant to be hooked into 'pre_user_query' action. * Meant to be hooked into 'pre_user_query' action.
* *
* @internal
* @param WP_User_Query $wp_user_query WP_User_Query to modify. * @param WP_User_Query $wp_user_query WP_User_Query to modify.
*/ */
public static function exclude_existing_customers_from_query( $wp_user_query ) { public static function exclude_existing_customers_from_query( $wp_user_query ) {
@ -108,6 +112,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Get total number of rows imported. * Get total number of rows imported.
* *
* @internal
* @return int * @return int
*/ */
public static function get_total_imported() { public static function get_total_imported() {
@ -119,6 +124,7 @@ class CustomersScheduler extends ImportScheduler {
* Get all available scheduling actions. * Get all available scheduling actions.
* Used to determine action hook names and clear events. * Used to determine action hook names and clear events.
* *
* @internal
* @return array * @return array
*/ */
public static function get_scheduler_actions() { public static function get_scheduler_actions() {
@ -131,6 +137,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Schedule import. * Schedule import.
* *
* @internal
* @param int $user_id User ID. * @param int $user_id User ID.
* @return void * @return void
*/ */
@ -142,6 +149,7 @@ class CustomersScheduler extends ImportScheduler {
* Schedule an import if the "last active" meta value was changed. * Schedule an import if the "last active" meta value was changed.
* Function expects to be hooked into the `updated_user_meta` action. * Function expects to be hooked into the `updated_user_meta` action.
* *
* @internal
* @param int $meta_id ID of updated metadata entry. * @param int $meta_id ID of updated metadata entry.
* @param int $user_id ID of the user being updated. * @param int $user_id ID of the user being updated.
* @param string $meta_key Meta key being updated. * @param string $meta_key Meta key being updated.
@ -155,6 +163,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Schedule an action to anonymize a single Order. * Schedule an action to anonymize a single Order.
* *
* @internal
* @param WC_Order $order Order object. * @param WC_Order $order Order object.
* @return void * @return void
*/ */
@ -168,6 +177,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Schedule an action to delete a single User. * Schedule an action to delete a single User.
* *
* @internal
* @param int $user_id User ID. * @param int $user_id User ID.
* @return void * @return void
*/ */
@ -181,6 +191,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Imports a single customer. * Imports a single customer.
* *
* @internal
* @param int $user_id User ID. * @param int $user_id User ID.
* @return void * @return void
*/ */
@ -191,6 +202,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Delete a batch of customers. * Delete a batch of customers.
* *
* @internal
* @param int $batch_size Number of items to delete. * @param int $batch_size Number of items to delete.
* @return void * @return void
*/ */
@ -212,6 +224,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Anonymize the customer data for a single order. * Anonymize the customer data for a single order.
* *
* @internal
* @param int $order_id Order id. * @param int $order_id Order id.
* @return void * @return void
*/ */
@ -264,6 +277,7 @@ class CustomersScheduler extends ImportScheduler {
/** /**
* Delete the customer data for a single user. * Delete the customer data for a single user.
* *
* @internal
* @param int $user_id User ID. * @param int $user_id User ID.
* @return void * @return void
*/ */

View File

@ -3,12 +3,13 @@
* Import related abstract functions. * Import related abstract functions.
*/ */
namespace Automattic\WooCommerce\Admin\Schedulers; namespace Automattic\WooCommerce\Internal\Admin\Schedulers;
interface ImportInterface { interface ImportInterface {
/** /**
* Get items based on query and return IDs along with total available. * Get items based on query and return IDs along with total available.
* *
* @internal
* @param int $limit Number of records to retrieve. * @param int $limit Number of records to retrieve.
* @param int $page Page number. * @param int $page Page number.
* @param int|bool $days Number of days prior to current date to limit search results. * @param int|bool $days Number of days prior to current date to limit search results.
@ -19,6 +20,7 @@ interface ImportInterface {
/** /**
* Get total number of items already imported. * Get total number of items already imported.
* *
* @internal
* @return null * @return null
*/ */
public static function get_total_imported(); public static function get_total_imported();

View File

@ -3,7 +3,7 @@
* Import related functions and actions. * Import related functions and actions.
*/ */
namespace Automattic\WooCommerce\Admin\Schedulers; namespace Automattic\WooCommerce\Internal\Admin\Schedulers;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
@ -29,6 +29,7 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Returns true if an import is in progress. * Returns true if an import is in progress.
* *
* @internal
* @return bool * @return bool
*/ */
public static function is_importing() { public static function is_importing() {
@ -58,6 +59,7 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Get batch sizes. * Get batch sizes.
* *
* @internal
* @retun array * @retun array
*/ */
public static function get_batch_sizes() { public static function get_batch_sizes() {
@ -76,6 +78,7 @@ abstract class ImportScheduler implements ImportInterface {
* Get all available scheduling actions. * Get all available scheduling actions.
* Used to determine action hook names and clear events. * Used to determine action hook names and clear events.
* *
* @internal
* @return array * @return array
*/ */
public static function get_scheduler_actions() { public static function get_scheduler_actions() {
@ -91,6 +94,7 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Queue the imports into multiple batches. * Queue the imports into multiple batches.
* *
* @internal
* @param integer|boolean $days Number of days to import. * @param integer|boolean $days Number of days to import.
* @param boolean $skip_existing Skip exisiting records. * @param boolean $skip_existing Skip exisiting records.
*/ */
@ -110,6 +114,7 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Imports a batch of items to update. * Imports a batch of items to update.
* *
* @internal
* @param int $batch_number Batch number to import (essentially a query page number). * @param int $batch_number Batch number to import (essentially a query page number).
* @param int|bool $days Number of days to import. * @param int|bool $days Number of days to import.
* @param bool $skip_existing Skip exisiting records. * @param bool $skip_existing Skip exisiting records.
@ -146,6 +151,8 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Queue item deletion in batches. * Queue item deletion in batches.
*
* @internal
*/ */
public static function delete_batch_init() { public static function delete_batch_init() {
global $wpdb; global $wpdb;
@ -164,6 +171,7 @@ abstract class ImportScheduler implements ImportInterface {
/** /**
* Delete a batch by passing the count to be deleted to the child delete method. * Delete a batch by passing the count to be deleted to the child delete method.
* *
* @internal
* @return void * @return void
*/ */
public static function delete_batch() { public static function delete_batch() {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Automattic\WooCommerce\Admin\Schedulers; namespace Automattic\WooCommerce\Internal\Admin\Schedulers;
/** /**
* Class MailchimpScheduler * Class MailchimpScheduler
@ -26,6 +26,7 @@ class MailchimpScheduler {
/** /**
* MailchimpScheduler constructor. * MailchimpScheduler constructor.
* *
* @internal
* @param \WC_Logger_Interface|null $logger Logger instance. * @param \WC_Logger_Interface|null $logger Logger instance.
*/ */
public function __construct( \WC_Logger_Interface $logger = null ) { public function __construct( \WC_Logger_Interface $logger = null ) {
@ -37,6 +38,8 @@ class MailchimpScheduler {
/** /**
* Attempt to subscribe store_email to MailChimp. * Attempt to subscribe store_email to MailChimp.
*
* @internal
*/ */
public function run() { public function run() {
// Abort if we've already subscribed to MailChimp. // Abort if we've already subscribed to MailChimp.
@ -82,6 +85,7 @@ class MailchimpScheduler {
/** /**
* Make an HTTP request to the API. * Make an HTTP request to the API.
* *
* @internal
* @param string $store_email Email address to subscribe. * @param string $store_email Email address to subscribe.
* *
* @return mixed * @return mixed

View File

@ -3,7 +3,7 @@
* Order syncing related functions and actions. * Order syncing related functions and actions.
*/ */
namespace Automattic\WooCommerce\Admin\Schedulers; namespace Automattic\WooCommerce\Internal\Admin\Schedulers;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
@ -13,7 +13,6 @@ use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsData
use \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore as TaxesDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore as TaxesDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Cache as ReportsCache; use \Automattic\WooCommerce\Admin\API\Reports\Cache as ReportsCache;
use \Automattic\WooCommerce\Admin\Schedulers\CustomersScheduler;
/** /**
* OrdersScheduler Class. * OrdersScheduler Class.
@ -28,6 +27,8 @@ class OrdersScheduler extends ImportScheduler {
/** /**
* Attach order lookup update hooks. * Attach order lookup update hooks.
*
* @internal
*/ */
public static function init() { public static function init() {
// Activate WC_Order extension. // Activate WC_Order extension.
@ -49,17 +50,19 @@ class OrdersScheduler extends ImportScheduler {
/** /**
* Add customer dependencies. * Add customer dependencies.
* *
* @internal
* @return array * @return array
*/ */
public static function get_dependencies() { public static function get_dependencies() {
return array( return array(
'import_batch_init' => CustomersScheduler::get_action( 'import_batch_init' ), 'import_batch_init' => \Automattic\WooCommerce\Internal\Admin\Schedulers\CustomersScheduler::get_action( 'import_batch_init' ),
); );
} }
/** /**
* Get the order/refund IDs and total count that need to be synced. * Get the order/refund IDs and total count that need to be synced.
* *
* @internal
* @param int $limit Number of records to retrieve. * @param int $limit Number of records to retrieve.
* @param int $page Page number. * @param int $page Page number.
* @param int|bool $days Number of days prior to current date to limit search results. * @param int|bool $days Number of days prior to current date to limit search results.
@ -111,6 +114,8 @@ class OrdersScheduler extends ImportScheduler {
/** /**
* Get total number of rows imported. * Get total number of rows imported.
*
* @internal
*/ */
public static function get_total_imported() { public static function get_total_imported() {
global $wpdb; global $wpdb;
@ -120,6 +125,7 @@ class OrdersScheduler extends ImportScheduler {
/** /**
* Schedule this import if the post is an order or refund. * Schedule this import if the post is an order or refund.
* *
* @internal
* @param int $post_id Post ID. * @param int $post_id Post ID.
*/ */
public static function possibly_schedule_import( $post_id ) { public static function possibly_schedule_import( $post_id ) {
@ -134,6 +140,7 @@ class OrdersScheduler extends ImportScheduler {
* Imports a single order or refund to update lookup tables for. * Imports a single order or refund to update lookup tables for.
* If an error is encountered in one of the updates, a retry action is scheduled. * If an error is encountered in one of the updates, a retry action is scheduled.
* *
* @internal
* @param int $order_id Order or refund ID. * @param int $order_id Order or refund ID.
* @return void * @return void
*/ */
@ -179,6 +186,7 @@ class OrdersScheduler extends ImportScheduler {
/** /**
* Delete a batch of orders. * Delete a batch of orders.
* *
* @internal
* @param int $batch_size Number of items to delete. * @param int $batch_size Number of items to delete.
* @return void * @return void
*/ */

View File

@ -40,7 +40,7 @@ use \Automattic\WooCommerce\Admin\Notes\PerformanceOnMobile;
use \Automattic\WooCommerce\Admin\Notes\ManageOrdersOnTheGo; use \Automattic\WooCommerce\Admin\Notes\ManageOrdersOnTheGo;
use \Automattic\WooCommerce\Admin\Notes\AddFirstProduct; use \Automattic\WooCommerce\Admin\Notes\AddFirstProduct;
use \Automattic\WooCommerce\Admin\Notes\NavigationNudge; use \Automattic\WooCommerce\Admin\Notes\NavigationNudge;
use Automattic\WooCommerce\Admin\Schedulers\MailchimpScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler;
use \Automattic\WooCommerce\Admin\Notes\CompleteStoreDetails; use \Automattic\WooCommerce\Admin\Notes\CompleteStoreDetails;
use \Automattic\WooCommerce\Admin\Notes\UpdateStoreDetails; use \Automattic\WooCommerce\Admin\Notes\UpdateStoreDetails;
use \Automattic\WooCommerce\Admin\Notes\SetUpAdditionalPaymentTypes; use \Automattic\WooCommerce\Admin\Notes\SetUpAdditionalPaymentTypes;

View File

@ -11,7 +11,7 @@ use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\Admin\WCAdminHelper; use Automattic\WooCommerce\Admin\WCAdminHelper;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Init as OnboardingTasks; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Init as OnboardingTasks;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
use Automattic\WooCommerce\Admin\Schedulers\MailchimpScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler;
/** /**
* Contains backend logic for the onboarding profile and checklist feature. * Contains backend logic for the onboarding profile and checklist feature.

View File

@ -7,9 +7,9 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Schedulers\CustomersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\CustomersScheduler;
use Automattic\WooCommerce\Admin\Schedulers\OrdersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\OrdersScheduler;
use Automattic\WooCommerce\Admin\Schedulers\ImportScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\ImportScheduler;
/** /**
* ReportsSync Class. * ReportsSync Class.
@ -45,8 +45,8 @@ class ReportsSync {
); );
foreach ( $schedulers as $scheduler ) { foreach ( $schedulers as $scheduler ) {
if ( ! is_subclass_of( $scheduler, 'Automattic\WooCommerce\Admin\Schedulers\ImportScheduler' ) ) { if ( ! is_subclass_of( $scheduler, 'Automattic\WooCommerce\Internal\Admin\Schedulers\ImportScheduler' ) ) {
throw new \Exception( __( 'Report sync schedulers should be derived from the Automattic\WooCommerce\Admin\Schedulers\ImportScheduler class.', 'woocommerce-admin' ) ); throw new \Exception( __( 'Report sync schedulers should be derived from the Automattic\WooCommerce\Internal\Admin\Schedulers\ImportScheduler class.', 'woocommerce-admin' ) );
} }
} }

View File

@ -6,8 +6,8 @@
* @since 3.5.0 * @since 3.5.0
*/ */
use Automattic\WooCommerce\Admin\Schedulers\CustomersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\CustomersScheduler;
use Automattic\WooCommerce\Admin\Schedulers\OrdersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\OrdersScheduler;
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/** /**

View File

@ -7,7 +7,7 @@
use \Automattic\WooCommerce\Admin\API\OnboardingProfile; use \Automattic\WooCommerce\Admin\API\OnboardingProfile;
use Automattic\WooCommerce\Admin\Features\Onboarding; use Automattic\WooCommerce\Admin\Features\Onboarding;
use Automattic\WooCommerce\Admin\Schedulers\MailchimpScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler;
/** /**
* WC Tests API Onboarding Profile * WC Tests API Onboarding Profile

View File

@ -6,8 +6,8 @@
* @since 3.5.0 * @since 3.5.0
*/ */
use Automattic\WooCommerce\Admin\Schedulers\CustomersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\CustomersScheduler;
use Automattic\WooCommerce\Admin\Schedulers\OrdersScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\OrdersScheduler;
/** /**
* Reports Generation Batch Queue Test Class * Reports Generation Batch Queue Test Class

View File

@ -6,14 +6,14 @@
*/ */
use Automattic\WooCommerce\Admin\Features\Onboarding; use Automattic\WooCommerce\Admin\Features\Onboarding;
use Automattic\WooCommerce\Admin\Schedulers\MailchimpScheduler; use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler;
/** /**
* Class WC_Tests_Mailchimp_Scheduler * Class WC_Tests_Mailchimp_Scheduler
*/ */
class WC_Tests_Mailchimp_Scheduler extends WC_Unit_Test_Case { class WC_Tests_Mailchimp_Scheduler extends WC_Unit_Test_Case {
/** /**
* @var MailchimpScheduler MailchimpScheduler instance to test * @var \Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler MailchimpScheduler instance to test
*/ */
private $instance; private $instance;