Skip to content

Commit 44e5e1c

Browse files
fajardoleoswashata
authored andcommitted
[garbage-collector] Fixed an issue related to modified slugs.
1 parent 13bbba6 commit 44e5e1c

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

includes/class-fs-garbage-collector.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function clean() {
5959
$options = $this->load_options();
6060
$has_updated_option = false;
6161

62-
$products_to_clean = $this->get_products_to_clean();
62+
$filtered_products = $this->get_filtered_products();
63+
$products_to_clean = $filtered_products['products_to_clean'];
64+
$active_products_by_id_map = $filtered_products['active_products_by_id_map'];
6365

6466
foreach( $products_to_clean as $product ) {
6567
$slug = $product->slug;
@@ -85,10 +87,25 @@ function clean() {
8587
} else if ( array_key_exists( "{$slug}:{$this->_type}", $option ) ) { /* admin_notices */
8688
unset( $option[ "{$slug}:{$this->_type}" ] );
8789
$updated = true;
88-
} else if ( isset( $product->id ) && array_key_exists( $product->id, $option ) ) { /* all_licenses */
89-
unset( $option[ $product->id ] );
90-
$updated = true;
91-
} else if ( isset( $product->file ) && array_key_exists( $product->file, $option ) ) { /* file_slug_map */
90+
} else if ( isset( $product->id ) && array_key_exists( $product->id, $option ) ) { /* all_licenses, add-ons, and id_slug_type_path_map */
91+
$is_inactive_by_id = ! isset( $active_products_by_id_map[ $product->id ] );
92+
$is_inactive_by_slug = (
93+
'id_slug_type_path_map' === $option_name &&
94+
(
95+
! isset( $option[ $product->id ]['slug'] ) ||
96+
$slug === $option[ $product->id ]['slug']
97+
)
98+
);
99+
100+
if ( $is_inactive_by_id || $is_inactive_by_slug ) {
101+
unset( $option[ $product->id ] );
102+
$updated = true;
103+
}
104+
} else if ( /* file_slug_map */
105+
isset( $product->file ) &&
106+
array_key_exists( $product->file, $option ) &&
107+
$slug === $option[ $product->file ]
108+
) {
92109
unset( $option[ $product->file ] );
93110
$updated = true;
94111
}
@@ -145,15 +162,22 @@ private function get_products() {
145162
if ( ! isset( $products[ $slug ] ) ) {
146163
$products[ $slug ] = (object) $product_data;
147164
}
165+
166+
// 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.
167+
$products[ $slug ] = clone $products[ $slug ];
168+
169+
// The reason for having the line above. This also handles a scenario in which the slug is either empty or not empty but incorrect.
170+
$products[ $slug ]->slug = $slug;
148171
}
149172

150173
$this->update_gc_timestamp( $products );
151174

152175
return $products;
153176
}
154177

155-
private function get_products_to_clean() {
156-
$products_to_clean = array();
178+
private function get_filtered_products() {
179+
$products_to_clean = array();
180+
$active_products_by_id_map = array();
157181

158182
$products = $this->get_products();
159183

@@ -163,6 +187,7 @@ private function get_products_to_clean() {
163187
}
164188

165189
if ( $this->is_product_active( $slug ) ) {
190+
$active_products_by_id_map[ $product_data->id ] = true;
166191
continue;
167192
}
168193

@@ -178,7 +203,10 @@ private function get_products_to_clean() {
178203
}
179204
}
180205

181-
return $products_to_clean;
206+
return array(
207+
'products_to_clean' => $products_to_clean,
208+
'active_products_by_id_map' => $active_products_by_id_map,
209+
);
182210
}
183211

184212
/**

start.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @var string
1717
*/
18-
$this_sdk_version = '2.6.2.4';
18+
$this_sdk_version = '2.6.2.5';
1919

2020
#region SDK Selection Logic --------------------------------------------------------------------
2121

0 commit comments

Comments
 (0)