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

Sort CSV cron exports by date (desc) #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jorgeatorres
Copy link
Member

The table in WC > Subscription Exporter > Cron exports lists exports as provided by the filesystem, but this can be a bit confusing, as recent files might appear in the middle of the table between older files.
This PR makes sure all exports are sorted by the time the file was last modified. Assuming these files are not manipulated in the server (after the export) this actually means newer files now appear on top.

Testing instructions

  1. Go to WC > Subscriptions Exporte and perform a few exports.
  2. Make sure they are listed in WC > Subscription Exporter > Cron exports with newer files on top and older files at the bottom.

Copy link

@sun sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this and contributing your improvement.

Can you review the suggestions and below and consider to apply them to your branch, please?

Comment on lines +310 to +315
usort(
$files_data,
function( $file1, $file2 ) {
return $file2['ctime'] - $file1['ctime'];
}
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the spaceship operator (available since PHP 7.0):

Suggested change
usort(
$files_data,
function( $file1, $file2 ) {
return $file2['ctime'] - $file1['ctime'];
}
);
usort( $files_data, function( $file1, $file2 ) {
return $file2['ctime'] <=> $file1['ctime'];
});

In addition, use arrow functions (available since PHP 7.4):

Suggested change
usort(
$files_data,
function( $file1, $file2 ) {
return $file2['ctime'] - $file1['ctime'];
}
);
usort( $files_data, fn( $file1, $file2 ) => $file2['ctime'] <=> $file1['ctime']);

WordPress requires PHP 7.4, so this is fine.

@@ -518,7 +518,7 @@ public function save_mapping() {
}

foreach ( $mapping_rules as $key => $value ) {
if ( ! empty( $value ) && is_array( $mapped_fields[ $value ] ) ) {
if ( ! empty( $value ) && isset( $mapped_fields[ $value ] ) && is_array( $mapped_fields[ $value ] ) ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR - please revert here and propose the change in a separate one.

Suggested change
if ( ! empty( $value ) && isset( $mapped_fields[ $value ] ) && is_array( $mapped_fields[ $value ] ) ) {
if ( ! empty( $value ) && is_array( $mapped_fields[ $value ] ) ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants