installed plugin Easy Digital Downloads version 3.1.0.3

This commit is contained in:
2022-11-27 15:03:07 +00:00
committed by Gitium
parent 555673545b
commit c5dce2cec6
1200 changed files with 238970 additions and 0 deletions

View File

@ -0,0 +1,197 @@
<?php
/**
* 3.0 Data Migration - Base.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Base Class.
*
* @since 3.0
*/
class Base extends \EDD_Batch_Export {
/**
* Orders.
*
* @since 3.0
* @var string
*/
const ORDERS = 'orders';
/**
* Discounts.
*
* @since 3.0
* @var string
*/
const DISCOUNTS = 'discounts';
/**
* Our export type. Used for export-type specific filters/actions.
*
* @since 3.0
* @var string
*/
public $export_type = '';
/**
* Allows for a non-download batch processing to be run.
*
* @since 3.0
* @var bool
*/
public $is_void = true;
/**
* Sets the number of items to pull on each step.
*
* @since 3.0
* @var int
*/
public $per_step = 50;
/**
* Is the upgrade done?
*
* @since 3.0
* @var bool
*/
public $done;
/**
* Message.
*
* @since 3.0
* @var string
*/
public $message;
/**
* Completed message.
*
* @since 3.0
* @var string
*/
public $completed_message;
/**
* Upgrade routine.
*
* @since 3.0
* @var string
*/
public $upgrade;
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
return false;
}
/**
* Process a step.
*
* @since 3.0
*
* @return bool
*/
public function process_step() {
if ( ! $this->can_export() ) {
wp_die(
esc_html__( 'You do not have permission to run this upgrade.', 'easy-digital-downloads' ),
esc_html__( 'Error', 'easy-digital-downloads' ),
array(
'response' => 403,
)
);
}
$had_data = $this->get_data();
if ( $had_data ) {
$this->done = false;
// Save the *next* step to do.
update_option( sprintf( 'edd_v3_migration_%s_step', sanitize_key( $this->upgrade ) ), $this->step + 1 );
return true;
} else {
$this->done = true;
$this->message = $this->completed_message;
edd_set_upgrade_complete( $this->upgrade );
delete_option( sprintf( 'edd_v3_migration_%s_step', sanitize_key( $this->upgrade ) ) );
edd_v30_is_migration_complete();
return false;
}
}
/**
* Set the headers.
*
* @since 3.0
*/
public function headers() {
edd_set_time_limit();
}
/**
* Perform the migration.
*
* @since 3.0
*
* @return void
*/
public function export() {
// Set headers.
$this->headers();
edd_die();
}
/**
* Return the global database interface.
*
* @since 3.0
* @access protected
* @static
*
* @return \wpdb|\stdClass
*/
protected static function get_db() {
return isset( $GLOBALS['wpdb'] )
? $GLOBALS['wpdb']
: new \stdClass();
}
/**
* Set properties specific to the export.
*
* @since 3.0
*
* @param array $request Form data passed into the batch processor.
*/
public function set_properties( $request ) {
}
/**
* Allow for pre-fetching of data for the remainder of the batch processor.
*
* @since 3.0
*/
public function pre_fetch() {
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* 3.0 Data Migration - Customer Addresses.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Customer_Addresses Class.
*
* @since 3.0
*/
class Customer_Addresses extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Customer addresses migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_customer_addresses';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->usermeta}
WHERE meta_key = %s
ORDER BY umeta_id ASC
LIMIT %d, %d",
esc_sql( '_edd_user_address' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
Data_Migrator::customer_addresses( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(umeta_id) AS count FROM {$this->get_db()->usermeta} WHERE meta_key = %s", esc_sql( '_edd_user_address' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* 3.0 Data Migration - Customer Email Addresses.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Customer_Email_Addresses Class.
*
* @since 3.0
*/
class Customer_Email_Addresses extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Customer email addresses migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_customer_email_addresses';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->edd_customermeta}
WHERE meta_key = %s
LIMIT %d, %d",
esc_sql( 'additional_email' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
// Check if email has already been migrated.
if ( ! empty( $result->edd_customer_id ) && $result->meta_value ) {
$number_results = edd_count_customer_email_addresses( array(
'customer_id' => $result->edd_customer_id,
'email' => $result->meta_value
) );
if ( $number_results > 0 ) {
continue;
}
}
Data_Migrator::customer_email_addresses( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(meta_id) AS count FROM {$this->get_db()->edd_customermeta} WHERE meta_key = %s", esc_sql( 'additional_email' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* 3.0 Data Migration - Customer Notes.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
use Carbon\Carbon;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Customer_Notes Class.
*
* @since 3.0
*/
class Customer_Notes extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Customer notes migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_customer_notes';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->edd_customers}
LIMIT %d, %d",
$offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
Data_Migrator::customer_notes( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( "SELECT COUNT(id) AS count FROM {$this->get_db()->edd_customers}" );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* 3.0 Data Migration - Discounts.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Discounts Class.
*
* @since 3.0
*/
class Discounts extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Discounts migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_discounts';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->posts}
WHERE post_type = %s
LIMIT %d, %d",
esc_sql( 'edd_discount' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
// Check if discount has already been migrated.
if ( edd_get_discount( $result->ID ) ) {
continue;
}
Data_Migrator::discounts( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(ID) AS count FROM {$this->get_db()->posts} WHERE post_type = %s", esc_sql( 'edd_discount' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* 3.0 Data Migration - Logs.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Logs Class.
*
* @since 3.0
*/
class Logs extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Logs migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_logs';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT p.*, t.slug
FROM {$this->get_db()->posts} AS p
LEFT JOIN {$this->get_db()->term_relationships} AS tr ON (p.ID = tr.object_id)
LEFT JOIN {$this->get_db()->term_taxonomy} AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
LEFT JOIN {$this->get_db()->terms} AS t ON (tt.term_id = t.term_id)
WHERE p.post_type = %s AND t.slug != %s
GROUP BY p.ID
LIMIT %d, %d",
esc_sql( 'edd_log' ), esc_sql( 'sale' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
Data_Migrator::logs( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(ID) AS count FROM {$this->get_db()->posts} WHERE post_type = %s", esc_sql( 'edd_log' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,91 @@
<?php
/**
* 3.0 Data Migration - Order Notes.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Order_Notes Class.
*
* @since 3.0
*/
class Order_Notes extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Order notes migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_order_notes';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->comments}
WHERE comment_type = %s
ORDER BY comment_id ASC
LIMIT %d, %d",
esc_sql( 'edd_payment_note' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
$result->object_id = $result->comment_post_ID;
Data_Migrator::order_notes( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(comment_ID) AS count FROM {$this->get_db()->comments} WHERE comment_type = %s", esc_sql( 'edd_payment_note' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* 3.0 Data Migration - Orders.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Orders Class.
*
* @since 3.0
*/
class Orders extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Orders migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_orders';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
$results = $this->get_db()->get_results( $this->get_db()->prepare(
"SELECT *
FROM {$this->get_db()->posts}
WHERE post_type = %s
ORDER BY ID ASC
LIMIT %d, %d",
esc_sql( 'edd_payment' ), $offset, $this->per_step
) );
if ( ! empty( $results ) ) {
$orders = new \EDD\Database\Queries\Order();
foreach ( $results as $result ) {
// Check if order has already been migrated.
if ( $orders->get_item( $result->ID ) ) {
continue;
}
Data_Migrator::orders( $result );
}
return true;
}
$this->recalculate_sales_earnings();
return false;
}
/**
* Recalculates the sales and earnings numbers for all downloads once the orders have been migrated.
*
* @since 3.0
* @return void
*/
private function recalculate_sales_earnings() {
global $wpdb;
$downloads = $wpdb->get_results(
"SELECT ID
FROM {$wpdb->posts}
WHERE post_type = 'download'
ORDER BY ID ASC"
);
$total = count( $downloads );
if ( ! empty( $total ) ) {
foreach ( $downloads as $download ) {
edd_recalculate_download_sales_earnings( $download->ID );
}
}
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(id) AS count FROM {$this->get_db()->posts} WHERE post_type = %s", esc_sql( 'edd_payment' ) ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,160 @@
<?php
/**
* 3.0 Data Migration - Remove Legacy Data.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Remove_Legacy_Data Class.
*
* @since 3.0
*/
class Remove_Legacy_Data extends Base {
/**
* Sets the number of items to pull on each step.
*
* This is 50 in base, but we're cutting it in half here because we delete 25 from posts and 25 from comments
* on each step. Together combined that's 50.
*
* @since 3.0
* @var int
*/
public $per_step = 25;
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Legacy data removed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'v30_legacy_data_removed';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
// Perform some database operations on the first step.
if ( 1 === $this->step ) {
// Drop customer `payment_ids` column. It's no longer needed.
$customer_table = edd_get_component_interface( 'customer', 'table' );
if ( $customer_table instanceof \EDD\Database\Tables\Customers && $customer_table->column_exists( 'payment_ids' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->get_db()->edd_customers} DROP `payment_ids`" );
}
// Delete unneeded meta.
$this->get_db()->query( $this->get_db()->prepare( "DELETE FROM {$this->get_db()->edd_customermeta} WHERE meta_key = %s", esc_sql( 'additional_email' ) ) );
$this->get_db()->query( $this->get_db()->prepare( "DELETE FROM {$this->get_db()->usermeta} WHERE meta_key = %s", esc_sql( '_edd_user_address' ) ) );
}
// First delete custom post types.
$results = $this->get_db()->get_col( $this->get_db()->prepare(
"SELECT id
FROM {$this->get_db()->posts}
WHERE post_type IN(%s, %s, %s)
ORDER BY id ASC
LIMIT %d",
esc_sql( 'edd_payment' ), esc_sql( 'edd_discount' ), esc_sql( 'edd_log' ), $this->per_step
), 0 );
$data_was_deleted = false;
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
wp_delete_post( $result, true );
}
$data_was_deleted = true;
}
// Then delete order notes, stored in comments.
$results = $this->get_db()->get_col( $this->get_db()->prepare(
"SELECT comment_ID
FROM {$this->get_db()->comments}
WHERE comment_type = %s
ORDER BY comment_ID ASC
LIMIT %d",
'edd_payment_note', $this->per_step
) );
if ( ! empty( $results ) ) {
foreach( $results as $result ) {
wp_delete_comment( $result, true );
}
$data_was_deleted = true;
}
return $data_was_deleted;
}
/**
* Calculate the percentage completed.
*
* Because we're *deleting* records as we go, this percentage will not be accurate because we don't track
* exactly how many we've deleted. So this percentage is really just best guess.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
// Get post type total.
$total = $this->get_db()->get_var( $this->get_db()->prepare(
"SELECT COUNT(id) AS count
FROM {$this->get_db()->posts}
WHERE post_type IN(%s, %s, %s)",
esc_sql( 'edd_payment' ), esc_sql( 'edd_discount' ), esc_sql( 'edd_log' )
) );
if ( empty( $total ) ) {
$total = 0;
}
// Get order note total.
$order_note_total = $this->get_db()->get_var( $this->get_db()->prepare(
"SELECT COUNT(comment_ID) AS count
FROM {$this->get_db()->comments}
WHERE comment_type = %s",
'edd_payment_note'
) );
if ( empty( $order_note_total ) ) {
$order_note_total = 0;
}
// Combine the two.
$total += $order_note_total;
// Estimate how many we've already done to improve the percentage.
$number_done = $this->per_step * $this->step;
$total += $number_done;
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( $number_done / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,96 @@
<?php
/**
* 3.0 Data Migration - Tax Rates.
*
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Admin\Upgrades\v3;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Tax_Rates Class.
*
* @since 3.0
*/
class Tax_Rates extends Base {
/**
* Constructor.
*
* @param int $step Step.
*/
public function __construct( $step = 1 ) {
parent::__construct( $step );
$this->completed_message = __( 'Tax rates migration completed successfully.', 'easy-digital-downloads' );
$this->upgrade = 'migrate_tax_rates';
}
/**
* Retrieve the data pertaining to the current step and migrate as necessary.
*
* @since 3.0
*
* @return bool True if data was migrated, false otherwise.
*/
public function get_data() {
$offset = ( $this->step - 1 ) * $this->per_step;
if ( 1 === $this->step ) {
$default_tax_rate = edd_get_option( 'tax_rate', false );
if ( ! empty( $default_tax_rate ) ) {
edd_add_tax_rate(
array(
'scope' => 'global',
'amount' => floatval( $default_tax_rate ),
)
);
}
}
$results = get_option( 'edd_tax_rates', array() );
$results = array_slice( $results, $offset, $this->per_step, true );
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
Data_Migrator::tax_rates( $result );
}
return true;
}
return false;
}
/**
* Calculate the percentage completed.
*
* @since 3.0
*
* @return float Percentage.
*/
public function get_percentage_complete() {
$total = count( get_option( 'edd_tax_rates', array() ) );
if ( empty( $total ) ) {
$total = 0;
}
$percentage = 100;
if ( $total > 0 ) {
$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
}
if ( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* v3 Upgrade Actions
*
* @package EDD
* @subpackage Admin/Upgrades/v3
* @copyright Copyright (c) 2020, Sandhills Development, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Handles the 3.0 upgrade process.
*
* This loops through all upgrades that have not yet been completed, and steps through each process.
*
* @since 3.0
* @return void
*/
function edd_process_v3_upgrade() {
check_ajax_referer( 'edd_process_v3_upgrade' );
$all_upgrades = edd_get_v30_upgrades();
// Filter out completed upgrades.
foreach ( $all_upgrades as $upgrade_key => $upgrade_details ) {
if ( edd_has_upgrade_completed( $upgrade_key ) ) {
unset( $all_upgrades[ $upgrade_key ] );
}
}
$upgrade_keys = array_keys( $all_upgrades );
// Use supplied upgrade key if available, otherwise the first item in the list.
$upgrade_key = ! empty( $_POST['upgrade_key'] ) && 'false' !== $_POST['upgrade_key'] ? $_POST['upgrade_key'] : false;
if ( empty( $upgrade_key ) ) {
$upgrade_key = reset( $upgrade_keys );
}
if ( ! array_key_exists( $upgrade_key, $all_upgrades ) ) {
wp_send_json_error( sprintf( __( '"%s" is not a valid 3.0 upgrade.', 'easy-digital-downloads' ), $upgrade_key ) );
}
$step = ! empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
// If we have a step already saved, use that instead.
$saved_step = get_option( sprintf( 'edd_v3_migration_%s_step', sanitize_key( $upgrade_key ) ) );
if ( ! empty( $saved_step ) ) {
$step = absint( $saved_step );
}
$class_name = $all_upgrades[ $upgrade_key ]['class'];
// Load the required classes.
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export.php';
do_action( 'edd_batch_export_class_include', $class_name );
if ( ! class_exists( $class_name ) ) {
wp_send_json_error( __( 'Error loading migration class.', 'easy-digital-downloads' ) );
}
/** @var \EDD_Batch_Export $export */
$export = new $class_name( $step );
if ( ! $export->can_export() ) {
wp_die( -1, 403, array( 'response' => 403 ) );
}
$was_processed = $export->process_step();
$percentage_complete = round( $export->get_percentage_complete(), 2 );
// Build some shared args.
$response_args = array(
'upgrade_processed' => $upgrade_key,
'nonce' => wp_create_nonce( 'edd_process_v3_upgrade' )
);
if ( $was_processed ) {
// Data was processed, which means we'll want to repeat this upgrade again next time.
wp_send_json_success( wp_parse_args( array(
'upgrade_completed' => false,
'next_step' => $step + 1,
'next_upgrade' => $upgrade_key,
'percentage' => $percentage_complete,
), $response_args ) );
} else {
// No data was processed, which means it's time to move on to the next upgrade.
// Figure out which upgrade is next.
$remaining_upgrades = array_slice( $upgrade_keys, array_search( $upgrade_key, $upgrade_keys ) + 1 );
$next_upgrade = ! empty( $remaining_upgrades ) ? reset( $remaining_upgrades ) : false;
wp_send_json_success( wp_parse_args( array(
'upgrade_completed' => true,
'next_step' => 1,
'next_upgrade' => $next_upgrade,
'percentage' => 0
), $response_args ) );
}
}
add_action( 'wp_ajax_edd_process_v3_upgrade', 'edd_process_v3_upgrade' );