Skip to content

Commit

Permalink
[garbage-collector] Fixed an issue related to modified slugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
fajardoleo committed Mar 14, 2024
1 parent e79b974 commit 6addbad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
49 changes: 41 additions & 8 deletions includes/class-fs-garbage-collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function clean() {
$options = $this->load_options();
$has_updated_option = false;

$products_to_clean = $this->get_products_to_clean();
$filtered_products = $this->get_filtered_products();
$products_to_clean = $filtered_products['products_to_clean'];
$active_products_by_id_map = $filtered_products['active_products_by_id_map'];

foreach( $products_to_clean as $product ) {
$slug = $product->slug;
Expand All @@ -85,10 +87,30 @@ function clean() {
} else if ( array_key_exists( "{$slug}:{$this->_type}", $option ) ) { /* admin_notices */
unset( $option[ "{$slug}:{$this->_type}" ] );
$updated = true;
} else if ( isset( $product->id ) && array_key_exists( $product->id, $option ) ) { /* all_licenses */
unset( $option[ $product->id ] );
$updated = true;
} else if ( isset( $product->file ) && array_key_exists( $product->file, $option ) ) { /* file_slug_map */
} else if ( isset( $product->id ) && array_key_exists( $product->id, $option ) ) { /* all_licenses, add-ons, and id_slug_type_path_map */
$unset_option = false;

if ( ! isset( $active_products_by_id_map[ $product->id ] ) ) {
$unset_option = true;
} else if (
'id_slug_type_path_map' === $option_name &&
(
! isset( $option[ $product->id ]['slug'] ) ||
$slug === $option[ $product->id ]['slug']
)
) {
$unset_option = true;
}

if ( $unset_option ) {
unset( $option[ $product->id ] );
$updated = true;
}
} else if ( /* file_slug_map */
isset( $product->file ) &&
array_key_exists( $product->file, $option ) &&
$slug === $option[ $product->file ]
) {
unset( $option[ $product->file ] );
$updated = true;
}
Expand Down Expand Up @@ -145,15 +167,22 @@ private function get_products() {
if ( ! isset( $products[ $slug ] ) ) {
$products[ $slug ] = (object) $product_data;
}

// This is needed to handle a scenario in which there are duplicate sets of data for the same product, but one of them needs to be removed.
$products[ $slug ] = clone $products[ $slug ];

// The reason for having the line above. This also handles a scenario in which the slug is either empty or not empty but incorrect.
$products[ $slug ]->slug = $slug;
}

$this->update_gc_timestamp( $products );

return $products;
}

private function get_products_to_clean() {
$products_to_clean = array();
private function get_filtered_products() {
$products_to_clean = array();
$active_products_by_id_map = array();

$products = $this->get_products();

Expand All @@ -163,6 +192,7 @@ private function get_products_to_clean() {
}

if ( $this->is_product_active( $slug ) ) {
$active_products_by_id_map[ $product_data->id ] = true;
continue;
}

Expand All @@ -178,7 +208,10 @@ private function get_products_to_clean() {
}
}

return $products_to_clean;
return array(
'products_to_clean' => $products_to_clean,
'active_products_by_id_map' => $active_products_by_id_map,
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion start.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$this_sdk_version = '2.6.2.1';
$this_sdk_version = '2.6.2.2';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down

0 comments on commit 6addbad

Please sign in to comment.