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

not to remove the merged file path from the saved data #195

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
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
41 changes: 9 additions & 32 deletions src/Order/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,7 @@ function ( $barc ) {
$barcodes
);

$saved_data['labels'] = array_map(
function ( $label ) {
unset( $label['merged_files'] );

return $label;
},
$labels
);
$saved_data['labels'] = $labels;

if ( $this->settings->is_auto_complete_order_enabled() ) {
// Updating the order status to completed.
Expand Down Expand Up @@ -711,7 +704,8 @@ public function put_label_content( $response, $order, $parent_barcode, $parent_l
$label_extension = ! empty( $label_contents['OutputType'] ) ? sanitize_title( $label_contents['OutputType'] ) : 'pdf';
$barcode = $response[ $type ][ $shipment_idx ][ $content_type['barcode_key'] ];
$barcode = is_array( $barcode ) ? array_shift( $barcode ) : $barcode;
$filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, 'A6', $label_extension );
$label_format = $this->settings->get_label_format();
$filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, $label_format, $label_extension );
Comment on lines +707 to +708
Copy link
Member

Choose a reason for hiding this comment

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

but the label file returned from API is always A6, is there a reason for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Abdalsalaam It cause a fatal error when it generate files with format A4 then try to create the label again from bulk action because file path is A6 but the one saved to database is A4

$filepath = trailingslashit( POSTNL_UPLOADS_DIR ) . $filename;

if ( wp_mkdir_p( POSTNL_UPLOADS_DIR ) && ! file_exists( $filepath ) ) {
Expand Down Expand Up @@ -1277,6 +1271,12 @@ public function delete_label( $saved_data ) {
return false;
}

if( isset( $saved_data['labels']['label']['merged_files'] ) ){
foreach ( $saved_data['labels']['label']['merged_files'] as $label_path ) {
unlink( $label_path );
}
}
OlfatProgressus marked this conversation as resolved.
Show resolved Hide resolved

return unlink( $saved_data['labels']['label']['filepath'] );
}

Expand Down Expand Up @@ -1419,29 +1419,6 @@ protected function get_tracking_link( $order_id ) {
return sprintf( '<a href="%1$s" target="_blank" class="postnl-tracking-link">%2$s</a>', esc_url( $tracking_url ), $saved_data['labels']['label']['barcode'] );
}

/**
* Delete label files from label info.
*
* @param Array $labels List of label info.
*/
public function delete_label_files( $labels ) {
if ( empty( $labels ) ) {
return;
}

foreach ( $labels as $label_type => $label_info ) {
if ( empty( $label_info['merged_files'] ) || empty( $label_info['filepath'] ) ) {
continue;
}

foreach ( $label_info['merged_files'] as $path ) {
if ( file_exists( $path ) && $path !== $label_info['filepath'] ) {
unlink( $path );
}
}
}
}

/**
* Check if the order have the label data.
*
Expand Down
4 changes: 0 additions & 4 deletions src/Order/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ public function merge_bulk_labels( $gen_labels ) {

$merged_info = $this->merge_labels( $label_paths, $filename, $start_position );

foreach ( $gen_labels as $labels ) {
$this->delete_label_files( $labels );
}

if ( file_exists( $merged_info ['filepath'] ) ) {
// We're saving the bulk file path temporarily and access it later during the download process.
// This information expires in 3 minutes (180 seconds), just enough for the user to see the
Expand Down
2 changes: 0 additions & 2 deletions src/Order/Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ public function save_meta_box_ajax() {
$labels = $result['labels'];
$tracking_note = $this->get_tracking_note( $order_id );

$this->delete_label_files( $labels );

if ( ! empty( $tracking_note ) ) {
$return_data = array_merge(
$result['saved_data'],
Expand Down