@@ -468,6 +468,7 @@ private function getCacheKey(string $scope, string $value): string
468
468
private function saveRemediations (array $ decisions ): array
469
469
{
470
470
$ errors = [];
471
+ $ count = 0 ;
471
472
foreach ($ decisions as $ decision ) {
472
473
$ remediation = $ this ->formatRemediationFromDecision ($ decision );
473
474
$ type = $ remediation [0 ];
@@ -492,9 +493,16 @@ private function saveRemediations(array $decisions): array
492
493
}
493
494
$ cacheKey = $ this ->getCacheKey ($ decision ['scope ' ], $ address ->toString ());
494
495
$ this ->addRemediationToCacheItem ($ cacheKey , $ type , $ exp , $ id );
496
+ ++$ count ;
495
497
} elseif (Constants::SCOPE_RANGE === $ decision ['scope ' ]) {
496
498
$ range = Subnet::parseString ($ decision ['value ' ]);
497
-
499
+ if (null === $ range ) {
500
+ $ this ->logger ->warning ('' , [
501
+ 'type ' => 'INVALID_RANGE_TO_ADD_FROM_REMEDIATION ' ,
502
+ 'decision ' => $ decision ,
503
+ ]);
504
+ continue ;
505
+ }
498
506
$ addressType = $ range ->getAddressType ();
499
507
$ isIpv6 = (Type::T_IPv6 === $ addressType );
500
508
if ($ isIpv6 || ($ range ->getNetworkPrefix () < 24 )) {
@@ -527,13 +535,15 @@ private function saveRemediations(array $decisions): array
527
535
throw new BouncerException ($ message );
528
536
}
529
537
} while (0 !== strcmp ($ address ->getComparableString (), $ comparableEndAddress ));
538
+ ++$ count ;
530
539
} elseif (Constants::SCOPE_COUNTRY === $ decision ['scope ' ]) {
531
540
$ cacheKey = $ this ->getCacheKey ($ decision ['scope ' ], $ decision ['value ' ]);
532
541
$ this ->addRemediationToCacheItem ($ cacheKey , $ type , $ exp , $ id );
542
+ ++$ count ;
533
543
}
534
544
}
535
545
536
- return ['success ' => $ this ->commit (), 'errors ' => $ errors ];
546
+ return ['success ' => $ this ->commit (), 'errors ' => $ errors, ' count ' => $ count ];
537
547
}
538
548
539
549
/**
@@ -570,7 +580,13 @@ private function removeRemediations(array $decisions): array
570
580
}
571
581
} elseif (Constants::SCOPE_RANGE === $ decision ['scope ' ]) {
572
582
$ range = Subnet::parseString ($ decision ['value ' ]);
573
-
583
+ if (null === $ range ) {
584
+ $ this ->logger ->warning ('' , [
585
+ 'type ' => 'INVALID_RANGE_TO_REMOVE_FROM_REMEDIATION ' ,
586
+ 'decision ' => $ decision ,
587
+ ]);
588
+ continue ;
589
+ }
574
590
$ addressType = $ range ->getAddressType ();
575
591
$ isIpv6 = (Type::T_IPv6 === $ addressType );
576
592
if ($ isIpv6 || ($ range ->getNetworkPrefix () < 24 )) {
@@ -751,8 +767,15 @@ public function pullUpdates(): array
751
767
$ nbNew = 0 ;
752
768
if ($ newDecisions ) {
753
769
$ saveResult = $ this ->saveRemediations ($ newDecisions );
754
- $ addErrors = $ saveResult ['errors ' ];
755
- $ nbNew = \count ($ newDecisions );
770
+ if (!empty ($ saveResult ['success ' ])){
771
+ $ addErrors = $ saveResult ['errors ' ]??0 ;
772
+ $ nbNew = $ saveResult ['count ' ]??0 ;
773
+ }
774
+ else {
775
+ $ this ->logger ->warning ('' , [
776
+ 'type ' => 'CACHE_UPDATED_FAILED ' ,
777
+ 'message ' => 'Something went wrong while committing to cache adapter ' ]);
778
+ }
756
779
}
757
780
758
781
$ this ->logger ->debug ('' , ['type ' => 'CACHE_UPDATED ' , 'deleted ' => $ nbDeleted , 'new ' => $ nbNew ]);
0 commit comments