File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -173,29 +173,34 @@ public function cloudfront_client() : \Aws\CloudFront\CloudFrontClient {
173173 return $ client ;
174174 }
175175
176+ public static function create_invalidation ( string $ distribution_id , array $ items ,
177+ int $ quantity ) : string {
178+ $ client = self ::cloudfront_client ();
179+
180+ return $ client ->createInvalidation (
181+ [
182+ 'DistributionId ' => $ distribution_id ,
183+ 'InvalidationBatch ' => [
184+ 'CallerReference ' => 'WP2Static S3 Add-on ' . time (),
185+ 'Paths ' => [
186+ 'Items ' => $ items ,
187+ 'Quantity ' => $ quantity ,
188+ ],
189+ ],
190+ ]
191+ );
192+ }
193+
176194 public function cloudfront_invalidate_all_items () : void {
177195 if ( ! Controller::getValue ( 'cfDistributionID ' ) ) {
178196 return ;
179197 }
180198
181199 \WP2Static \WsLog::l ( 'Invalidating all CloudFront items ' );
182200
183- $ client = self ::cloudfront_client ();
184-
185201 try {
186- $ result = $ client ->createInvalidation (
187- [
188- 'DistributionId ' => Controller::getValue ( 'cfDistributionID ' ),
189- 'InvalidationBatch ' => [
190- 'CallerReference ' => 'WP2Static S3 Add-on ' . time (),
191- 'Paths ' => [
192- 'Items ' => [ '/* ' ],
193- 'Quantity ' => 1 ,
194- ],
195- ],
196- ]
197- );
198-
202+ self ::create_invalidation ( Controller::getValue ( 'cfDistributionID ' ),
203+ [ '/* ' ], 1 );
199204 } catch ( AwsException $ e ) {
200205 // output error message if fails
201206 error_log ( $ e ->getMessage () );
You can’t perform that action at this time.
0 commit comments