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,237 @@
<?php
/**
* Migrate File Download Logs
*
* Removes some PII from the log meta, and adds the customer ID of the payment to allow more accurate
* file download counts for a customer.
*
* @subpackage Admin/Classes/EDD_SL_License_Log_Migration
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.9.2
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* EDD_File_Download_Log_Migration Class
*
* @since 2.9.2
*/
class EDD_File_Download_Log_Migration extends EDD_Batch_Export {
/**
* Our export type. Used for export-type specific filters/actions
* @var string
* @since 2.9.2
*/
public $export_type = '';
/**
* Allows for a non-download batch processing to be run.
* @since 2.9.2
* @var boolean
*/
public $is_void = true;
/**
* Sets the number of items to pull on each step
* @since 2.9.2
* @var integer
*/
public $per_step = 50;
/**
* Get the Export Data
*
* @access public
* @since 2.9.2
* @return array $data The data for the CSV file
*/
public function get_data() {
$step_items = $this->get_log_ids_for_current_step();
if ( ! is_array( $step_items ) ) {
return false;
}
if ( empty( $step_items ) ) {
return false;
}
foreach ( $step_items as $log_id ) {
$log_id = (int) $log_id;
$sanitized_log_id = absint( $log_id );
if ( $sanitized_log_id !== $log_id ) {
edd_debug_log( "Log ID mismatch, skipping log ID {$log_id}" );
continue;
}
$has_customer_id = (int) get_post_meta( $log_id, '_edd_log_customer_id', true );
if ( ! empty( $has_customer_id ) ) {
continue;
}
$payment_id = (int) get_post_meta( $log_id, '_edd_log_payment_id', true );
if ( ! empty( $payment_id ) ) {
$customer_id = edd_get_payment_customer_id( $payment_id );
if ( $customer_id < 0 ) {
$customer_id = 0;
}
update_post_meta( $log_id, '_edd_log_customer_id', $customer_id );
delete_post_meta( $log_id, '_edd_log_user_info' );
}
}
return true;
}
/**
* Return the calculated completion percentage
*
* @since 2.9.2
* @return int
*/
public function get_percentage_complete() {
$total = (int) get_option( 'edd_fdlm_total_logs', 0 );
$percentage = 100;
if( $total > 0 ) {
$percentage = ( ( $this->step * $this->per_step ) / $total ) * 100;
}
if( $percentage > 100 ) {
$percentage = 100;
}
return $percentage;
}
/**
* Set the properties specific to the payments export
*
* @since 2.9.2
* @param array $request The Form Data passed into the batch processing
*/
public function set_properties( $request ) {}
/**
* Process a step
*
* @since 2.9.2
* @return bool
*/
public function process_step() {
if ( ! $this->can_export() ) {
wp_die(
__( 'You do not have permission to run this upgrade.', 'easy-digital-downloads' ),
__( 'Error', 'easy-digital-downloads' ),
array( 'response' => 403 ) );
}
$had_data = $this->get_data();
if( $had_data ) {
$this->done = false;
return true;
} else {
$this->done = true;
delete_option( 'edd_fdlm_total_logs' );
delete_option( 'edd_fdlm_term_tax_id' );
$this->message = __( 'File download logs updated successfully.', 'easy-digital-downloads' );
edd_set_upgrade_complete( 'update_file_download_log_data' );
return false;
}
}
public function headers() {
edd_set_time_limit();
}
/**
* Perform the export
*
* @access public
* @since 2.9.2
* @return void
*/
public function export() {
// Set headers
$this->headers();
edd_die();
}
/**
* Fetch total number of log IDs needing migration
*
* @since 2.9.5
*
* @global object $wpdb
*/
public function pre_fetch() {
global $wpdb;
// Default count (assume no entries)
$log_id_count = 0;
// Query for a term ID (make sure log items exist)
$term_id = $wpdb->get_var( "SELECT term_id FROM {$wpdb->terms} WHERE name = 'file_download' LIMIT 1" );
// Log items exist...
if ( ! empty( $term_id ) ) {
// Query for possible entries...
$term_tax_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'edd_log_type' LIMIT 1", $term_id ) );
// Entries exist...
if ( ! empty( $term_tax_id ) ) {
// Cache the term taxonomy ID
update_option( 'edd_fdlm_term_tax_id', $term_tax_id );
// Count the number of entries!
$log_id_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $term_tax_id ) );
}
}
// Temporarily save the number of rows
update_option( 'edd_fdlm_total_logs', (int) $log_id_count );
}
/**
* Get the log IDs (50 based on this->per_step) for the current step
*
* @since 2.9.5
*
* @global object $wpdb
* @return array
*/
private function get_log_ids_for_current_step() {
global $wpdb;
// Default values
$log_ids = array();
$offset = ( $this->step * $this->per_step ) - $this->per_step;
// Count the number of entries!
$term_tax_id = (int) get_option( 'edd_fdlm_term_tax_id', 0 );
// Only query if term taxonomy ID was prefetched
if ( ! empty( $term_tax_id ) ) {
$log_ids = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d LIMIT %d, %d", $term_tax_id, $offset, $this->per_step ) );
}
// Always return an array
return ! is_wp_error( $log_ids )
? (array) $log_ids
: array();
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Downgrades
*
* @package easy-digital-downloads
* @copyright Copyright (c) 2021, Sandhills Development, LLC
* @license GPL2+
* @since 2.11
*/
/**
* Checks if the current site has downgraded, and if so, performs any necessary actions.
*
* @since 2.11
* @return bool Whether or not a downgrade was performed.
*/
function edd_do_downgrade() {
$did_downgrade = false;
$edd_version = preg_replace( '/[^0-9.].*/', '', get_option( 'edd_version' ) );
$downgraded_from = get_option( 'edd_version_downgraded_from' );
/**
* Check for downgrade from 3.0 to 2.11.
*/
if ( version_compare( EDD_VERSION, '3.0-beta1', '<' ) ) {
if (
version_compare( $edd_version, '3.0-beta1', '>=' ) ||
( $downgraded_from && version_compare( $downgraded_from, '3.0-beta1', '>=' ) )
) {
/*
* This site probably just downgraded from EDD 3.0. Let's perform a downgrade.
*/
$did_downgrade = edd_maybe_downgrade_from_v3();
}
}
if ( $did_downgrade ) {
update_option( 'edd_version', preg_replace( '/[^0-9.].*/', '', EDD_VERSION ) );
delete_option( 'edd_version_downgraded_from' );
}
return $did_downgrade;
}
add_action( 'admin_init', 'edd_do_downgrade' );
/**
* Performs a database downgrade from EDD 3.0 to 2.11 if one is needed.
* The main operation here is changing the customer meta column from `edd_customer_id` (v3.0 version)
* back to `customer_id` for v2.x.
*
* @since 2.11
* @return bool Whether the downgrade was performed.
*/
function edd_maybe_downgrade_from_v3() {
global $wpdb;
$customer_meta_table = EDD()->customer_meta->table_name;
// If there is no column called `edd_customer_id`, then we don't need to downgrade.
$columns = $wpdb->query( "SHOW COLUMNS FROM {$customer_meta_table} LIKE 'edd_customer_id'");
if ( empty( $columns ) ) {
return false;
}
$wpdb->query( "ALTER TABLE {$customer_meta_table} CHANGE `edd_customer_id` `customer_id` bigint(20) unsigned NOT NULL default '0'" );
$wpdb->query( "ALTER TABLE {$customer_meta_table} DROP INDEX edd_customer_id" );
$wpdb->query( "ALTER TABLE {$customer_meta_table} ADD INDEX customer_id (customer_id)" );
// These two calls re-add the table version numbers for us.
EDD()->customer_meta->create_table();
EDD()->customers->create_table();
edd_debug_log( 'Completed downgrade from EDD 3.0.', true );
return true;
}

View File

@ -0,0 +1,139 @@
<?php
/**
* Upgrade Screen
*
* @package EDD
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.3.1
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Render Upgrades Screen
*
* @since 1.3.1
* @return void
*/
function edd_upgrades_screen() {
// Get the upgrade being performed
$action = isset( $_GET['edd-upgrade'] )
? sanitize_text_field( $_GET['edd-upgrade'] )
: ''; ?>
<div class="wrap">
<h1><?php _e( 'Upgrades', 'easy-digital-downloads' ); ?></h1>
<hr class="wp-header-end">
<?php if ( is_callable( 'edd_upgrade_render_' . $action ) ) {
// Until we have fully migrated all upgrade scripts to this new system,
// we will selectively enqueue the necessary scripts.
add_filter( 'edd_load_admin_scripts', '__return_true' );
edd_load_admin_scripts( 'edd-admin-upgrades' );
// This is the new method to register an upgrade routine, so we can use
// an ajax and progress bar to display any needed upgrades.
call_user_func( 'edd_upgrade_render_' . $action );
// Remove the above filter
remove_filter( 'edd_load_admin_scripts', '__return_true' );
} else {
// This is the legacy upgrade method, which requires a page refresh
// at each step.
$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
$total = isset( $_GET['total'] ) ? absint( $_GET['total'] ) : false;
$custom = isset( $_GET['custom'] ) ? absint( $_GET['custom'] ) : 0;
$number = isset( $_GET['number'] ) ? absint( $_GET['number'] ) : 100;
$steps = round( ( $total / $number ), 0 );
// Bump step
if ( ( $steps * $number ) < $total ) {
$steps++;
}
// Update step option
update_option( 'edd_doing_upgrade', array(
'page' => 'edd-upgrades',
'edd-upgrade' => $action,
'step' => $step,
'total' => $total,
'custom' => $custom,
'steps' => $steps
) );
// Prevent step estimate from going over
if ( $step > $steps ) {
$steps = $step;
}
if ( ! empty( $action ) ) :
// Redirect URL
$redirect = add_query_arg( array(
'edd_action' => sanitize_key( $action ),
'step' => absint( $step ),
'total' => absint( $total ),
'custom' => absint( $custom ),
), admin_url( 'index.php' ) ); ?>
<div id="edd-upgrade-status">
<p><?php _e( 'The upgrade process has started, please be patient. This could take several minutes. You will be automatically redirected when the upgrade is finished.', 'easy-digital-downloads' ); ?></p>
<?php if ( ! empty( $total ) ) : ?>
<p><strong><?php printf( __( 'Step %d of approximately %d running', 'easy-digital-downloads' ), $step, $steps ); ?></strong></p>
<?php endif; ?>
</div>
<script type="text/javascript">
setTimeout( function() {
document.location.href = '<?php echo esc_url_raw( $redirect ); ?>';
}, 250 );
</script>
<?php else :
// Redirect URL
$redirect = admin_url( 'index.php' ); ?>
<div id="edd-upgrade-status">
<p>
<?php _e( 'The upgrade process has started, please be patient. This could take several minutes. You will be automatically redirected when the upgrade is finished.', 'easy-digital-downloads' ); ?>
<img src="<?php echo esc_url( EDD_PLUGIN_URL . 'assets/images/loading.gif' ); ?>" id="edd-upgrade-loader"/>
</p>
</div>
<script type="text/javascript">
jQuery( document ).ready( function() {
// Trigger upgrades on page load
var data = {
action: 'edd_trigger_upgrades'
};
jQuery.post( ajaxurl, data, function (response) {
if ( 'complete' !== response ) {
return;
}
jQuery( '#edd-upgrade-loader' ).hide();
setTimeout( function() {
document.location.href = '<?php echo esc_url_raw( $redirect ); ?>';
}, 250 );
});
});
</script>
<?php endif;
} ?>
</div>
<?php
}

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' );