Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CLI download recalculations #9560

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions includes/class-edd-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -1821,21 +1821,38 @@ public function display_legacy_payment_data( $args ) {
public function recalculate_download_sales_earnings() {
global $wpdb;

$downloads = $wpdb->get_results(
"SELECT ID
$step = 0;
$offset = 0;
$number = 1000;
$has_results = true;
$total = $wpdb->get_var(
"SELECT COUNT(ID)
robincornett marked this conversation as resolved.
Show resolved Hide resolved
FROM {$wpdb->posts}
WHERE post_type = 'download'
ORDER BY ID ASC"
WHERE post_type = 'download'"
);
$total = count( $downloads );
if ( ! empty( $total ) ) {
$progress = new \cli\progress\Bar( 'Recalculating Download Sales and Earnings', $total );
foreach ( $downloads as $download ) {
edd_recalculate_download_sales_earnings( $download->ID );
$progress->tick();

$progress = new \cli\progress\Bar( 'Recalculating Download Sales and Earnings', $total );

while ( $has_results ) {
$downloads = $wpdb->get_results(
"SELECT ID
FROM {$wpdb->posts}
WHERE post_type = 'download'
ORDER BY ID ASC
LIMIT {$offset}, {$number}"
);
if ( ! empty( $downloads ) ) {
foreach ( $downloads as $download ) {
edd_recalculate_download_sales_earnings( $download->ID );
$progress->tick();
}
$step++;
$offset = ( $step * $number );
} else {
$has_results = false;
}
$progress->finish();
}
$progress->finish();
WP_CLI::line( __( 'Sales and Earnings successfully recalculated for all downloads.', 'easy-digital-downloads' ) );
WP_CLI::line( __( 'Downloads Updated: ', 'easy-digital-downloads' ) . $total );
}
Expand Down