-
Notifications
You must be signed in to change notification settings - Fork 56
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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?
usort( | ||
$files_data, | ||
function( $file1, $file2 ) { | ||
return $file2['ctime'] - $file1['ctime']; | ||
} | ||
); |
There was a problem hiding this comment.
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):
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):
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 ] ) ) { |
There was a problem hiding this comment.
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.
if ( ! empty( $value ) && isset( $mapped_fields[ $value ] ) && is_array( $mapped_fields[ $value ] ) ) { | |
if ( ! empty( $value ) && is_array( $mapped_fields[ $value ] ) ) { |
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